写一个溶解着色器,用OpenGL语言写UnityShaderlab
时间: 2023-03-09 16:41:48 浏览: 133
我可以为你写一个溶解着色器,用OpenGL语言写UnityShaderlab。下面是示例代码: Shader "Custom/Dissolve Effect" { Properties { _MainTex ("Texture", 2D) = "white" {} _DissolveAmount ("Dissolve Amount", Range (0, 1)) = 0.5 } SubShader { Tags { "RenderType"="Opaque" } Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float _DissolveAmount; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); float dist = length(col.rgb); // Change this if you want to use another channel instead of RGB col.a = saturate(dist - _DissolveAmount); return col; } ENDCG } } }
阅读全文