Shader "Shader Forge/AdditiveTwoTex" { Properties { [Header(additive shader)]//对shader的总体说明性文字可以这样写 [Space]//空位 _MainTex ("MainTex", 2D) = "white" {} _SecondTex("SecondTex",2D)="white"{} _TintColor ("Color", Color) = (0.5,0.5,0.5,1) _Bright ("Bright", Float ) = 2 [Space(50)] [Toggle] _DRIVESECONDTEX("SecondTex?", Float) = 0 [Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull Mode", Float) = 2//enum()枚举函数,将CullMode写到属性面板,默认值“0”代表是off,“1”代表front"2"代表back [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Float) = 04//默认值从0到8本别代表了test类型 [Enum(Off, 0, On, 1)] _ZWrite ("ZWrite", Float) = 0 } SubShader { Tags { "IgnoreProjector"="True" "Queue"="Transparent" "RenderType"="Transparent" } Pass { Name "FORWARD" Tags { "LightMode"="ForwardBase" } Blend One One Cull [_Cull] ZTest [_ZTest] ZWrite [_ZWrite] CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #pragma shader_feature _DRIVESECONDTEX_ON//定义了开关_DRIVESECONDTEX_ON,形成两个变体shader //#pragma multi_compile_fwdbase // #pragma only_renderers d3d9 d3d11 glcore gles #pragma target 3.0 sampler2D _MainTex; float4 _MainTex_ST; sampler2D _SecondTex; float4 _SecondTex_ST; float4 _TintColor; float _Bright; struct VertexInput { float4 vertex : POSITION; float2 texcoord0 : TEXCOORD0; float2 texcoord1:TEXCOORD1; float4 vertexColor : COLOR; }; struct VertexOutput { float4 pos : SV_POSITION; float2 uv0 : TEXCOORD0; float2 uv1:TEXCOORD1; float4 vertexColor : COLOR; }; VertexOutput vert (VertexInput v) { VertexOutput o = (VertexOutput)0; o.uv0 = v.texcoord0; o.uv1=v.texcoord1; o.vertexColor = v.vertexColor; o.pos = UnityObjectToClipPos( v.vertex ); return o; } float4 frag(VertexOutput i) : COLOR { float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex)); #if _DRIVESECONDTEX_ON float4 _SecondTex_var=tex2D(_SecondTex,TRANSFORM_TEX(i.uv1,_SecondTex)); float3 emissive = ((_MainTex_var.rgb*_SecondTex_var.rgb*_MainTex_var.a)*i.vertexColor.rgb*_TintColor.rgb*_Bright*i.vertexColor.a); #else float3 emissive = ((_MainTex_var.rgb*_MainTex_var.a)*i.vertexColor.rgb*_TintColor.rgb*_Bright*i.vertexColor.a); #endif return fixed4(emissive,1); } ENDCG } } //CustomEditor "ShaderForgeMaterialInspector" }
c
运行