Unity-URP学习笔记(六)溶解材质拓展Unity-URP学习笔记(六)溶解材质拓展
URP溶解材质
结果展⽰
Shader展⽰
Shader "MyURP/CharDissolutionPlus"
{
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",float)=0.5
_DissolutionWidth("DissolutionWidth",float)=0.2
_EmissionsIntensity("EmissionsIntensity",float)=1.0
_EmissionsColor("EmissionsColor",Color)=(1,1,1,1)
_TargetVector3("TargetVector3",Vector)=(0,0,0,0)
}
SubShader
{
Pass
{
Name "BASE"
Tags
Tags天下无人不识君
{
"RenderType"="TransparentCutout"
"Queue"="Geometry"
"RenderPipeline"="UniversalPipeline"
}
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/der-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/der-pipelines.universal/ShaderLibrary/Lighting.hlsl"
//传⼊顶点着⾊器的数据
struct a2v
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
//传⼊⽚元着⾊器的数据
读书心得格式模板struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float3 viewDir : TEXCOORD1;食品海报
float3 worldNormal : TEXCOORD2;
float2 uv2 :TEXCOORD3;
迅雷btfloat4 worldposition : TEXCOORD4;
};
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;
vector _TargetVector3;
CBUFFER_END
half remap(half x, half t1, half t2, half s1, half s2)
{
return(x - t1)/(t2 - t1)*(s2 - s1)+ s1;
}
/
/顶点着⾊器
v2f vert(a2v v)
{
英语一年级v2f o;
o.uv =TRANSFORM_TEX(v.uv, _MainTex);
o.uv2 =TRANSFORM_TEX(v.uv,_DissolutionTex);
o.worldNormal =al);
float3 worldPos =TransformObjectToWorld(v.vertex).xyz;
o.viewDir =normalize(_-worldPos);
= worldPos;
= worldPos;
o.worldposition.w =0;
o.vertex =TransformObjectToHClip(v.vertex);
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 BaColor =lerp(_CellColor,_Color,LdotN)*Albedo;
half4 FinalColor=lerp(BaColor,_HighLightColor+Albedo,HdotN);
///
float dis =distance(float4( ,0.0), _TargetVector3)-_AlphaCutoff;
float remapDis =remap(dis,0,1,0,1);
remapDis+=Dissolution.r;
clip(remapDis -0.5);
arp断网攻击half em1 =saturate(_DissolutionWidth-remapDis);
half4 emissions = em1*_EmissionsIntensity*_EmissionsColor;
///
return FinalColor+emissions;
//return emissions;
}
ENDHLSL
}
}
}
shader⾥⾯的TargetVector3⽤⽬标的世界坐标。