合并着色器

时间:2018-12-05 22:15:44

标签: unity3d shader

您将如何组合这两个着色器?

Shader "Legacy Shaders/Diffuse" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200

CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
fixed4 _Color;

struct Input {
    float2 uv_MainTex;
};

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Alpha = c.a;
}
ENDCG
}

Fallback "Legacy Shaders/VertexLit"
}

Shader "Custom/Jelly" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
    }
    SubShader {
        Pass {
            Tags { "RenderType"="Opaque" }

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            sampler2D _MainTex;
            struct v2f {
                float4 pos : SV_POSITION;
                half2 uv : TEXCOORD0;
            };

            v2f vert(appdata_base v) {
                v2f o;
                v.vertex.x += sign(v.vertex.x) * sin(_Time.w)/50;
                v.vertex.y += sign(v.vertex.y) * cos(_Time.w)/50;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv = v.texcoord;
                return o;
            }


            half4 frag(v2f i) : COLOR {
                half4 c = tex2D(_MainTex, i.uv);
                return c;
            }

            ENDCG
        }
    }
    FallBack "Diffuse"
}

我试图将其合并为一个,我尝试了各种方法,但不确定如何在果冻着色器中启用照明来获得颜色。

当我将float2 uv_MainTex带入结构v2f时,似乎出现了问题,似乎不喜欢这样。它已经在那里了,我只是看错了吗?

有什么帮助吗?

谢谢

0 个答案:

没有答案