【Shader】Position Based Gradient Shader

这里写图片描述

原文链接:https://spennerino.wordpress.com/2017/06/20/gradient-shader/

Shader "Custom/Fog"

{

Properties

{

_Color("Color", Color) = (1,1,1,1)

_MainTex("Texture", 2D) = "white" {}

_FogColor("Fog Color", Color) = (0.3, 0.4, 0.7, 1.0)

_FogStart("Fog Start", float) = 0

_FogEnd("Fog End", float) = 0

}



SubShader

{

Tags{ "RenderType" = "Opaque" }



CGPROGRAM



#pragma surface surf Lambert finalcolor:mycolor vertex:myvert



struct Input

{

float2 uv_MainTex;

half fog;

};



fixed4 _Color;

fixed4 _FogColor;

half _FogStart;

half _FogEnd;

sampler2D _MainTex;



void myvert(inout appdata_full v, out Input data)

{

UNITY_INITIALIZE_OUTPUT(Input,data);

float4 pos = mul(unity_ObjectToWorld, v.vertex).xyzw;

data.fog = saturate((_FogStart - pos.y) / (_FogStart - _FogEnd));

}



void mycolor(Input IN, SurfaceOutput o, inout fixed4 color)

{

fixed3 fogColor = _FogColor.rgb;

fixed3 tintColor = _Color.rgb;

#ifdef UNITY_PASS_FORWARDADD

fogColor = 0;

#endif

color.rgb = lerp(color.rgb * tintColor, fogColor, IN.fog);

}



void surf(Input IN, inout SurfaceOutput o)

{

o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;

}



ENDCG

}



Fallback "Diffuse"

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值