├── Images ├── image_0.png └── image_1.png ├── LICENSE ├── README.md ├── Scripts └── MaterialUpdater.cs └── Shaders ├── ToonForwardPass.hlsl ├── ToonInput.hlsl ├── ToonOutlinePass.hlsl └── URPGenshinToon.shader /Images/image_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaze-mio/UnityGenshinToonShader/af8f00c7a0cac455b308238576b344df7ed1cc1f/Images/image_0.png -------------------------------------------------------------------------------- /Images/image_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaze-mio/UnityGenshinToonShader/af8f00c7a0cac455b308238576b344df7ed1cc1f/Images/image_1.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 风澪瑟 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityGenshinToonShader 2 | 3 | A custom genshin-like toon shader, based on URP 4 | 5 | 基于 URP 的仿原神风格化渲染着色器 6 | 7 | ## Supported Features 8 | 9 | - **Light Map** (R / B for specular, G for AO, A for material type) 10 | - **Shadow Ramp** 11 | - **Emission** 12 | - **Normal Map** 13 | - **Face Shadow**, based on SDF Light Map 14 | - **Face Blush** 15 | - **Nonmetallic and Metallic Specular**, based on Blinn-Phong Model 16 | - **Rim Light**, based on Depth Texture and Fresnel 17 | - **Outline**, based on Back Facing 18 | - **Double-Sided Rendering** 19 | 20 | ## Scripts 21 | 22 | - **MaterialUpdater** : pass face direction to material 23 | 24 | ## References 25 | 26 | - A Unity sample project, for rendering Genshin characters like Nahida. 27 | 28 | [NahidaRenderProject](https://github.com/kaze-mio/NahidaRenderProject) 29 | 30 | - A genshin-like post processing render feature, based on URP. 31 | 32 | [UnityGenshinPostProcessing](https://github.com/kaze-mio/UnityGenshinPostProcessing) 33 | 34 | ## Render Examples 35 | 36 | ![image_0](Images/image_0.png) 37 | ![image_1](Images/image_1.png) 38 | 39 | -------------------------------------------------------------------------------- /Scripts/MaterialUpdater.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | public class MaterialUpdater : MonoBehaviour 5 | { 6 | [SerializeField] 7 | private GameObject m_HeadBone; 8 | 9 | [SerializeField] 10 | private Vector3 m_HeadDirection = Vector3.up; 11 | 12 | [SerializeField] 13 | private List m_FaceRenderers; 14 | 15 | private void Update() 16 | { 17 | if (m_FaceRenderers == null || m_HeadBone == null) 18 | { 19 | return; 20 | } 21 | Vector3 direction = m_HeadBone.transform.rotation * m_HeadDirection; 22 | foreach (var renderer in m_FaceRenderers) 23 | { 24 | foreach (var material in renderer.materials) 25 | { 26 | material.SetVector("_FaceDirection", direction); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Shaders/ToonForwardPass.hlsl: -------------------------------------------------------------------------------- 1 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 2 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 3 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" 4 | 5 | struct Attributes 6 | { 7 | float4 positionOS : POSITION; 8 | float3 normalOS : NORMAL; 9 | float4 tangentOS : TANGENT; 10 | float4 color : COLOR; 11 | float2 uv : TEXCOORD0; 12 | float2 backUV : TEXCOORD1; 13 | }; 14 | 15 | struct Varyings 16 | { 17 | float2 uv : TEXCOORD0; 18 | float2 backUV : TEXCOORD1; 19 | float3 positionWS : TEXCOORD2; 20 | half3 tangentWS : TEXCOORD3; 21 | half3 bitangentWS : TEXCOORD4; 22 | half3 normalWS : TEXCOORD5; 23 | float4 positionNDC : TEXCOORD6; 24 | half4 color : COLOR; 25 | float4 positionCS : SV_POSITION; 26 | }; 27 | 28 | half GetShadow(Varyings input, half3 lightDirection, half aoFactor) 29 | { 30 | half NDotL = dot(input.normalWS, lightDirection); 31 | half halfLambert = 0.5 * NDotL + 0.5; 32 | half shadow = saturate(2.0 * halfLambert * aoFactor); 33 | return lerp(shadow, 1.0, step(0.9, aoFactor)); 34 | } 35 | 36 | half GetFaceShadow(Varyings input, half3 lightDirection) 37 | { 38 | half3 F = SafeNormalize(half3(_FaceDirection.x, 0.0, _FaceDirection.z)); 39 | half3 L = SafeNormalize(half3(lightDirection.x, 0.0, lightDirection.z)); 40 | half FDotL = dot(F, L); 41 | half FCrossL = cross(F, L).y; 42 | 43 | half2 shadowUV = input.uv; 44 | shadowUV.x = lerp(shadowUV.x, 1.0 - shadowUV.x, step(0.0, FCrossL)); 45 | half faceShadowMap = SAMPLE_TEXTURE2D(_FaceLightMap, sampler_FaceLightMap, shadowUV).r; 46 | half faceShadow = step(-0.5 * FDotL + 0.5 + _FaceShadowOffset, faceShadowMap); 47 | 48 | half faceMask = SAMPLE_TEXTURE2D(_FaceShadow, sampler_FaceShadow, input.uv).a; 49 | half maskedFaceShadow = lerp(faceShadow, 1.0, faceMask); 50 | 51 | return maskedFaceShadow; 52 | } 53 | 54 | half3 GetShadowColor(half shadow, half material, half day) 55 | { 56 | int index = 4; 57 | index = lerp(index, 1, step(0.2, material)); 58 | index = lerp(index, 2, step(0.4, material)); 59 | index = lerp(index, 0, step(0.6, material)); 60 | index = lerp(index, 3, step(0.8, material)); 61 | 62 | half rangeMin = 0.5 + _ShadowOffset - _ShadowSmoothness; 63 | half rangeMax = 0.5 + _ShadowOffset; 64 | half2 rampUV = half2(smoothstep(rangeMin, rangeMax, shadow), index / 10.0 + 0.5 * day + 0.05); 65 | half3 shadowRamp = SAMPLE_TEXTURE2D(_ShadowRamp, sampler_ShadowRamp, rampUV); 66 | 67 | half3 shadowColor = shadowRamp * lerp(_ShadowColor, 1.0, smoothstep(0.9, 1.0, rampUV.x)); 68 | shadowColor = lerp(shadowColor, 1.0, step(rangeMax, shadow)); 69 | 70 | return shadowColor; 71 | } 72 | 73 | half3 GetSpecular(Varyings input, half3 lightDirection, half3 albedo, half3 lightMap) 74 | { 75 | half3 V = GetWorldSpaceNormalizeViewDir(input.positionWS); 76 | half3 H = SafeNormalize(lightDirection + V); 77 | half NDotH = dot(input.normalWS, H); 78 | half blinnPhong = pow(saturate(NDotH), _SpecularSmoothness); 79 | 80 | half3 normalVS = TransformWorldToViewNormal(input.normalWS, true); 81 | half2 matcapUV = 0.5 * normalVS.xy + 0.5; 82 | half3 metalMap = SAMPLE_TEXTURE2D(_MetalMap, sampler_MetalMap, matcapUV); 83 | 84 | half3 nonMetallic = step(1.1, lightMap.b + blinnPhong) * lightMap.r * _NonmetallicIntensity; 85 | half3 metallic = blinnPhong * lightMap.b * albedo * metalMap * _MetallicIntensity; 86 | half3 specular = lerp(nonMetallic, metallic, step(0.9, lightMap.r)); 87 | 88 | return specular; 89 | } 90 | 91 | half GetRim(Varyings input) 92 | { 93 | half3 normalVS = TransformWorldToViewNormal(input.normalWS, true); 94 | float2 uv = input.positionNDC.xy / input.positionNDC.w; 95 | float2 offset = float2(_RimOffset * normalVS.x / _ScreenParams.x, 0.0); 96 | 97 | float depth = LinearEyeDepth(SampleSceneDepth(uv), _ZBufferParams); 98 | float offsetDepth = LinearEyeDepth(SampleSceneDepth(uv + offset), _ZBufferParams); 99 | half rim = smoothstep(0.0, _RimThreshold, offsetDepth - depth) * _RimIntensity; 100 | 101 | half3 V = GetWorldSpaceNormalizeViewDir(input.positionWS); 102 | half NDotV = dot(input.normalWS, V); 103 | half fresnel = pow(saturate(1.0 - NDotV), 5.0); 104 | 105 | return rim * fresnel; 106 | } 107 | 108 | Varyings ForwardPassVertex(Attributes input) 109 | { 110 | VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); 111 | VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); 112 | 113 | Varyings output = (Varyings)0; 114 | output.uv = TRANSFORM_TEX(input.uv, _BaseMap); 115 | output.backUV = TRANSFORM_TEX(input.backUV, _BaseMap); 116 | output.positionWS = vertexInput.positionWS; 117 | output.tangentWS = normalInput.tangentWS; 118 | output.bitangentWS = normalInput.bitangentWS; 119 | output.normalWS = normalInput.normalWS; 120 | output.color = input.color; 121 | output.positionNDC = vertexInput.positionNDC; 122 | output.positionCS = vertexInput.positionCS; 123 | 124 | output.positionCS.xy += _ScreenOffset.xy * output.positionCS.w; 125 | 126 | return output; 127 | } 128 | 129 | half4 ForwardPassFragment(Varyings input, FRONT_FACE_TYPE facing : FRONT_FACE_SEMANTIC) : SV_TARGET 130 | { 131 | #if _DOUBLE_SIDED 132 | input.uv = lerp(input.uv, input.backUV, IS_FRONT_VFACE(facing, 0.0, 1.0)); 133 | #endif 134 | 135 | half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv); 136 | half3 albedo = baseMap.rgb * _BaseColor.rgb; 137 | half alpha = baseMap.a; 138 | 139 | #if _IS_FACE 140 | albedo = lerp(albedo, _FaceBlushColor.rgb, _FaceBlushStrength * alpha); 141 | #endif 142 | 143 | #if _NORMAL_MAP 144 | half3x3 tangentToWorld = half3x3(input.tangentWS, input.bitangentWS, input.normalWS); 145 | half4 normalMap = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.uv); 146 | half3 normalTS = UnpackNormal(normalMap); 147 | half3 normalWS = TransformTangentToWorld(normalTS, tangentToWorld, true); 148 | input.normalWS = normalWS; 149 | #endif 150 | 151 | Light mainLight = GetMainLight(); 152 | half3 lightDirection = SafeNormalize(mainLight.direction * _LightDirectionMultiplier); 153 | 154 | half4 lightMap = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.uv); 155 | half material = lerp(lightMap.a, _CustomMaterialType, _UseCustomMaterialType); 156 | #if _IS_FACE 157 | half shadow = GetFaceShadow(input, lightDirection); 158 | #else 159 | half aoFactor = lightMap.g * input.color.r; 160 | half shadow = GetShadow(input, lightDirection, aoFactor); 161 | #endif 162 | half3 shadowColor = GetShadowColor(shadow, material, _IsDay); 163 | 164 | half3 specular = 0.0; 165 | #if _SPECULAR 166 | specular = GetSpecular(input, lightDirection, albedo, lightMap.rgb); 167 | #endif 168 | 169 | half3 emission = 0.0; 170 | #if _EMISSION 171 | emission = albedo * _EmissionIntensity * alpha; 172 | #endif 173 | 174 | half3 rim = 0.0; 175 | #if _RIM 176 | rim = albedo * GetRim(input); 177 | #endif 178 | 179 | half3 finalColor = albedo * shadowColor + specular + rim + emission; 180 | half finalAlpha = 1.0; 181 | 182 | return half4(finalColor, finalAlpha); 183 | } 184 | -------------------------------------------------------------------------------- /Shaders/ToonInput.hlsl: -------------------------------------------------------------------------------- 1 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 2 | 3 | CBUFFER_START(UnityPerMaterial) 4 | float4 _BaseMap_ST; 5 | half4 _BaseColor; 6 | half _IsDay; 7 | half _Cull; 8 | half _SrcBlend; 9 | half _DstBlend; 10 | 11 | half4 _LightDirectionMultiplier; 12 | half _ShadowOffset; 13 | half _ShadowSmoothness; 14 | half4 _ShadowColor; 15 | half _UseCustomMaterialType; 16 | half _CustomMaterialType; 17 | 18 | half _EmissionIntensity; 19 | 20 | half4 _FaceDirection; 21 | half _FaceShadowOffset; 22 | half4 _FaceBlushColor; 23 | half _FaceBlushStrength; 24 | 25 | half _SpecularSmoothness; 26 | half _NonmetallicIntensity; 27 | half _MetallicIntensity; 28 | 29 | half _RimOffset; 30 | half _RimThreshold; 31 | half _RimIntensity; 32 | 33 | half _UseSmoothNormal; 34 | half _OutlineWidth; 35 | half4 _OutlineWidthParams; 36 | half _OutlineZOffset; 37 | half4 _ScreenOffset; 38 | half4 _OutlineColor; 39 | half4 _OutlineColor2; 40 | half4 _OutlineColor3; 41 | half4 _OutlineColor4; 42 | half4 _OutlineColor5; 43 | CBUFFER_END 44 | 45 | TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap); 46 | TEXTURE2D(_LightMap); SAMPLER(sampler_LightMap); 47 | TEXTURE2D(_ShadowRamp); SAMPLER(sampler_ShadowRamp); 48 | TEXTURE2D(_NormalMap); SAMPLER(sampler_NormalMap); 49 | TEXTURE2D(_FaceLightMap); SAMPLER(sampler_FaceLightMap); 50 | TEXTURE2D(_FaceShadow); SAMPLER(sampler_FaceShadow); 51 | TEXTURE2D(_MetalMap); SAMPLER(sampler_MetalMap); 52 | -------------------------------------------------------------------------------- /Shaders/ToonOutlinePass.hlsl: -------------------------------------------------------------------------------- 1 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" 2 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" 3 | 4 | struct Attributes 5 | { 6 | float4 positionOS : POSITION; 7 | float3 normalOS : NORMAL; 8 | float4 tangentOS : TANGENT; 9 | float4 color : COLOR; 10 | float2 uv : TEXCOORD0; 11 | float3 smoothNormal : TEXCOORD7; 12 | }; 13 | 14 | struct Varyings 15 | { 16 | float2 uv : TEXCOORD0; 17 | float4 positionCS : SV_POSITION; 18 | }; 19 | 20 | float GetOutlineWidth(float positionVS_Z) 21 | { 22 | float fovFactor = 2.414 / UNITY_MATRIX_P[1].y; 23 | float z = abs(positionVS_Z * fovFactor); 24 | 25 | float4 params = _OutlineWidthParams; 26 | float k = saturate((z - params.x) / (params.y - params.x)); 27 | float width = lerp(params.z, params.w, k); 28 | 29 | return 0.01 * _OutlineWidth * width; 30 | } 31 | 32 | float4 GetOutlinePosition(VertexPositionInputs vertexInput, VertexNormalInputs normalInput, half4 vertexColor) 33 | { 34 | float z = vertexInput.positionVS.z; 35 | float width = GetOutlineWidth(z) * vertexColor.a; 36 | 37 | half3 normalVS = TransformWorldToViewNormal(normalInput.normalWS); 38 | normalVS = SafeNormalize(half3(normalVS.xy, 0.0)); 39 | 40 | float3 positionVS = vertexInput.positionVS; 41 | positionVS += 0.01 * _OutlineZOffset * SafeNormalize(positionVS); 42 | positionVS += width * normalVS; 43 | 44 | float4 positionCS = TransformWViewToHClip(positionVS); 45 | positionCS.xy += _ScreenOffset.zw * positionCS.w; 46 | 47 | return positionCS; 48 | } 49 | 50 | Varyings OutlinePassVertex(Attributes input) 51 | { 52 | VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz); 53 | VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS); 54 | 55 | half3x3 tangentToWorld = half3x3(normalInput.tangentWS, normalInput.bitangentWS, normalInput.normalWS); 56 | half3 normalTS = 2.0 * (input.smoothNormal - 0.5); 57 | half3 normalWS = TransformTangentToWorld(normalTS, tangentToWorld, true); 58 | normalInput.normalWS = lerp(normalInput.normalWS, normalWS, _UseSmoothNormal); 59 | 60 | float4 positionCS = GetOutlinePosition(vertexInput, normalInput, input.color); 61 | 62 | Varyings output = (Varyings)0; 63 | output.uv = TRANSFORM_TEX(input.uv, _BaseMap); 64 | output.positionCS = positionCS; 65 | 66 | return output; 67 | } 68 | 69 | half4 OutlinePassFragment(Varyings input) : SV_TARGET 70 | { 71 | half4 lightMap = SAMPLE_TEXTURE2D(_LightMap, sampler_LightMap, input.uv); 72 | half material = lightMap.a; 73 | 74 | half4 color = _OutlineColor5; 75 | color = lerp(color, _OutlineColor4, step(0.2, material)); 76 | color = lerp(color, _OutlineColor3, step(0.4, material)); 77 | color = lerp(color, _OutlineColor2, step(0.6, material)); 78 | color = lerp(color, _OutlineColor, step(0.8, material)); 79 | 80 | return color; 81 | } 82 | -------------------------------------------------------------------------------- /Shaders/URPGenshinToon.shader: -------------------------------------------------------------------------------- 1 | Shader "URPGenshinToon" 2 | { 3 | Properties 4 | { 5 | [Header(General)] 6 | [MainTexture]_BaseMap("Base Map", 2D) = "white" {} 7 | [MainColor] _BaseColor("Base Color", Color) = (1,1,1,1) 8 | [ToggleUI] _IsDay("Is Day", Float) = 1 9 | [Toggle(_DOUBLE_SIDED)] _DoubleSided("Double Sided", Float) = 0 10 | [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull", Float) = 2 11 | [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 1 12 | [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 0 13 | 14 | [Header(Shadow)] 15 | _LightMap("Light Map", 2D) = "white" {} 16 | _LightDirectionMultiplier("Light Direction Multiplier", Vector) = (1,1,1,0) 17 | _ShadowOffset("Shadow Offset", Float) = 0 18 | _ShadowSmoothness("Shadow Smoothness", Float) = 0 19 | [HDR] _ShadowColor("Shadow Color", Color) = (1,1,1,1) 20 | _ShadowRamp("Shadow Ramp", 2D) = "white" {} 21 | [ToggleUI] _UseCustomMaterialType("Use Custom Material Type", Float) = 0 22 | _CustomMaterialType("Custom Material Type", Float) = 1 23 | 24 | [Header(Emission)] 25 | [Toggle(_EMISSION)] _UseEmission("Use Emission", Float) = 0 26 | _EmissionIntensity("Emission Intensity", Float) = 1 27 | 28 | [Header(Normal)] 29 | [Toggle(_NORMAL_MAP)] _UseNormalMap("Use Normal Map", Float) = 0 30 | [Normal] _NormalMap("Normal Map", 2D) = "bump" {} 31 | 32 | [Header(Face)] 33 | [Toggle(_IS_FACE)] _IsFace("Is Face", Float) = 0 34 | _FaceDirection("Face Direction", Vector) = (0,0,1,0) 35 | _FaceShadowOffset("Face Shadow Offset", Float) = 0 36 | _FaceBlushColor("Face Blush Color", Color) = (1,1,1,1) 37 | _FaceBlushStrength("Face Blush Strength", Float) = 1 38 | _FaceLightMap("Face Light Map", 2D) = "white" {} 39 | _FaceShadow("Face Shadow", 2D) = "white" {} 40 | 41 | [Header(Specular)] 42 | [Toggle(_SPECULAR)] _UseSpecular("Use Specular", Float) = 0 43 | _SpecularSmoothness("Specular Smoothness", Float) = 1 44 | _NonmetallicIntensity("Nonmetallic Intensity", Float) = 1 45 | _MetallicIntensity("Metallic Intensity", Float) = 1 46 | _MetalMap("Metal Map", 2D) = "white" {} 47 | 48 | [Header(Rim Light)] 49 | [Toggle(_RIM)] _UseRim("Use Rim", Float) = 0 50 | _RimOffset("Rim Offset", Float) = 1 51 | _RimThreshold("Rim Threshold", Float) = 1 52 | _RimIntensity("Rim Intensity", Float) = 1 53 | 54 | [Header(Outline)] 55 | [ToggleUI] _UseSmoothNormal("Use Smooth Normal", Float) = 0 56 | _OutlineWidth("Outline Width", Float) = 1 57 | _OutlineWidthParams("Outline Width Params", Vector) = (0,1,0,1) 58 | _OutlineZOffset("Outline Z Offset", Float) = 0 59 | _ScreenOffset("Screen Offset", Vector) = (0,0,0,0) 60 | _OutlineColor("Outline Color", Color) = (0,0,0,1) 61 | _OutlineColor2("Outline Color 2", Color) = (0,0,0,1) 62 | _OutlineColor3("Outline Color 3", Color) = (0,0,0,1) 63 | _OutlineColor4("Outline Color 4", Color) = (0,0,0,1) 64 | _OutlineColor5("Outline Color 5", Color) = (0,0,0,1) 65 | } 66 | 67 | Subshader 68 | { 69 | Tags 70 | { 71 | "RenderType" = "Opaque" 72 | "RenderPipeline" = "UniversalPipeline" 73 | "UniversalMaterialType" = "Lit" 74 | "IgnoreProjector" = "True" 75 | } 76 | 77 | Pass 78 | { 79 | Name "Forward" 80 | Tags {"LightMode" = "UniversalForward"} 81 | 82 | Cull[_Cull] 83 | ZWrite On 84 | Blend[_SrcBlend][_DstBlend] 85 | 86 | HLSLPROGRAM 87 | 88 | // Universal Pipeline keywords 89 | #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN 90 | #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS 91 | #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS 92 | #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING 93 | #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION 94 | #pragma multi_compile_fragment _ _SHADOWS_SOFT 95 | #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION 96 | #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3 97 | #pragma multi_compile_fragment _ _LIGHT_LAYERS 98 | #pragma multi_compile_fragment _ _LIGHT_COOKIES 99 | #pragma multi_compile _ _FORWARD_PLUS 100 | #pragma multi_compile_fragment _ _WRITE_RENDERING_LAYERS 101 | 102 | // Unity defined keywords 103 | #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING 104 | #pragma multi_compile _ SHADOWS_SHADOWMASK 105 | #pragma multi_compile _ DIRLIGHTMAP_COMBINED 106 | #pragma multi_compile _ LIGHTMAP_ON 107 | #pragma multi_compile _ DYNAMICLIGHTMAP_ON 108 | #pragma multi_compile_fragment _ LOD_FADE_CROSSFADE 109 | #pragma multi_compile_fog 110 | #pragma multi_compile_fragment _ DEBUG_DISPLAY 111 | 112 | #pragma shader_feature_local_fragment _DOUBLE_SIDED 113 | #pragma shader_feature_local_fragment _EMISSION 114 | #pragma shader_feature_local_fragment _NORMAL_MAP 115 | #pragma shader_feature_local_fragment _IS_FACE 116 | #pragma shader_feature_local_fragment _SPECULAR 117 | #pragma shader_feature_local_fragment _RIM 118 | 119 | #pragma vertex ForwardPassVertex 120 | #pragma fragment ForwardPassFragment 121 | 122 | #include "ToonInput.hlsl" 123 | #include "ToonForwardPass.hlsl" 124 | 125 | ENDHLSL 126 | } 127 | 128 | Pass 129 | { 130 | Name "ShadowCaster" 131 | Tags{"LightMode" = "ShadowCaster"} 132 | 133 | ZWrite On 134 | ZTest LEqual 135 | ColorMask 0 136 | Cull[_Cull] 137 | 138 | HLSLPROGRAM 139 | 140 | #pragma vertex ShadowPassVertex 141 | #pragma fragment ShadowPassFragment 142 | 143 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 144 | #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl" 145 | 146 | ENDHLSL 147 | } 148 | 149 | Pass 150 | { 151 | Name "DepthOnly" 152 | Tags{"LightMode" = "DepthOnly"} 153 | 154 | ZWrite On 155 | ColorMask R 156 | Cull[_Cull] 157 | 158 | HLSLPROGRAM 159 | 160 | #pragma vertex DepthOnlyVertex 161 | #pragma fragment DepthOnlyFragment 162 | 163 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 164 | #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl" 165 | 166 | ENDHLSL 167 | } 168 | 169 | Pass 170 | { 171 | Name "DepthNormals" 172 | Tags{"LightMode" = "DepthNormals"} 173 | 174 | ZWrite On 175 | Cull[_Cull] 176 | 177 | HLSLPROGRAM 178 | 179 | #pragma vertex DepthNormalsVertex 180 | #pragma fragment DepthNormalsFragment 181 | 182 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl" 183 | #include "Packages/com.unity.render-pipelines.universal/Shaders/LitDepthNormalsPass.hlsl" 184 | 185 | ENDHLSL 186 | } 187 | 188 | Pass 189 | { 190 | Name "Outline" 191 | Tags {"LightMode" = "SRPDefaultUnlit"} 192 | 193 | Cull Front 194 | 195 | HLSLPROGRAM 196 | 197 | #pragma vertex OutlinePassVertex 198 | #pragma fragment OutlinePassFragment 199 | 200 | #include "ToonInput.hlsl" 201 | #include "ToonOutlinePass.hlsl" 202 | 203 | ENDHLSL 204 | } 205 | } 206 | } 207 | --------------------------------------------------------------------------------