【问题标题】:Unity3D: My shader doesn't work well in GameViewUnity3D:我的着色器在 GameView 中无法正常工作
【发布时间】:2015-12-29 04:36:06
【问题描述】:

我用凹凸纹理编写了 SurfaceShader。

我将我的材质应用到一个球体上。我可以在场景视图中看到球体,但在游戏视图中看不到球体。

当我将其他着色器应用到球体时,我可以在 GameView 中看到球体。

我在 Unity 社区找到了the same question

我知道我不应该使用顶点光照,而应该使用像素光照。

但我不明白应该更改哪些设置。我应该修改我的着色器还是我的设置?

我的着色器如下。

Shader "Custom/MyShader2"{
    Properties{
        _Bump("Bump",2D) = "white"{}
        _DiffuseColor("Diffuse Color", Color) = (1.0,1.0,1.0)
        _Specular("Specular",Range(1.0,50.0)) = 15.0
        _Alpha("Alpha",Range(0,1)) = 1
    }
    SubShader{
        Tags{
            "RenderType" = "Opaque"
        }
        CGPROGRAM
        #pragma surface surf Original alpha
        struct Input{
            float4 color: COLOR;
            float2 uv_Bump;
        };
        float3 _DiffuseColor;
        float _Specular;
        sampler2D _Bump;
        float _Alpha;
        half4 LightingOriginal( SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
            half diff = max(0,dot(s.Normal,lightDir));
            half spec = max(0,dot(s.Normal,normalize(lightDir + viewDir)));
            spec = pow(spec, _Specular);
            half trans = 1.0 - max(0,dot(s.Normal, viewDir)) + spec;
            half4 c;
            c. rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec / 2) * (atten * 2);
            c.a = trans;
            return c;
        }
        void surf( Input IN, inout SurfaceOutput o) {
            o.Albedo = _DiffuseColor * _Alpha;;
            o.Normal = UnpackNormal(tex2D(_Bump,IN.uv_Bump));
            o.Alpha = _Alpha;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

还是谢谢。

【问题讨论】:

    标签: unity3d shader


    【解决方案1】:

    尝试改变

    Tags { "RenderType" = "Opaque" }
    

    Tags { "Queue"="Transparent" "RenderType"="Transparent" }
    Blend SrcAlpha OneMinusSrcAlpha
    Cull Off ZWrite Off 
    

    【讨论】:

    • 感谢您的第一个回答。但是我不能通过改变shader来解决问题。
    猜你喜欢
    • 1970-01-01
    • 2013-10-02
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 2022-01-21
    • 1970-01-01
    • 2016-02-05
    相关资源
    最近更新 更多