将透明着色器更改为黑色(Unity)

时间:2017-12-08 03:44:51

标签: opengl unity3d shader

我在这里要做的是,我想让这个hair变成黑色。我在检查器上更改了颜色色调但仍然无效。

到目前为止,这是我的头发着色器的代码:

Shader "Custom/Paul/Hair" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Color ("Color Tint", Color) = (1,1,1,1) 
}

SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 100

    ZWrite off
    Lighting Off
    Blend SrcAlpha OneMinusSrcAlpha
    Cull back

    Pass {
        CGPROGRAM

             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_fog

             #include "UnityCG.cginc"

             struct appdata_t {
                 float4 vertex : POSITION;
                 float2 texcoord : TEXCOORD0;
             };

             struct v2f {
                 float4 vertex : SV_POSITION;
                 half2 texcoord : TEXCOORD0;
                 UNITY_FOG_COORDS(1)
                 half4 color: COLOR;
             };

             sampler2D _MainTex;
             float4 _MainTex_ST;

             v2f vert (appdata_t v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                 UNITY_TRANSFER_FOG(o,o.vertex);
                 return o;
             }

             fixed4 frag (v2f i) : SV_Target
             {
                 fixed4 col = tex2D(_MainTex, i.texcoord);
                 //fixed4 col = tex2D(_MainTex, i.texcoord) * _Color;
                 UNITY_APPLY_FOG(i.fogCoord, col);
                 return col;
             }
        ENDCG
    }
  }
}

我尝试更改属性中的颜色色调但不会改变头发的颜色。有没有办法在着色器属性中动态更改头发颜色,甚至不在着色器属性中,甚至只在代码上。抱歉我的英语不好。

还有一件事。我没有任何错误。

1 个答案:

答案 0 :(得分:0)

我最终做了这件事。

Shader "Custom/Paul/Hair" {


Properties
{
    _MainTex ("Texture", 2D) = "white" {}
    _Color("Color", Color) = (1,1,1,1)
}
SubShader
{
    Tags{ "Queue" = "AlphaTest" "RenderType" = "TransparentCutout" "IgnoreProjector" = "True" }
    LOD 100

    Blend SrcAlpha OneMinusSrcAlpha
    ZWrite off
    Lighting Off
    Cull back

    Pass
    {
        CGPROGRAM

        #pragma vertex vert
        #pragma fragment frag

        #include "UnityCG.cginc"

        struct appdata
        {
            float4 vertex : POSITION;
            float2 uv : TEXCOORD0;
        };

        struct v2f
        {
            float4 vertex : SV_POSITION;
            half2 uv : TEXCOORD0;
        };

        float4 _MainTex_ST;
        sampler2D _MainTex;
        fixed4 _Color;

        v2f vert (appdata v)
        {
            v2f o = (v2f)0;
            o.vertex = UnityObjectToClipPos(v.vertex);
            o.uv = TRANSFORM_TEX(v.uv, _MainTex);
            o.uv = v.uv;
            return o;
        }

        fixed4 frag (v2f i) : SV_Target
        {
            fixed4 col = tex2D(_MainTex, i.uv) * _Color;
            return col;
        }
        ENDCG
    }
}

这可能有助于遇到与我相同问题的其他人。