// Shader uses custom editor to set double sided GI // Needs _Culling to be set properly Shader "Toon" { Properties { [HeaderHelpLuxURP_URL(snoamqpqhtdl)] [Header(Surface Options)] [Space(8)] [ToggleOff(_RECEIVE_SHADOWS_OFF)] _ReceiveShadows("Receive Shadows", Float) = 1.0 _SkinShadowBias(" Shadow Caster Bias", Range(.1, 1.0)) = 1.0 _SkinShadowSamplingBias(" Shadow Sampling Bias", Range(0, 0.05)) = 0 [Header(Surface Inputs)] [Space(8)] [MainTexture] _BaseMap("Albedo (RGB) Smoothness (A)", 2D) = "white" {} _ClothMask1("Cloth Mask1", 2D) = "white" {} _ClothMask2("Cloth Mask2", 2D) = "white" {} _ClothMask3("Cloth Mask3", 2D) = "white" {} [MainColor] _BaseColor("Color", Color) = (1,1,1,1) [Space(5)] _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5 // For some reason android did not like _SpecColor!? _SpecularColor("Specular", Color) = (0.2, 0.2, 0.2) [Space(5)] [Toggle(_NORMALMAP)] _ApplyNormal("Enable Normal Map", Float) = 0.0 [NoScaleOffset] _BumpMap(" Normal Map", 2D) = "bump" {} _BumpScale(" Normal Scale", Float) = 1.0 [Toggle(_NORMALMAPDIFFUSE)] _ApplyNormalDiffuse(" Enable Diffuse Normal Sample", Float) = 0.0 _Bias(" Bias", Range(0.0, 8.0)) = 3.0 [Toggle]_VertexNormal(" Use Vertex Normal for Diffuse", Float) = 1 _SSSMap("SSS Map", 2D) = "black" {} _ILMMap("ILM Map",2D) = "gray" {} _DetailMap("Detail Map",2D) = "white" {} _ToonThesHold("ToonThesHold",Range(0,1)) = 0.5 _ToonHardness("ToonHardness",Float) = 20.0 _SpecColor("Spec Color",Color) = (1,1,1,1) _SpecSize("Spec Size",Range(0,1)) = 0.1 _RimLightDir("RimLight Dir",Vector) = (1,0,-1,0) _RimLightColor("RimLight Color",Color) = (1,1,1,1) _OutlineWidth("Outline Width",Float) = 7.0 _OutlineZbias("Outline Zbias",Float) = -10 _OutlineColor("Outline Color",Color) = (1,1,1,1) [Header(Mask)] [Space(8)] _MakeUpMask1_RGB("MakeUpMask1_RGB (R: 眼影 G: 腮红 B: 口红 A: 眼线)", 2D) = "black" {} _MakeUpMask2_RGB("MakeUpMask2_RGB (R: 纹身区域)", 2D) = "black" {} _Mask1_Rchannel_TextureAmountA("Mask1_Rchannel_Texture-Amount(A)", 2D) = "black" {} _Mask1_Gchannel_TextureAmountA("Mask1_Gchannel_Texture-Amount(A)", 2D) = "black" {} _Mask1_Bchannel_TextureAmountA("Mask1_Bchannel_Texture-Amount(A)", 2D) = "black" {} _Mask2_Rchannel_TextureAmountA("Mask2_Rchannel_Texture-Amount(A)", 2D) = "black" {} _Mask2_Gchannel_TextureAmountA("Mask2_Gchannel_Texture-Amount(A)", 2D) = "black" {} _Mask2_Bchannel_TextureAmountA("Mask2_Bchannel_Texture-Amount(A)", 2D) = "black" {} _Mask1_Rchannel_ColorAmountA("Mask1_Rchannel_Color-Amount(A)", Color) = (0.7735849, 0.2006942, 0.3233189, 0.7843137) _Mask1_Gchannel_ColorAmountA("Mask1_Gchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.4917381, 0.7843137) _Mask1_Bchannel_ColorAmountA("Mask1_Bchannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137) _Mask1_Achannel_ColorAmountA("Mask1_Achannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137) _Mask2_Rchannel_ColorAmountA("Mask2_Rchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.7071339, 0.7843137) _Mask2_Gchannel_ColorAmountA("Mask2_Gchannel_Color-Amount(A)", Color) = (0.772549, 0.2, 0.6776864, 0.7843137) _Mask2_Bchannel_ColorAmountA("Mask2_Bchannel_Color-Amount(A)", Color) = (0.772549, 0.7037676, 0.2, 0.7843137) // Needed by the inspector [HideInInspector] _Culling("Culling", Float) = 0.0 // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff [HideInInspector] _MainTex("Albedo", 2D) = "white" {} [HideInInspector] _Color("Color", Color) = (1,1,1,1) [HideInInspector] _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.0 // URP 10.1. needs this for the depthnormal pass [HideInInspector] _Cutoff(" Threshold", Range(0.0, 1.0)) = 0.5 [HideInInspector] _Surface("__surface", Float) = 0.0 } SubShader { Tags { "RenderPipeline" = "UniversalPipeline" "RenderType" = "Opaque" "Queue" = "Geometry" } LOD 100 Pass { Tags { "LightMode" = "UniversalForward" } HLSLPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN #pragma multi_compile_fragment _ _SHADOWS_SOFT #pragma multi_compile _ _ADDITIONAL_LIGHTS #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS //#pragma multi_compile_fwdbase //#include "UnityCG.cginc" //#include "AutoLight.cginc" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" #include "Includes/Lux URP Skin Inputs Custom Toon.hlsl" struct Attritubes { float4 positionOS : POSITION; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; float3 normalOS : NORMAL; float4 color : COLOR; }; struct Varyings { float4 positionCS : SV_POSITION; float4 uv : TEXCOORD0; float3 positionWS : TEXCOORD1; float3 normalWS : TEXCOORD2; float4 vertexColor : TEXCOORD3; float4 shadowCoord : TEXCOORD4; }; //TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap); TEXTURE2D(_SSSMap); SAMPLER(sampler_SSSMap); TEXTURE2D(_ILMMap); SAMPLER(sampler_ILMMap); TEXTURE2D(_DetailMap); SAMPLER(sampler_DetailMap); /*CBUFFER_START(UnityPerMaterial) float _ToonThesHold; float _ToonHardness; float4 _SpecColor; float _SpecSize; float4 _RimLightDir; float4 _RimLightColor; CBUFFER_END*/ Varyings vert (Attritubes input) { Varyings output = (Varyings)0; VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); output.positionCS = vertexInput.positionCS; output.positionWS = vertexInput.positionWS; //output.positionCS = TransformObjectToHClip(input.positionOS.xyz); //output.positionWS = TransformObjectToWorld(input.positionOS.xyz); output.normalWS = TransformObjectToWorldNormal(input.normalOS); output.uv = float4(input.texcoord0,input.texcoord1); output.vertexColor = input.color; output.shadowCoord = GetShadowCoord(vertexInput); return output; } half4 GetColor(float2 uv) { //half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)) * _BaseColor; half4 albedoAlpha = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv * _BaseMap_ST.xy + _BaseMap_ST.zw) * _BaseColor; //-------------------------------------------------------- float2 uv_MakeUpMask1_RGB = uv.xy * _MakeUpMask1_RGB_ST.xy + _MakeUpMask1_RGB_ST.zw; float4 tex2DNode143 = SAMPLE_TEXTURE2D(_MakeUpMask1_RGB, sampler_MakeUpMask1_RGB, uv_MakeUpMask1_RGB); float2 uv_Mask1_Rchannel_TextureAmountA = uv.xy * _Mask1_Rchannel_TextureAmountA_ST.xy + _Mask1_Rchannel_TextureAmountA_ST.zw; float4 tex2D_mask1_R = SAMPLE_TEXTURE2D(_Mask1_Rchannel_TextureAmountA, sampler_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA); float2 uv_Mask1_Gchannel_TextureAmountA = uv.xy * _Mask1_Gchannel_TextureAmountA_ST.xy + _Mask1_Gchannel_TextureAmountA_ST.zw; float4 tex2D_mask1_G = SAMPLE_TEXTURE2D(_Mask1_Gchannel_TextureAmountA, sampler_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA); float2 uv_Mask1_Bchannel_TextureAmountA = uv.xy * _Mask1_Bchannel_TextureAmountA_ST.xy + _Mask1_Bchannel_TextureAmountA_ST.zw; float4 tex2D_mask1_B = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA); float2 uv_Mask1_Achannel_TextureAmountA = uv.xy * _Mask1_Achannel_TextureAmountA_ST.xy + _Mask1_Achannel_TextureAmountA_ST.zw; float4 tex2D_mask1_A = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Achannel_TextureAmountA); float2 uv_Mask2_Rchannel_TextureAmountA = uv.xy * _Mask2_Rchannel_TextureAmountA_ST.xy + _Mask2_Rchannel_TextureAmountA_ST.zw; float4 tex2D_mask2_R = SAMPLE_TEXTURE2D(_Mask2_Rchannel_TextureAmountA, sampler_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA); float2 uv_Mask2_Gchannel_TextureAmountA = uv.xy * _Mask2_Gchannel_TextureAmountA_ST.xy + _Mask2_Gchannel_TextureAmountA_ST.zw; float4 tex2D_mask2_G = SAMPLE_TEXTURE2D(_Mask2_Gchannel_TextureAmountA, sampler_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA); float2 uv_Mask2_Bchannel_TextureAmountA = uv.xy * _Mask2_Bchannel_TextureAmountA_ST.xy + _Mask2_Bchannel_TextureAmountA_ST.zw; float4 tex2D_mask2_B = SAMPLE_TEXTURE2D(_Mask2_Bchannel_TextureAmountA, sampler_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA); float clampResult295 = clamp((tex2DNode143.r * tex2D_mask1_R.a * _Mask1_Rchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_R_Color = tex2D_mask1_R * _Mask1_Rchannel_ColorAmountA; float4 lerpResult145 = lerp(albedoAlpha, _Mask1_R_Color, clampResult295); float clampResult296 = clamp((tex2DNode143.g * tex2D_mask1_G.a * _Mask1_Gchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_G_Color = tex2D_mask1_G * _Mask1_Gchannel_ColorAmountA; float4 lerpResult160 = lerp(lerpResult145, _Mask1_G_Color, clampResult296); float clampResult297 = clamp((tex2DNode143.b * tex2D_mask1_B.a * _Mask1_Bchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_B_Color = tex2D_mask1_B * _Mask1_Bchannel_ColorAmountA; float4 lerpResult161 = lerp(lerpResult160, _Mask1_B_Color, clampResult297); float clampResult2971 = clamp((tex2DNode143.a * tex2D_mask1_A.a * _Mask1_Achannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask1_A_Color = tex2D_mask1_A * _Mask1_Achannel_ColorAmountA; float4 lerpResult1611 = lerp(lerpResult161, _Mask1_A_Color, clampResult2971); //mask2 float2 uv_MakeUpMask2_RGB = uv.xy * _MakeUpMask2_RGB_ST.xy + _MakeUpMask2_RGB_ST.zw; float4 tex2DNode144 = SAMPLE_TEXTURE2D(_MakeUpMask2_RGB, sampler_MakeUpMask2_RGB, uv_MakeUpMask2_RGB); float clampResult298 = clamp((tex2DNode144.r * tex2D_mask2_R.a * _Mask2_Rchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask2_R_Color = tex2D_mask2_R * _Mask2_Rchannel_ColorAmountA; float4 lerpResult162 = lerp(lerpResult1611, _Mask2_Rchannel_ColorAmountA, clampResult298); float clampResult299 = clamp((tex2DNode144.g * tex2D_mask2_G.a * _Mask2_Gchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask2_G_Color = tex2D_mask2_G * _Mask2_Gchannel_ColorAmountA; float4 lerpResult163 = lerp(lerpResult162, _Mask2_Gchannel_ColorAmountA, clampResult299); float clampResult300 = clamp((tex2DNode144.b * tex2D_mask2_B.a * _Mask2_Bchannel_ColorAmountA.a), 0.0, 1.0); float4 _Mask2_B_Color = tex2D_mask2_B * _Mask2_Bchannel_ColorAmountA; float4 lerpResult164 = lerp(lerpResult163, _Mask2_Bchannel_ColorAmountA, clampResult300); albedoAlpha.rgb = half3(lerpResult164.r, lerpResult164.g, lerpResult164.b); return albedoAlpha; } half4 frag (Varyings input) : SV_Target { // clip cloth mask half v_ClothMask1 = _ClothMask1.Sample(sampler_ClothMask1, input.uv.xy).r; clip(v_ClothMask1 - 0.5); half v_ClothMask2 = _ClothMask2.Sample(sampler_ClothMask2, input.uv.xy).r; clip(v_ClothMask2 - 0.5); half v_ClothMask3 = _ClothMask3.Sample(sampler_ClothMask3, input.uv.xy).r; clip(v_ClothMask3 - 0.5); half2 uv1 = input.uv.xy; half2 uv2 = input.uv.zw; //向量 float3 normalDir = normalize(input.normalWS); //float3 lightDir = normalize(_MainLightPosition.xyz); float3 viewDir = normalize(_WorldSpaceCameraPos - input.positionWS); //Base贴图 //half4 base_map = SAMPLE_TEXTURE2D(_BaseMap,sampler_BaseMap,uv1); half4 base_map = GetColor(uv1); half3 base_color = base_map.rgb; // 亮部的颜色 half base_mask = base_map.a; //用来区分皮肤和非皮肤区域 //SSS贴图 half4 sss_map = SAMPLE_TEXTURE2D(_SSSMap,sampler_SSSMap, uv1); //half3 sss_color = sss_map.rgb * _BaseColor; //暗部的颜色 //half sss_alpha = sss_map.a; //边缘光的强度控制 half3 sss_color = base_color; //暗部的颜色 half sss_alpha = base_map.a; //边缘光的强度控制 //ILM贴图 half4 ilm_map = SAMPLE_TEXTURE2D(_ILMMap,sampler_ILMMap, uv1); float spec_intensity = ilm_map.r; //控制高光强度 float diffuse_control = ilm_map.g * 2.0 - 1.0; //控制光照的偏移 float spec_size = ilm_map.b; //控制高光形状大小 float inner_line = ilm_map.a; //内描线 //顶点色 float ao = input.vertexColor.r; Light mainLight = GetMainLight(input.shadowCoord,input.positionWS,float4(1.0,1.0,1.0,1.0)); float3 lightDir = mainLight.direction; float shadow = mainLight.shadowAttenuation; //float shadow = MainLightRealtimeShadow(input.shadowCoord); float atten = lerp(1 , shadow, input.vertexColor.g); //漫反射 half NdotL = dot(normalDir, lightDir); half half_lambert = (NdotL + 1.0) * 0.5; half labmbert_term = half_lambert * ao * atten + diffuse_control; half toon_diffuse = saturate((labmbert_term - _ToonThesHold) * _ToonHardness); //多光源 #ifdef _ADDITIONAL_LIGHTS uint pixelLightCount = GetAdditionalLightsCount(); for(uint lightIndex = 0; lightIndex < pixelLightCount; ++lightIndex) { Light light = GetAdditionalLight(lightIndex,input.positionWS,float4(1.0,1.0,1.0,1.0)); half NdotL_add = dot(normalDir, light.direction); half half_lambert_add = (NdotL_add + 1.0) * 0.5; float atten_add = lerp(1 , light.shadowAttenuation * light.distanceAttenuation , input.vertexColor.g); half labmbert_term_add = half_lambert_add * ao * atten_add + diffuse_control; toon_diffuse += saturate((labmbert_term_add * light.color - _ToonThesHold) * _ToonHardness); } #endif half3 final_diffuse = lerp(sss_color, base_color,toon_diffuse); //高光 float NdotV = (dot(normalDir, viewDir) + 1.0) * 0.5; float spec_term = NdotV * ao + diffuse_control; spec_term = half_lambert * 0.9 + spec_term * 0.1; half toon_spec = saturate((spec_term - (1.0 - spec_size * _SpecSize)) * 500); half3 spec_color = (_SpecColor.rgb + base_color) * 0.5; half3 final_spec = toon_spec * spec_color * spec_intensity; //描线 half3 inner_line_color = lerp(base_color * 0.2,float3(1.0,1.0,1.0),inner_line); half3 detail_color = SAMPLE_TEXTURE2D(_DetailMap,sampler_DetailMap, uv2);//第二套UV Detail细节图 detail_color = lerp(base_color * 0.2, float3(1.0, 1.0, 1.0), detail_color); half3 final_line = inner_line_color * inner_line_color * detail_color; //补光、边缘 float3 lightDir_rim = normalize(mul((float3x3)unity_MatrixInvV,_RimLightDir.xyz)); half NdotL_rim = (dot(normalDir, lightDir_rim)+ 1.0) * 0.5; half rimlight_term = NdotL_rim + diffuse_control; half toon_rim = saturate((rimlight_term - _ToonThesHold) * 20); half3 rim_color = (_RimLightColor.rgb + base_color) * 0.5 * sss_alpha; half3 final_rimlight = toon_rim * rim_color * base_mask * toon_diffuse * _RimLightColor.a; half3 final_color = (final_diffuse + final_spec + final_rimlight) * final_line; final_color = sqrt(max(exp2(log2(max(final_color, 0.0)) * 2.2), 0.0)); return float4(final_color,1.0); } ENDHLSL } Pass { Cull Front CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "AutoLight.cginc" struct appdata { float4 vertex : POSITION; float2 texcoord0 : TEXCOORD0; float3 normal : NORMAL; float4 color : COLOR; }; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float4 vertex_color : TEXCOORD3; }; sampler2D _BaseMap; sampler2D _SSSMap; sampler2D _ILMMap; float _OutlineWidth; float _OutlineZbias; float4 _OutlineColor; sampler2D _ClothMask1; sampler2D _ClothMask2; sampler2D _ClothMask3; v2f vert (appdata v) { v2f o; float3 pos_view = UnityObjectToViewPos(v.vertex); float3 normal_world = UnityObjectToWorldNormal(v.normal); float3 outline_dir = normalize(mul((float3x3)UNITY_MATRIX_V, normal_world)); outline_dir.z = _OutlineZbias * (1.0 - v.color.b); pos_view += outline_dir * _OutlineWidth * 0.001 * v.color.a; o.pos = mul(UNITY_MATRIX_P, float4(pos_view, 1.0)); o.uv = v.texcoord0; o.vertex_color = v.color; return o; } half4 frag(v2f i) : SV_Target { half v_ClothMask1 = tex2D(_ClothMask1, i.uv.xy).r;//_ClothMask1.Sample(sampler_ClothMask1, input.uv.xy).r; clip(v_ClothMask1 - 0.5); half v_ClothMask2 = tex2D(_ClothMask2, i.uv.xy).r; clip(v_ClothMask2 - 0.5); half v_ClothMask3 = tex2D(_ClothMask3, i.uv.xy).r; clip(v_ClothMask3 - 0.5); float3 basecolor = tex2D(_BaseMap, i.uv.xy).xyz; half maxComponent = max(max(basecolor.r, basecolor.g), basecolor.b) - 0.004; half3 saturatedColor = step(maxComponent.rrr, basecolor) * basecolor; saturatedColor = lerp(basecolor.rgb, saturatedColor, 0.6); half3 outlineColor = 0.8 * saturatedColor * basecolor * _OutlineColor.xyz; return float4(outlineColor, 1.0); } ENDCG } Pass { Name "ShadowCaster" Tags{"LightMode" = "ShadowCaster"} ZWrite On ZTest LEqual ColorMask 0 Cull[_Cull] HLSLPROGRAM #pragma exclude_renderers gles gles3 glcore #pragma target 4.5 // ------------------------------------- // Material Keywords #pragma shader_feature_local_fragment _ALPHATEST_ON #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A //-------------------------------------- // GPU Instancing #pragma multi_compile_instancing #pragma multi_compile _ DOTS_INSTANCING_ON // ------------------------------------- // Universal Pipeline keywords // This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW #pragma vertex ShadowPassVertex #pragma fragment ShadowPassFragment #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl" ENDHLSL } Pass { Name "DepthOnly" Tags{"LightMode" = "DepthOnly"} ZWrite On ColorMask 0 Cull[_Cull] HLSLPROGRAM #pragma exclude_renderers gles gles3 glcore #pragma target 4.5 #pragma vertex DepthOnlyVertex #pragma fragment DepthOnlyFragment // ------------------------------------- // Material Keywords #pragma shader_feature_local_fragment _ALPHATEST_ON #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A //-------------------------------------- // GPU Instancing #pragma multi_compile_instancing #pragma multi_compile _ DOTS_INSTANCING_ON #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl" ENDHLSL } // Pass // { // Name "ForwardLit" // Tags{"LightMode" = "UniversalForward"} // Stencil { // Ref[_Stencil] // ReadMask[_ReadMask] // WriteMask[_WriteMask] // Comp[_StencilComp] // Pass[_StencilOp] // Fail[_StencilFail] // ZFail[_StencilZFail] // } // ZWrite On // Cull Back // HLSLPROGRAM // // Required to compile gles 2.0 with standard SRP library // #pragma prefer_hlslcc gles // #pragma exclude_renderers d3d11_9x // #pragma target 2.0 // // ------------------------------------- // // Material Keywords // #define _SPECULAR_SETUP // #pragma shader_feature_local _NORMALMAP // #pragma shader_feature_local_fragment _NORMALMAPDIFFUSE // #pragma shader_feature_local _DISTANCEFADE // not per fragment // #pragma shader_feature_local_fragment _RIMLIGHTING // #pragma shader_feature_local_fragment _BACKSCATTER // #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF // #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF // #pragma shader_feature_local _RECEIVE_SHADOWS_OFF // // ------------------------------------- // // Universal Pipeline keywords // #pragma multi_compile _ _MAIN_LIGHT_SHADOWS // #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE // #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS // #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS // #pragma multi_compile_fragment _ _SHADOWS_SOFT // #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION // #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING // #pragma multi_compile _ SHADOWS_SHADOWMASK // // ------------------------------------- // // Unity defined keywords // #pragma multi_compile _ DIRLIGHTMAP_COMBINED // #pragma multi_compile _ LIGHTMAP_ON // #pragma multi_compile_fog // //-------------------------------------- // // GPU Instancing // #pragma multi_compile_instancing // // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5 // // Include base inputs and all other needed "base" includes // #include "Includes/Lux URP Skin Inputs Custom.hlsl" // #pragma vertex LitPassVertex // #pragma fragment LitPassFragment // //-------------------------------------- // // Vertex shader // VertexOutput LitPassVertex(VertexInput input) // { // VertexOutput output = (VertexOutput)0; // UNITY_SETUP_INSTANCE_ID(input); // UNITY_TRANSFER_INSTANCE_ID(input, output); // UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); // // Set distance fade value // #if defined(_DISTANCEFADE) // float3 worldInstancePos = UNITY_MATRIX_M._m03_m13_m23; // float3 diff = (_WorldSpaceCameraPos - worldInstancePos); // float dist = dot(diff, diff); // output.fade = saturate((_DistanceFade.x - dist) * _DistanceFade.y); // #else // output.fade = 1.0h; // #endif // VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); // VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); // float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS; // half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS); // half fogFactor = ComputeFogFactor(vertexInput.positionCS.z); // output.uv.xy = input.texcoord; // output.normalWS = normalInput.normalWS; //NormalizeNormalPerVertex(normalInput.normalWS); // output.viewDirWS = viewDirWS; // #ifdef _NORMALMAP // float sign = input.tangentOS.w * GetOddNegativeScale(); // output.tangentWS = float4(normalInput.tangentWS.xyz, sign); // #endif // OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV); // OUTPUT_SH(output.normalWS.xyz, output.vertexSH); // output.fogFactorAndVertexLight = half4(fogFactor, vertexLight); // #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR) // output.positionWS = vertexInput.positionWS; // #endif // #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) // // tweak the sampling position // vertexInput.positionWS += output.normalWS.xyz * _SkinShadowSamplingBias; // output.shadowCoord = GetShadowCoord(vertexInput); // #endif // output.positionCS = vertexInput.positionCS; // return output; // } // //-------------------------------------- // // Fragment shader and functions // inline void InitializeSkinLitSurfaceData(float2 uv, half fade, out SurfaceDescription outSurfaceData) // { // half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)) * _BaseColor; // //-------------------------------------------------------- // float2 uv_MakeUpMask1_RGB = uv.xy * _MakeUpMask1_RGB_ST.xy + _MakeUpMask1_RGB_ST.zw; // float4 tex2DNode143 = SAMPLE_TEXTURE2D(_MakeUpMask1_RGB, sampler_MakeUpMask1_RGB, uv_MakeUpMask1_RGB); // float2 uv_Mask1_Rchannel_TextureAmountA = uv.xy * _Mask1_Rchannel_TextureAmountA_ST.xy + _Mask1_Rchannel_TextureAmountA_ST.zw; // float4 tex2D_mask1_R = SAMPLE_TEXTURE2D(_Mask1_Rchannel_TextureAmountA, sampler_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA); // float2 uv_Mask1_Gchannel_TextureAmountA = uv.xy * _Mask1_Gchannel_TextureAmountA_ST.xy + _Mask1_Gchannel_TextureAmountA_ST.zw; // float4 tex2D_mask1_G = SAMPLE_TEXTURE2D(_Mask1_Gchannel_TextureAmountA, sampler_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA); // float2 uv_Mask1_Bchannel_TextureAmountA = uv.xy * _Mask1_Bchannel_TextureAmountA_ST.xy + _Mask1_Bchannel_TextureAmountA_ST.zw; // float4 tex2D_mask1_B = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA); // float2 uv_Mask1_Achannel_TextureAmountA = uv.xy * _Mask1_Achannel_TextureAmountA_ST.xy + _Mask1_Achannel_TextureAmountA_ST.zw; // float4 tex2D_mask1_A = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Achannel_TextureAmountA); // float2 uv_Mask2_Rchannel_TextureAmountA = uv.xy * _Mask2_Rchannel_TextureAmountA_ST.xy + _Mask2_Rchannel_TextureAmountA_ST.zw; // float4 tex2D_mask2_R = SAMPLE_TEXTURE2D(_Mask2_Rchannel_TextureAmountA, sampler_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA); // float2 uv_Mask2_Gchannel_TextureAmountA = uv.xy * _Mask2_Gchannel_TextureAmountA_ST.xy + _Mask2_Gchannel_TextureAmountA_ST.zw; // float4 tex2D_mask2_G = SAMPLE_TEXTURE2D(_Mask2_Gchannel_TextureAmountA, sampler_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA); // float2 uv_Mask2_Bchannel_TextureAmountA = uv.xy * _Mask2_Bchannel_TextureAmountA_ST.xy + _Mask2_Bchannel_TextureAmountA_ST.zw; // float4 tex2D_mask2_B = SAMPLE_TEXTURE2D(_Mask2_Bchannel_TextureAmountA, sampler_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA); // float clampResult295 = clamp((tex2DNode143.r * tex2D_mask1_R.a * _Mask1_Rchannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask1_R_Color = tex2D_mask1_R * _Mask1_Rchannel_ColorAmountA; // float4 lerpResult145 = lerp(albedoAlpha, _Mask1_R_Color, clampResult295); // float clampResult296 = clamp((tex2DNode143.g * tex2D_mask1_G.a * _Mask1_Gchannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask1_G_Color = tex2D_mask1_G * _Mask1_Gchannel_ColorAmountA; // float4 lerpResult160 = lerp(lerpResult145, _Mask1_G_Color, clampResult296); // float clampResult297 = clamp((tex2DNode143.b * tex2D_mask1_B.a * _Mask1_Bchannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask1_B_Color = tex2D_mask1_B * _Mask1_Bchannel_ColorAmountA; // float4 lerpResult161 = lerp(lerpResult160, _Mask1_B_Color, clampResult297); // float clampResult2971 = clamp((tex2DNode143.a * tex2D_mask1_A.a * _Mask1_Achannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask1_A_Color = tex2D_mask1_A * _Mask1_Achannel_ColorAmountA; // float4 lerpResult1611 = lerp(lerpResult161, _Mask1_A_Color, clampResult2971); // //mask2 // float2 uv_MakeUpMask2_RGB = uv.xy * _MakeUpMask2_RGB_ST.xy + _MakeUpMask2_RGB_ST.zw; // float4 tex2DNode144 = SAMPLE_TEXTURE2D(_MakeUpMask2_RGB, sampler_MakeUpMask2_RGB, uv_MakeUpMask2_RGB); // float clampResult298 = clamp((tex2DNode144.r * tex2D_mask2_R.a * _Mask2_Rchannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask2_R_Color = tex2D_mask2_R * _Mask2_Rchannel_ColorAmountA; // float4 lerpResult162 = lerp(lerpResult1611, _Mask2_Rchannel_ColorAmountA, clampResult298); // float clampResult299 = clamp((tex2DNode144.g * tex2D_mask2_G.a * _Mask2_Gchannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask2_G_Color = tex2D_mask2_G * _Mask2_Gchannel_ColorAmountA; // float4 lerpResult163 = lerp(lerpResult162, _Mask2_Gchannel_ColorAmountA, clampResult299); // float clampResult300 = clamp((tex2DNode144.b * tex2D_mask2_B.a * _Mask2_Bchannel_ColorAmountA.a), 0.0, 1.0); // float4 _Mask2_B_Color = tex2D_mask2_B * _Mask2_Bchannel_ColorAmountA; // float4 lerpResult164 = lerp(lerpResult163, _Mask2_Bchannel_ColorAmountA, clampResult300); // albedoAlpha.rgb = half3(lerpResult164.r, lerpResult164.g, lerpResult164.b); // //-------------------------------- // outSurfaceData.alpha = 1; // outSurfaceData.albedo = albedoAlpha.rgb; // outSurfaceData.metallic = 0; // outSurfaceData.specular = _SpecularColor.rgb; // // Normal Map // #if defined (_NORMALMAP) // outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale); // #if defined(_NORMALMAPDIFFUSE) // half4 sampleNormalDiffuse = SAMPLE_TEXTURE2D_BIAS(_BumpMap, sampler_BumpMap, uv, _Bias); // // Do not manually unpack the normal map as it might use RGB. // outSurfaceData.diffuseNormalTS = UnpackNormal(sampleNormalDiffuse); // #else // outSurfaceData.diffuseNormalTS = half3(0,0,1); // #endif // #else // outSurfaceData.normalTS = half3(0,0,1); // outSurfaceData.diffuseNormalTS = half3(0,0,1); // #endif // half4 SSSAOSample = SAMPLE_TEXTURE2D(_SSSAOMap, sampler_SSSAOMap, uv); // outSurfaceData.translucency = SSSAOSample.g; // outSurfaceData.skinMask = SSSAOSample.r; // outSurfaceData.occlusion = lerp(1.0h, SSSAOSample.a, _OcclusionStrength); // outSurfaceData.curvature = SSSAOSample.b; // outSurfaceData.smoothness = albedoAlpha.a * _Smoothness; // outSurfaceData.emission = SAMPLE_TEXTURE2D(_EmissionMap, sampler_EmissionMap, uv).rgb * _EmissionColor.rgb; // } // void InitializeInputData(VertexOutput input, half3 normalTS, half3 diffuseNormalTS, out InputData inputData // #ifdef _NORMALMAP // , inout float3 bitangent // #endif // , inout half3 diffuseNormalWS // ) // { // inputData = (InputData)0; // #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR) // inputData.positionWS = input.positionWS; // #endif // half3 viewDirWS = SafeNormalize(input.viewDirWS); // #ifdef _NORMALMAP // float sgn = input.tangentWS.w; // should be either +1 or -1 // bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz); // half3x3 ToW = half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz); // inputData.normalWS = TransformTangentToWorld(normalTS, ToW); // inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS); // #ifdef _NORMALMAPDIFFUSE // diffuseNormalWS = TransformTangentToWorld(diffuseNormalTS, ToW); // diffuseNormalWS = NormalizeNormalPerPixel(diffuseNormalWS); // #else // // Here we let the user decide to use the per vertex or the specular normal. // diffuseNormalWS = (_VertexNormal) ? NormalizeNormalPerPixel(input.normalWS.xyz) : inputData.normalWS; // #endif // #else // inputData.normalWS = NormalizeNormalPerPixel(input.normalWS); // diffuseNormalWS = inputData.normalWS; // #endif // inputData.viewDirectionWS = viewDirWS; // #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) // inputData.shadowCoord = input.shadowCoord; // #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) // inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS + input.normalWS * _SkinShadowSamplingBias); // #else // inputData.shadowCoord = float4(0, 0, 0, 0); // #endif // inputData.fogCoord = input.fogFactorAndVertexLight.x; // inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; // inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, diffuseNormalWS); //inputData.normalWS); // //inputData.normalizedScreenSpaceUV = input.positionCS.xy; // inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS); // } // half4 LitPassFragment(VertexOutput input) : SV_Target // { // UNITY_SETUP_INSTANCE_ID(input); // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); // // clip cloth mask // half v_ClothMask1 = _ClothMask1.Sample(sampler_ClothMask1, input.uv.xy).r; // clip(v_ClothMask1 - 0.5); // half v_ClothMask2 = _ClothMask2.Sample(sampler_ClothMask1, input.uv.xy).r; // clip(v_ClothMask2 - 0.5); // half v_ClothMask3 = _ClothMask3.Sample(sampler_ClothMask1, input.uv.xy).r; // clip(v_ClothMask3 - 0.5); // // Get the surface description // SurfaceDescription surfaceData; // InitializeSkinLitSurfaceData(input.uv.xy, input.fade, surfaceData); // // Prepare surface data (like bring normal into world space and get missing inputs like gi // half3 diffuseNormalWS; // InputData inputData; // #ifdef _NORMALMAP // float3 bitangent; // #endif // InitializeInputData(input, surfaceData.normalTS, surfaceData.diffuseNormalTS, inputData // #ifdef _NORMALMAP // , bitangent // #endif // , diffuseNormalWS // ); // #if defined(_RIMLIGHTING) // half rim = saturate(1.0h - saturate(dot(inputData.normalWS, inputData.viewDirectionWS))); // half power = _RimPower; // UNITY_BRANCH if (_RimFrequency > 0) { // half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h) * _RimPerPositionFrequency) * 3.1416h; // power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition)) * 0.5h); // } // surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a; // #endif // // Apply lighting // half4 color = LuxLWRPSkinFragmentPBR( // inputData, // surfaceData.albedo, // surfaceData.metallic, // surfaceData.specular, // surfaceData.smoothness, // surfaceData.occlusion, // surfaceData.emission, // surfaceData.alpha, // // Subsurface Scattering // half4(_TranslucencyStrength * surfaceData.translucency, _TranslucencyPower, _ShadowStrength, _Distortion), // // AmbientReflection Strength // _AmbientReflectionStrength, // // Diffuse Normal // // #if defined(_NORMALMAP) && defined(_NORMALMAPDIFFUSE) // // NormalizeNormalPerPixel( TransformTangentToWorld(surfaceData.diffuseNormalTS, half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz)) ) // // #else // // input.normalWS // // #endif // diffuseNormalWS, // _SubsurfaceColor.rgb, // (_SampleCurvature) ? surfaceData.curvature * _Curvature : lerp(surfaceData.translucency, 1, _Curvature), // // Lerp lighting towards standard according the distance fade // surfaceData.skinMask * input.fade, // _MaskByShadowStrength, // _Backscatter // ); // // Add fog // color.rgb = MixFog(color.rgb, inputData.fogCoord); // return color; // } // ENDHLSL // } // // Shadows ----------------------------------------------------- // Pass // { // Name "ShadowCaster" // Tags{"LightMode" = "ShadowCaster"} // ZWrite On // ZTest LEqual // ColorMask 0 // Cull Back // HLSLPROGRAM // // Required to compile gles 2.0 with standard srp library // #pragma prefer_hlslcc gles // #pragma exclude_renderers d3d11_9x // #pragma target 2.0 // // ------------------------------------- // // Material Keywords // //-------------------------------------- // // GPU Instancing // #pragma multi_compile_instancing // #pragma vertex ShadowPassVertex // #pragma fragment ShadowPassFragment // // Include base inputs and all other needed "base" includes // #include "Includes/Lux URP Skin Inputs Custom.hlsl" // #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" // // Shadow caster specific input // float3 _LightDirection; // VertexOutput ShadowPassVertex(VertexInput input) // { // VertexOutput output = (VertexOutput)0; // UNITY_SETUP_INSTANCE_ID(input); // UNITY_TRANSFER_INSTANCE_ID(input, output); // float3 positionWS = TransformObjectToWorld(input.positionOS.xyz); // float3 normalWS = TransformObjectToWorldDir(input.normalOS); // output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS * _SkinShadowBias, _LightDirection)); // #if UNITY_REVERSED_Z // output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE); // #else // output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE); // #endif // return output; // } // half4 ShadowPassFragment(VertexOutput input) : SV_TARGET // { // UNITY_SETUP_INSTANCE_ID(input); // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); // return 0; // } // ENDHLSL // } //// Depth ----------------------------------------------------- // Pass // { // Tags{"LightMode" = "DepthOnly"} // ZWrite On // ColorMask 0 // Cull Back // HLSLPROGRAM // // Required to compile gles 2.0 with standard srp library // #pragma prefer_hlslcc gles // #pragma exclude_renderers d3d11_9x // #pragma target 2.0 // #pragma vertex DepthOnlyVertex // #pragma fragment DepthOnlyFragment // // ------------------------------------- // // Material Keywords // //-------------------------------------- // // GPU Instancing // #pragma multi_compile_instancing // #define DEPTHONLYPASS // #include "Includes/Lux URP Skin Inputs Custom.hlsl" // VertexOutput DepthOnlyVertex(VertexInput input) // { // VertexOutput output = (VertexOutput)0; // UNITY_SETUP_INSTANCE_ID(input); // UNITY_TRANSFER_INSTANCE_ID(input, output); // UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); // output.positionCS = TransformObjectToHClip(input.positionOS.xyz); // return output; // } // half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET // { // UNITY_SETUP_INSTANCE_ID(input); // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input); // return 0; // } // ENDHLSL // } //// Depth Normals -------------------------------------------- // Pass // { // Name "DepthNormals" // Tags{"LightMode" = "DepthNormals"} // ZWrite On // Cull Back // HLSLPROGRAM // // Required to compile gles 2.0 with standard SRP library // #pragma prefer_hlslcc gles // #pragma exclude_renderers d3d11_9x // #pragma target 2.0 // #pragma vertex DepthNormalsVertex // #pragma fragment DepthNormalsFragment // // ------------------------------------- // // Material Keywords // #pragma shader_feature_local _NORMALMAP // //-------------------------------------- // // GPU Instancing // #pragma multi_compile_instancing // // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5 // //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" // #include "Includes/Lux URP Skin Inputs Custom.hlsl" // #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl" // ENDHLSL // } //// Meta ----------------------------------------------------- // Pass // { // Tags{"LightMode" = "Meta"} // Cull Off // HLSLPROGRAM // // Required to compile gles 2.0 with standard srp library // #pragma prefer_hlslcc gles // #pragma vertex UniversalVertexMeta // #pragma fragment UniversalFragmentMeta // #define _SPECULAR_SETUP // // First include all our custom stuff // #include "Includes/Lux URP Skin Inputs Custom.hlsl" // //-------------------------------------- // // Fragment shader and functions // inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData) // { // half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)); // outSurfaceData.alpha = 1; // outSurfaceData.albedo = albedoAlpha.rgb; // outSurfaceData.metallic = 0; // outSurfaceData.specular = _SpecularColor.rgb; // outSurfaceData.smoothness = _Smoothness; // outSurfaceData.normalTS = half3(0,0,1); // outSurfaceData.occlusion = 1; // outSurfaceData.emission = 0; // outSurfaceData.clearCoatMask = 0; // outSurfaceData.clearCoatSmoothness = 0; // } // // Finally include the meta pass related stuff // #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl" // ENDHLSL // } // End Passes ----------------------------------------------------- } CustomEditor "LuxURPCustomSkinShaderGUI" FallBack "Hidden/InternalErrorShader" }