Hey guys, So I'm working on a combination of the decal shader and the toony-lighted shader. However, I can have 3 sets of decals plus the main texture. I only need the toony effect to be on the main texture. However, if it's easier to do them all at once, that's fine too. Here's an example of what I have. Just that the performance sucks because of what's in the "surf" function Code (CSharp): Shader "Custom/ToonDecal" { Properties { _Color ("Main Color", Color) = (0.5,0.5,0.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} _DecalFirst ("Face", 2D) = "black" {} _DecalSecond ("Body", 2D) = "black" {} _DecalThird ("Accessory", 2D) = "black" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf ToonRamp approxview halfasview noforwardadd sampler2D _Ramp; sampler2D _DecalFirst; sampler2D _DecalSecond; sampler2D _DecalThird; #pragma lighting ToonRamp exclude_path:prepass approxview halfasview noforwardadd inline fixed4 LightingToonRamp (SurfaceOutput s, fixed3 lightDir, fixed atten) { #ifndef USING_DIRECTIONAL_LIGHT lightDir = normalize(lightDir); #endif fixed d = dot (s.Normal, lightDir)*0.5 + 0.5; fixed3 ramp = tex2D (_Ramp, fixed2(d,d)).rgb; fixed4 c; c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2); c.a = 0; return c; } sampler2D _MainTex; fixed4 _Color; struct Input { fixed2 uv_MainTex : TEXCOORD0; fixed2 uv_DecalFirst; fixed2 uv_DecalSecond; fixed2 uv_DecalThird; }; void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex)* _Color; half4 decalTwo = tex2D(_DecalSecond, IN.uv_DecalSecond); c.rgb = lerp (c.rgb, decalTwo.rgb, decalTwo.a); half4 decalThree = tex2D(_DecalThird, IN.uv_DecalThird); c.rgb = lerp (c.rgb, decalThree.rgb, decalThree.a); half4 decalOne = tex2D(_DecalFirst, IN.uv_DecalFirst); c.rgb = lerp (c.rgb, decalOne.rgb, decalOne.a); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } Fallback "Diffuse" } I have a very performance happy version that doesn't do the toon shading/lighting. But I'm having trouble figuring out how to add in the toon shading part... Code (CSharp): Pass{ SetTexture [_MainTex] { ConstantColor[_Color] combine texture *constant } SetTexture [_DecalFirst] { combine texture lerp (texture) previous } SetTexture [_DecalSecond] { combine texture lerp (texture) previous } SetTexture [_DecalThird] { combine texture lerp (texture) previous } } Any help or suggestions would be greatly appreciated
So I got this far with blending them. I believe that means it makes two passes now? But the lighting seems a bit off. Like the blended version is darker than the normal version. You can test this by setting a color such as sky blue with a bunch of decals. Then take out the pass with the texture combiners and see the sky blue change a bit. Code (CSharp): Shader "Custom/ToonDecal" { Properties { _Color ("Main Color", Color) = (0.5,0.5,0.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} _DecalFirst ("Body", 2D) = "black" {} _DecalSecond ("Accessory", 2D) = "black" {} _DecalThird ("Face", 2D) = "black" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 Pass{ SetTexture [_MainTex] { ConstantColor[_Color] combine texture *constant } SetTexture [_DecalFirst] { combine texture lerp (texture) previous } SetTexture [_DecalSecond] { combine texture lerp (texture) previous } SetTexture [_DecalThird] { combine texture lerp (texture) previous } } Blend DstColor Zero CGPROGRAM #pragma surface surf ToonRamp approxview halfasview noforwardadd sampler2D _Ramp; #pragma lighting ToonRamp exclude_path:prepass approxview halfasview noforwardadd inline fixed4 LightingToonRamp (SurfaceOutput s, fixed3 lightDir, fixed atten) { #ifndef USING_DIRECTIONAL_LIGHT lightDir = normalize(lightDir); #endif fixed d = dot (s.Normal, lightDir)*0.5 + 0.5; fixed3 ramp = tex2D (_Ramp, fixed2(d,d)).rgb; fixed4 c; c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2); c.a = 0; return c; } sampler2D _MainTex; fixed4 _Color; struct Input { fixed2 uv_MainTex : TEXCOORD0; }; void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } Fallback "Diffuse" }
So the color darkening in the second version is bugging me, so I'm resorting to the first method. Still wish there was a better way to do it. I did some logic that switches to simpler shaders depending on the amount of decals and circumstances, but I'd still like to optimize this one for the worst-case scenarios.