写一个支持urp的溶解shader写一个半卡通shader
支持URP的溶解Shader:
Shader "Custom/DissolveURP" { Properties { _MainTex ("Texture", 2D) = "white" {} _DissolveTex ("Dissolve Texture", 2D) = "white" {} _DissolveColor ("Dissolve Color", Color) = (1,1,1,1) _DissolveAmount ("Dissolve Amount", Range(0,1)) = 0.5 }
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
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;
sampler2D _DissolveTex;
float4 _DissolveColor;
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 {
float4 tex = tex2D(_MainTex, i.uv);
float4 dissolve = tex2D(_DissolveTex, i.uv);
float4 dissolveColor = lerp(tex, _DissolveColor, dissolve.r * _DissolveAmount);
dissolveColor.a = tex.a;
return dissolveColor;
}
ENDCG
}
}
FallBack "Diffuse"
}
半卡通Shader:
Shader "Custom/HalfToon" { Properties { _MainTex ("Texture", 2D) = "white" {} _Color ("Color", Color) = (1,1,1,1) _RampTex ("Ramp Texture", 2D) = "white" {} _ShadowColor ("Shadow Color", Color) = (0,0,0,1) }
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
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;
sampler2D _RampTex;
float4 _Color;
float4 _ShadowColor;
v2f vert (appdata v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target {
float4 tex = tex2D(_MainTex, i.uv);
float4 ramp = tex2D(_RampTex, float2(tex.r, 0.5));
float4 color = _Color * tex;
float4 shadow = _ShadowColor * (1 - ramp.r);
return color + shadow;
}
ENDCG
}
}
FallBack "Diffuse"
原文地址: https://www.cveoy.top/t/topic/fksG 著作权归作者所有。请勿转载和采集!