Lit.shader 3.5 KB
Newer Older
timchen1002's avatar
update  
timchen1002 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Shader "Custom RP/Lit"
{
    Properties
    {
        _BaseMap("Texture", 2D) = "white" {}
        _BaseColor("Color", Color) = (0.5, 0.5, 0.5, 1.0)
        // 透明度测试的阈值
        _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
        [Toggle(_CLIPPING)] _Clipping ("Alpha Clipping", Float) = 0
        // 是否接受投影
        [Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows ("Receive Shadows", Float) = 1
        // 阴影模式
        [KeywordEnum(On, Clip, Dither, Off)] _Shadows ("Shadows", Float) = 0
        // 金属度和光滑度
        _Metallic("Metallic", Range(0, 1)) = 0
        _Smoothness("Smoothness", Range(0, 1)) = 0.5
timchen1002's avatar
update  
timchen1002 已提交
17 18
        // 菲涅尔反射强度
        _Fresnel ("Fresnel", Range(0, 1)) = 1
timchen1002's avatar
update  
timchen1002 已提交
19 20 21
        // 自发光
        [NoScaleOffset] _EmissionMap("Emission", 2D) = "white" {}
        [HDR] _EmissionColor("Emission", Color) = (0.0, 0.0, 0.0, 0.0)
timchen1002's avatar
update  
timchen1002 已提交
22 23
        // 透明通道预乘
        [Toggle(_PREMULTIPLY_ALPHA)] _PremulAlpha("Premultiply Alpha", Float) = 0
timchen1002's avatar
update  
timchen1002 已提交
24 25 26 27 28
        // 设置混合模式
        [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1
        [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 0
        // 默认写入深度缓冲区
        [Enum(Off, 0, On, 1)] _ZWrite ("Z Write", Float) = 1
timchen1002's avatar
update  
timchen1002 已提交
29

timchen1002's avatar
update  
timchen1002 已提交
30 31 32
        [HideInInspector] _MainTex("Texture for Lightmap", 2D) = "white" {}
        [HideInInspector] _Color("Color for Lightmap", Color) = (0.5, 0.5, 0.5, 1.0)
    }
timchen1002's avatar
update  
timchen1002 已提交
33

timchen1002's avatar
update  
timchen1002 已提交
34 35 36 37 38 39
    SubShader
    {
        HLSLINCLUDE
        #include "../ShaderLibrary/Common.hlsl"
        #include "LitInput.hlsl"
        ENDHLSL
timchen1002's avatar
update  
timchen1002 已提交
40

timchen1002's avatar
update  
timchen1002 已提交
41 42 43 44 45 46
        Pass
        {
            Tags
            {
                "LightMode" = "CustomLit"
            }
timchen1002's avatar
update  
timchen1002 已提交
47

timchen1002's avatar
update  
timchen1002 已提交
48 49 50 51
            // 定义混合模式
            Blend [_SrcBlend] [_DstBlend]
            // 是否写入深度
            ZWrite [_ZWrite]
timchen1002's avatar
update  
timchen1002 已提交
52

timchen1002's avatar
update  
timchen1002 已提交
53 54 55 56 57 58 59 60 61 62
            HLSLPROGRAM
            #pragma target 3.5
            #pragma shader_feature _CLIPPING
            #pragma shader_feature _RECEIVE_SHADOWS
            // 是否透明通道预乘
            #pragma shader_feature _PREMULTIPLY_ALPHA
            #pragma multi_compile _ _DIRECTIONAL_PCF3 _DIRECTIONAL_PCF5 _DIRECTIONAL_PCF7
            #pragma multi_compile _ _CASCADE_BLEND_SOFT _CASCADE_BLEND_DITHER
            #pragma multi_compile _ _SHADOW_MASK_ALWAYS _SHADOW_MASK_DISTANCE
            #pragma multi_compile _ LIGHTMAP_ON
timchen1002's avatar
update  
timchen1002 已提交
63
            #pragma multi_compile _ LOD_FADE_CROSSFADE
timchen1002's avatar
update  
timchen1002 已提交
64 65 66 67 68 69 70
            #pragma multi_compile_instancing
            #pragma vertex LitPassVertex
            #pragma fragment LitPassFragment
            // 插入相关HLSL代码
            #include "LitPass.hlsl"
            ENDHLSL
        }
timchen1002's avatar
update  
timchen1002 已提交
71

timchen1002's avatar
update  
timchen1002 已提交
72 73 74 75 76 77
        Pass
        {
            Tags
            {
                "LightMode" = "ShadowCaster"
            }
timchen1002's avatar
update  
timchen1002 已提交
78

timchen1002's avatar
update  
timchen1002 已提交
79
            ColorMask 0
timchen1002's avatar
update  
timchen1002 已提交
80

timchen1002's avatar
update  
timchen1002 已提交
81 82 83
            HLSLPROGRAM
            #pragma target 3.5
            #pragma shader_feature _ _SHADOWS_CLIP _SHADOWS_DITHER
timchen1002's avatar
update  
timchen1002 已提交
84
            #pragma multi_compile _ LOD_FADE_CROSSFADE
timchen1002's avatar
update  
timchen1002 已提交
85 86 87 88 89 90
            #pragma multi_compile_instancing
            #pragma vertex ShadowCasterPassVertex
            #pragma fragment ShadowCasterPassFragment
            #include "ShadowCasterPass.hlsl"
            ENDHLSL
        }
timchen1002's avatar
update  
timchen1002 已提交
91

timchen1002's avatar
update  
timchen1002 已提交
92 93 94 95 96 97
        Pass
        {
            Tags
            {
                "LightMode" = "Meta"
            }
timchen1002's avatar
update  
timchen1002 已提交
98

timchen1002's avatar
update  
timchen1002 已提交
99
            Cull Off
timchen1002's avatar
update  
timchen1002 已提交
100

timchen1002's avatar
update  
timchen1002 已提交
101 102 103 104 105 106 107 108
            HLSLPROGRAM
            #pragma target 3.5
            #pragma vertex MetaPassVertex
            #pragma fragment MetaPassFragment
            #include "MetaPass.hlsl"
            ENDHLSL
        }
    }
timchen1002's avatar
update  
timchen1002 已提交
109

timchen1002's avatar
update  
timchen1002 已提交
110 111
    CustomEditor "CustomShaderGUI"
}