美文网首页Unity_Shader
透明度混合的阴影(不正确)

透明度混合的阴影(不正确)

作者: _Arturia | 来源:发表于2018-08-24 11:48 被阅读8次

首先说明,透明度混合是取不到完全正确的阴影的

Shader "_MyShader/6_Light/4_AlphaBlendWithShadow"
{
Properties
{
_Color ("Color ", COLOR) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" {}
_AlphaScale ("AlphaScale", Range(0,1)) = 1
}
SubShader
{
Tags {"Queue" = "Transparent" "IgnoreProjecter" = "true" "RenderType" = "Transparent"}

    pass {
        Tags {"LightMode" = "ForwardBase"}
        ZWrite off
        //Cull off
        Blend SrcAlpha OneMinusSrcAlpha

        CGPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        #include "Lighting.cginc"
        #include "AutoLight.cginc"
        #include "UnityCG.cginc"

        fixed4 _Color;
        sampler2D _MainTex;
        float4 _MainTex_ST;
        fixed _AlphaScale;

        struct a2v {
            float4 vertex: POSITION;
            float3 normal: NORMAL;
            float4 texcoord: TEXCOORD0;
        };

        struct v2f {
            float4 pos: SV_POSITION;
            float3 worldNormalDir: POSITION1;
            float3 worldLightDir: POSITION2;
            float2 uv: TEXCOORD0;
            float3 worldPos:POSITION3;
            SHADOW_COORDS(4)
        };

        v2f vert(a2v v){
            v2f o;
            o.pos = mul(UNITY_MATRIX_MVP,v.vertex);
            
            o.worldPos = mul(_Object2World,v.vertex).xyz;

            o.worldNormalDir = UnityObjectToWorldNormal(v.normal);
            o.worldLightDir = UnityWorldSpaceLightDir(v.vertex);

            o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);

            TRANSFER_SHADOW(o);

            return o;
        }

        fixed4 frag(v2f i):SV_Target{
            UNITY_LIGHT_ATTENUATION(atten,i,i.worldPos.xyz);

            fixed3 normalDir = normalize(i.worldNormalDir);
            fixed3 lightDir = normalize(i.worldLightDir);
            fixed4 tex = tex2D(_MainTex,i.uv);
            
            //AlphaTest
            //if(tex.a - _CutOff <= 0)
            //  discard;
            //clip(tex.a - _CutOff);

            fixed3 albedo = tex.rgb *_Color.rgb;
            
            fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;

            fixed3 diffuseC = _LightColor0.rgb * albedo * saturate(dot(normalDir,lightDir));

            fixed4 col = fixed4(ambient + diffuseC * atten ,tex.a * _AlphaScale);
            return col;
        }

        ENDCG
    }

}

FallBack "VertexLit"

}

相关文章

  • 透明度混合的阴影(不正确)

    首先说明,透明度混合是取不到完全正确的阴影的 Shader "_MyShader/6_Light/4_AlphaB...

  • Shader-透明效果-透明度混合

    透明度混合相较于透明度测试更加复杂一些,透明度混合可以得到真正的半透明效果,使用当前片元和透明度作为混合因子,与已...

  • 【Unity Shader入门精要学习】透明(三)

    透明度混合 透明度混合原理 这种方法可以得到真正的半透明效果,它会使用当前片元的透明度作为混合因子,与已经存储在颜...

  • CSS深度操作(3)

    一、IE的兼容 二、过度动画 在transition中写入多个 三、圆角and阴影and透明度 圆角 阴影 透明度...

  • URP透明效果

    URP透明效果 该节我们会实现URP下透明度测试、透明度混合和开启深度写入的透明度混合效果 本系列URP不再阐述具...

  • OpenGL学习17——混合

    混合(Blending) 混合(Blending) 在OpenGL中一般作为实现物体透明度的技术。一个物体的透明度...

  • Unity Shader 透明度混合物体的阴影

    Unity Shader系列文章:Unity Shader目录-初级篇[https://www.jianshu.c...

  • Shader基础篇—轮廓增强(转)

    1、介绍:如图所示,两个胶囊体都是采用同样的透明度混合方程进行混合的,并且颜色和透明度都一样。而左边的对透明度进行...

  • CALayer

    主要属性 1.设置阴影 shadowColor 阴影颜色 shadowOpacity 阴影的不透明度 shadow...

  • iOS阴影设置详解

    UIView的阴影设置主要通过UIView的layer的相关属性来设置 阴影的颜色 阴影的透明度 阴影的圆角 阴影...

网友评论

    本文标题:透明度混合的阴影(不正确)

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