zoukankan      html  css  js  c++  java
  • Unity shader学习之Alpha Test的阴影

    Alpha Test的阴影,

    shader如下:

    // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    
    Shader "Custom/Alpha Test Shadow"
    {
        Properties
        {
            _Color ("Main Color", Color) = (1,1,1,1)          // 必需
            _MainTex("Main Texture", 2D) = "white" {}
            _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5        // 必需
        }
    
        SubShader
        {
            Tags
            {
                "Queue" = "AlphaTest"
                "RenderType" = "TransparentCutout"
            }
    
            Pass
            {
                Tags
                {
                    "LightMode" = "ForwardBase"
                }
                Cull Off                                    // 背面
    
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fwdbase
    
                #include "UnityCG.cginc"
                #include "Lighting.cginc"
                #include "AutoLight.cginc"
    
                float4 _Color;
                sampler2D _MainTex;
                float _Cutoff;
    
                struct appdata
                {
                    float4 vertex : POSITION;
                    float2 uv : TEXCOORD0;
                    float3 normal : NORMAL;
                };
    
                struct v2f
                {
                    float4 pos : SV_POSITION;
                    float2 uv : TEXCOORD0;
                    float3 worldNormal : TEXCOORD1;
                    float3 worldPos : TEXCOORD2;
                    SHADOW_COORDS(3)
                };
    
                v2f vert(appdata v)
                {
                    v2f o;
                    o.pos = UnityObjectToClipPos(v.vertex);
                    o.uv = v.uv;
                    o.worldNormal = UnityObjectToWorldNormal(v.normal);
                    o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                    TRANSFER_SHADOW(o);
                    return o;
                }
    
                fixed4 frag(v2f i) : SV_TARGET
                {
                    fixed4 albedo = tex2D(_MainTex, i.uv) * _Color;
    
                    clip(albedo.a - _Cutoff);
    
                    fixed3 ambient = albedo.rgb * UNITY_LIGHTMODEL_AMBIENT.rgb;
    
                    float3 worldLight = UnityWorldSpaceLightDir(i.worldPos);
                    fixed3 diff = albedo.rgb * _LightColor0.rgb * max(0, dot(i.worldNormal, worldLight));
    
                    UNITY_LIGHT_ATTENUATION(atten, i, i.worldPos);
    
                    fixed3 col = ambient + diff * atten;
    
                    return fixed4(col, 1);
                }
    
                ENDCG
            }
        }
    
        Fallback "Transparent/Cutout/VertexLit"                    // 必需,阴影投射pass
    }

    效果如下:

  • 相关阅读:
    将本地sql文件导入到mysql中
    eclipse注释乱码问题
    导入import com.sun.image.codec.jpeg.JPEGCodec出错
    cmd启动和停止tomcat
    Tomcat修改端口
    ==和equals
    多态
    关键字——this,super,static,final
    方法重载、方法重写、四种权限修饰、JavaBean、代码块
    异常
  • 原文地址:https://www.cnblogs.com/jietian331/p/7198887.html
Copyright © 2011-2022 走看看