美文网首页
接收阴影时可调阴影颜色

接收阴影时可调阴影颜色

作者: 星易乾川 | 来源:发表于2018-07-11 10:28 被阅读0次
    Shader "DiffuseEmission" {
        Properties{
            _MainTex("Base (RGB)", 2D) = "white" {}
            _Color("MainColor", Color) = (0.9,0.9,0.9,0)
            _ShadowColor("ShadowColor", Color) = (0.15,0.15,0.15,0)
            _Emission("Emission", Range(0, 1)) = 0
            _ShadowStrength("ShadowStrength",Range(0, 1)) = 0.5
        }
            SubShader{
                Tags { "RenderType" = "Opaque" "Queue"="Geometry"}
                LOD 150
                pass{
                Tags { "LightMode"="ForwardBase" }
            CGPROGRAM
            
            #pragma multi_compile_fwdbase
            #pragma vertex vert
            #pragma fragment frag
            #include "Lighting.cginc"
            #include "AutoLight.cginc"
            #include "UnityCG.cginc"
        
            
            sampler2D _MainTex;
            half4 _MainTex_ST;
            float _Emission;
            float4 _Color;
            half _ShadowStrength;
            float3 _ShadowColor;
                struct a2v {
                    half4 vertex : POSITION;
                    half4 texcoord : TEXCOORD0;
                    float3 normal : NORMAL;
                        };
                
                struct v2f {
                    half4 pos : SV_POSITION;
                    half4 uv : TEXCOORD0;
                    float3 worldNormal : TEXCOORD2;
                    float3 worldPos : TEXCOORD1;
                    SHADOW_COORDS(3)
                };
                v2f vert(a2v v) {
                    v2f o;
                    UNITY_INITIALIZE_OUTPUT(v2f, o);
                    o.pos = UnityObjectToClipPos(v.vertex);
                    o.uv.xy = v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw; 
                    o.worldNormal = UnityObjectToWorldNormal(v.normal);
                    o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                    TRANSFER_SHADOW(o);
                    
                    return o;
                }
    
    
                fixed4 frag(v2f i) : SV_Target {
                    fixed3 worldNormal = normalize(i.worldNormal);
                    fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz);
                    fixed4 c = tex2D(_MainTex, i.uv.xy) * _Color + _Emission;
                    fixed3 diffuse =  c * max(0, dot(worldNormal, worldLightDir)) + _ShadowColor *  (1- dot(worldNormal, worldLightDir));
                    fixed atten = SHADOW_ATTENUATION(i);
                 
                                                                    
                 // return   half4(diffuse * (1 - (1 - atten) *  _ShadowStrength ),1.0);
                return half4(diffuse * (1 - (1 - atten) *  _ShadowStrength ) /*+ _ShadowColor*/,1.0);
                    }
            ENDCG
            }
            }
            Fallback "Diffuse"
    

    相关文章

      网友评论

          本文标题:接收阴影时可调阴影颜色

          本文链接:https://www.haomeiwen.com/subject/uuocpftx.html