为了使着色器正常工作,我必须更改哪个属性?

时间:2019-05-08 01:15:43

标签: c# unity3d virtual-reality

我已经制作了可以与轮廓配合使用的着色器,但是当我将其放在组件(例如多维数据集)上时,着色器会更改所有组件。我只想更改轮廓,而着色器将整个颜色更改为黑色。

代码如下:

Shader "Unlit/GlowShader"
{
    Properties
    {
        _Color("Main Color", Color) =   (0,0,0,0)
        //_MainTex ("Texture", 2D) = "white" {}
        _OutlineColor("Outline color", Color) = (0,0,0,1)
        _OutlineWidth("Outline Width", Range(1.0,5.0)) = 1.01
    }

    CGINCLUDE
    #include "UnityCG.cginc"
    struct appdata {
        float4 vertex : POSITION;
        float3 normal : NORMAL;
    };

    struct v2f {
        float4 pos : POSITION;
        float3 normal : NORMAL;
    };

    float _OutlineWidth;
    float4 _OutlineColor;

    v2f vert(appdata v)
    {
        v.vertex.xyz *= _OutlineWidth;
        v2f o;
        o.pos = UnityObjectToClipPos(v.vertex);
        return o;
    }

    ENDCG

    SubShader
    {
        Tags{"Queue" = "3000"}

        Pass //Render the Outline
        {
            ZWrite Off 

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            half4 frag(v2f i) : COLOR
            {
                return _OutlineColor;
            }

            ENDCG
        }

        Pass //Normal render
        {
            ZWrite On
            Material
            {
                Diffuse[_Color]
                Ambient[_Color]
            }
            Lighting On
            SetTexture[_MainText]
            {
                ConstantColor[_Color]
            }
            SetTexture[_MainText]
            {
                Combine previous * primary DOUBLE
            }
        }

    }
}

0 个答案:

没有答案