顶点颜色交融效果

xiaoxiao2021-02-28  85

Shader "Unlit/factoryhot"

{ Properties { _MainTex ("Texture", 2D) = "white" {} // _PointTex ("Texture", 2D) = "white" {} _FromColor ("FromColor", Color) = (0, 1, 0, 1) _ToColor ("ToColor", Color) = (1, 0, 0, 1) _Distance ("Distance", Float) = 1.0//颜色距离 _Sensitive ("Sensitive", Float) = 1.0//距离调整 } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM // Upgrade NOTE: excluded shader from DX11, Xbox360, OpenGL ES 2.0 because it uses unsized arrays #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float3 worldpos : TEXCOORD1; // UNITY_FOG_COORDS(2) float4 vertex : SV_POSITION; }; sampler2D _MainTex; float4 _MainTex_ST; fixed4 _FromColor; fixed4 _ToColor; fixed3 Value1;//顶点1 fixed3 Value2;//顶点2 fixed3 Value3;//顶点3 float _Distance; float _Sensitive; //sampler2D _PointTex; v2f vert (appdata v) { v2f o; o.worldpos= mul(_Object2World, v.vertex); o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); //UNITY_TRANSFER_FOG(o,o.vertex); return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); //col*=_FromColor; float s1=distance(i.worldpos,Value1);//abs(dot((i.worldpos-Value1),(i.worldpos-Value1)));//dis的平方 float s2=distance(i.worldpos,Value2);//,(i.worldpos-Value2))); float s3=distance(i.worldpos,Value3);//abs(dot((i.worldpos-Value3),(i.worldpos-Value3))); // fixed4 c1=saturate(lerp(_ToColor,_FromColor,_Sensitive*s1)); // fixed4 c2=saturate(lerp(_ToColor,_FromColor,_Sensitive*s2)); fixed4 c=float4(0,1,0,0); float t=0; t+=pow(saturate(1-_Sensitive*s1/_Distance),2);//saturate(lerp(c1,c2,_Sensitive*s1));; t+=pow(saturate(1-_Sensitive*s2/_Distance),2);//saturate(lerp(c2,c1,_Sensitive*s2));//c2; t+=pow(saturate(1-_Sensitive*s3/_Distance),2);//pow是进行对强度进行曲线化 防止颜色线性曲折 return lerp(_FromColor*col,_ToColor*col,saturate(t)); } ENDCG } } }
转载请注明原文地址: https://www.6miu.com/read-59103.html

最新回复(0)