unity: gameobjects invisible?

妖精的绣舞 提交于 2019-12-12 15:15:58

问题


I combined two shaders which can show transparency and cutoff Alpha. It works pretty fine, just two small problems stay. (1) in some specific camera angles the cutoff regions of an object are visible (only if a another object with the same shader is located behind that one) (2) if I fade out an object it's getting black not transparent

I'm new to shader-coding, thanks a lot for your help!!

Here's the shader:

Shader "Unlit/MyTransparent"
{
Properties{
    _Color("Main Color", Color) = (1,1,1,0.5)
    _MainTex("Base (RGB) Alpha (A)", 2D) = "white" {}
    _Cutoff("Base Alpha cutoff", Range(0,0.9)) = 0.5

}
    Category{
    //Tags{ "QUEUE" = "AlphaTested" "IGNOREPROJECTOR" = "true" "RenderType" = "Transparent" } // Transparent beides
    Blend SrcAlpha OneMinusSrcAlpha

    SubShader{ 

        Material{
        Diffuse[_Color]
        Ambient[_Color]
    }

        Pass{
            AlphaTest Greater[_Cutoff]
            SetTexture[_MainTex]{
            combine texture * primary, texture
        }
        } 

        Pass{
        GLSLPROGRAM
            varying mediump vec2 uv;

            uniform mediump vec4 _MainTex_ST;
            void main() {
                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
            }

            uniform lowp sampler2D _MainTex;
            uniform lowp vec4 _Color;
            void main() {
                gl_FragColor = texture2D(_MainTex, uv) * _Color;
                float ca = tex2D(_CutTex, IN.uv_MainTex).a;
            }

        ENDGLSL
} 

        Pass{
        ZWrite Off 
        SetTexture[_MainTex]{
            //combine texture * primary, texture
            Combine texture * constant ConstantColor[_Color] 
        }
}
}

    SubShader{ Pass{
    SetTexture[_MainTex]{ Combine texture * constant ConstantColor[_Color]}
} }
}

}

来源:https://stackoverflow.com/questions/39677847/unity-gameobjects-invisible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!