【问题标题】:Alpha channel not working correctly on vertex shaderAlpha 通道在顶点着色器上无法正常工作
【发布时间】:2017-09-12 06:25:53
【问题描述】:

我似乎对它的绘图顺序或类似的东西有一些问题。

我使用顶点颜色。

如果我再次将底部顶点的 alpha 设置为 1,我仍然会在柱子的顶部遇到绘制问题。

如果我将队列设置为不透明,它会正确呈现,但是 alpha 会呈现为白色(预计不透明队列中没有透明度)

Shader "Custom/VertexColors2" {
    Properties {
        _Color ("Color", Color) = (0,0,0,0)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _GridTex ("Grid Texture", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
    }
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}

        CGPROGRAM
        #pragma surface surf Standard alpha
        #pragma target 3.5

        sampler2D _MainTex;
        sampler2D _GridTex;

        struct Input {
            float2 uv_MainTex;
            float4 color : COLOR;
            float3 worldPos;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        void surf (Input IN, inout SurfaceOutputStandard o) {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;

            float2 gridUV = IN.worldPos.xz;
            gridUV.x *= 1 / (4 * 8.66025404);
            gridUV.y *= 1 / (2 * 15.0);
            fixed4 grid = tex2D(_GridTex, gridUV);

            o.Albedo = c.rgb * IN.color * grid;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = IN.color.a;
        }
        ENDCG
    }
    FallBack "Standard"
}

【问题讨论】:

    标签: unity3d hlsl vertex-shader cg


    【解决方案1】:

    我最终在 cg 开始之前添加了一个通道,它似乎正在做我想要它做的事情,但仍然需要更多的调整。

    Shader "Custom/VertexColors2" {
        Properties {
            _Color ("Color", Color) = (0,0,0,0)
            _MainTex ("Albedo (RGB)", 2D) = "white" {}
            _GridTex ("Grid Texture", 2D) = "white" {}
            _Glossiness ("Smoothness", Range(0,1)) = 0.5
            _Metallic ("Metallic", Range(0,1)) = 0.0
        }
        SubShader {
            Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Opaque"}
            LOD 200
    
            Pass {
                Cull Off
                Blend One OneMinusSrcAlpha
            }
                ZWrite Off
    
                CGPROGRAM
                #pragma surface surf Standard fullforwardshadows alpha:blend
                #pragma target 3.5
    
                sampler2D _MainTex;
                sampler2D _GridTex;
    
                struct Input {
                    float2 uv_MainTex;
                    float4 color : COLOR;
                    float3 worldPos;
                };
    
                half _Glossiness;
                half _Metallic;
                fixed4 _Color;
    
                void surf (Input IN, inout SurfaceOutputStandard o) {
                    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    
                    float2 gridUV = IN.worldPos.xz;
                    gridUV.x *= 1 / (4 * 8.66025404);
                    gridUV.y *= 1 / (2 * 15.0);
                    fixed4 grid = tex2D(_GridTex, gridUV);
    
                    o.Albedo = c.rgb * IN.color * grid;
                    o.Metallic = _Metallic;
                    o.Smoothness = _Glossiness;
                    o.Alpha = IN.color.a;
                }
                ENDCG
        }
        FallBack "Diffuse"
    }
    

    【讨论】:

      最近更新 更多