I’m currently trying to modify the Toony Gooch Shader to use the 2nd Uv layer coordinates (which are normally reserved for Unity Lightmapping) to multiply with the color returned from the Uv1 coordinates… The line that’s supposed to accomplish this is “o.Albedo = c.rgb * c2.rgb * _Color.rgb * IN.color.rgb * IN.color.a;”. I also defined all the needed variables and encountered no problem until I actually tried multiplying “c2” in the above code. Now according to my (admittedly shaky) understanding of Shaders so far the code below should work. It appears though that the compiled shader creates unexpected errors namely:
GLSL vertex shader: ERROR: 0:416: ‘_MainTexST’ : redefinition at line 22 (which appears to be a comment in the compiled Shader?)
Program ‘frag_surf’, declaration of “_MainTex_ST” conflicts with previous declaration at line 101
Program ‘vert_surf’, declaration of “_MainTex_ST” conflicts with previous declaration at line 101
Here the excerpt from line 101 of the compiled shader:
#ifndef LIGHTMAP_OFF
struct v2f_surf {
float4 pos : SV_POSITION;
float4 pack0 : TEXCOORD0;
float3 viewDir : TEXCOORD1;
fixed4 color : COLOR0;
fixed3 normal : TEXCOORD2;
float2 lmap : TEXCOORD3;
LIGHTING_COORDS(4,5)
};
#endif
And here the uncompiled shader as is:
Shader "Uv2"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
_RimColor ("Rim Color", Color) = (0.8,0.8,0.8,0.6)
_RimPower ("Rim Power", Float) = 1.4
_SColor ("Shadow Color", Color) = (0.0,0.0,0.0,1)
_LColor ("Highlight Color", Color) = (0.5,0.5,0.5,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf ToonRamp nolightmap
sampler2D _MainTex;
sampler2D _Ramp;
float4 _LColor;
float4 _SColor;
float4 _Color;
float _RimPower;
float4 _RimColor;
// custom lighting function that uses a texture ramp based
// on angle between light direction and normal
#pragma lighting ToonRamp exclude_path:prepass
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
{
#ifndef USING_DIRECTIONAL_LIGHT
lightDir = normalize(lightDir);
#endif
half d = dot (s.Normal, lightDir)*0.5 + 0.5;
half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
ramp = lerp(_SColor,_LColor,ramp);
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
c.a = 0;
return c;
}
struct Input
{
float2 uv_MainTex : TEXCOORD0;
float2 uv2_MainTex : TEXCOORD1;
float3 pos : POSITION0;
float3 viewDir;
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = tex2D(_MainTex, IN.uv_MainTex);
half4 c2 = tex2D(_MainTex, IN.uv2_MainTex);
o.Albedo = c.rgb * c2.rgb * _Color.rgb * IN.color.rgb * IN.color.a;
o.Alpha = c.a;
//Rim Light
half rim = 1.0f - saturate( dot(normalize(IN.viewDir), o.Normal) );
o.Emission = (_RimColor.rgb * pow(rim, _RimPower)) * _RimColor.a;
}
ENDCG
}
Fallback "Toon/Lighted"
}
Did anybody else perhaps already try abusing the second Uv set? Is this a huge undertaking or can this be fixed rather unspectacularly ?
Currently using Unity 3.5.5f3 on Windows 7.