110 lines
4.3 KiB
Plaintext
110 lines
4.3 KiB
Plaintext
Shader "MyURP/CharDissolution"
|
|
{
|
|
Properties
|
|
{
|
|
_Color ("Color", Color) = (1,1,1,1)
|
|
_MainTex ("Albedo (RGB)", 2D) = "white" {}
|
|
_CellWidth("CellWidth",Range(-1,1))=0.5
|
|
_CellColor("CellColor",Color) = (0,0,0,0)
|
|
_HighLightWidth("HighLightWidth",Range(-1,1))=0.5
|
|
_HighLightColor("HighLightColor",Color) = (1,1,1,1)
|
|
_DissolutionTex("DissolutionTex",2D) = "white"{}
|
|
_AlphaCutoff("AlphaCutoff",Range(0,1)) = 0.5
|
|
_DissolutionWidth("DissolutionWidth",float) = 0.2
|
|
_EmissionsIntensity("EmissionsIntensity",float) =1.0
|
|
_EmissionsColor("EmissionsColor",Color) = (1,1,1,1)
|
|
}
|
|
SubShader
|
|
{
|
|
Pass
|
|
{
|
|
Name "BASE"
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"Queue" = "Geometry"
|
|
"LightMode" = "LightweightForward"
|
|
}
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
|
|
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
|
|
#pragma target 3.0
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
//传入顶点着色器的数据
|
|
struct a2v
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float3 normal : NORMAL;
|
|
};
|
|
//传入片元着色器的数据
|
|
struct v2f
|
|
{
|
|
float4 worldPos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float3 viewDir : TEXCOORD1;
|
|
float3 worldNormal : TEXCOORD2;
|
|
float2 uv2 :TEXCOORD3;
|
|
};
|
|
TEXTURE2D(_MainTex);
|
|
SAMPLER(sampler_MainTex);
|
|
TEXTURE2D(_DissolutionTex);
|
|
SAMPLER(sampler_DissolutionTex);
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _Color;
|
|
float4 _MainTex_ST;
|
|
float4 _DissolutionTex_ST;
|
|
float _HighLightWidth;
|
|
float4 _HighLightColor;
|
|
float _CellWidth;
|
|
float4 _CellColor;
|
|
float _AlphaCutoff;
|
|
float _DissolutionWidth;
|
|
float _EmissionsIntensity;
|
|
float4 _EmissionsColor;
|
|
CBUFFER_END
|
|
//顶点着色器
|
|
v2f vert(a2v v)
|
|
{
|
|
v2f o;
|
|
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
|
o.uv2 = TRANSFORM_TEX(v.uv,_DissolutionTex);
|
|
o.worldPos = TransformObjectToHClip(v.vertex);
|
|
o.worldNormal = TransformObjectToWorldNormal(v.normal);
|
|
o.viewDir = normalize(_WorldSpaceCameraPos.xyz-TransformObjectToWorld(v.vertex.xyz));
|
|
return o;
|
|
}
|
|
//片元着色器
|
|
half4 frag(v2f i) : SV_Target
|
|
{
|
|
Light mainLight = GetMainLight();
|
|
half LdotN = dot(mainLight.direction,i.worldNormal);
|
|
LdotN = saturate(step(0,LdotN-_CellWidth));
|
|
///
|
|
half3 halfAngle = normalize(normalize(mainLight.direction)+normalize(i.viewDir));
|
|
half HdotN = saturate(dot(halfAngle,i.worldNormal));
|
|
HdotN = saturate(ceil(HdotN-_HighLightWidth));
|
|
///
|
|
half4 Albedo = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
|
|
half4 Dissolution = SAMPLE_TEXTURE2D(_DissolutionTex,sampler_DissolutionTex,i.uv2);
|
|
///
|
|
half4 BaseColor = lerp(_CellColor,_Color,LdotN)*Albedo;
|
|
half4 FinalColor= lerp(BaseColor,_HighLightColor+Albedo,HdotN);
|
|
///
|
|
half em1 = step(0,Dissolution.r - _AlphaCutoff+_DissolutionWidth);
|
|
half em2 = step(0,Dissolution.r - _AlphaCutoff-_DissolutionWidth);
|
|
half em = em1 - em2;
|
|
half4 emissions = em*_EmissionsIntensity*_EmissionsColor;
|
|
///
|
|
clip(Dissolution.r - _AlphaCutoff);
|
|
return FinalColor+emissions;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|