- Home /
Cel/Toon shading limit colors after all light
Hello! I am new to writing shader so wrote this simple thing to cut light into 2 tones (cel/toon shading) but i wonder if it is possible to make it work better with multiple light sources. Here what i have now: http://i.piccy.info/i9/21ac64c2cfb212377de9e8a6d74cf8c2/1413491875/9992/721611/pic1.png I wonder if it possible to get result of all light sources together and then modify it so it it always stay in 1 of 2 values - light gray or dark gray. Something like this: http://i.piccy.info/i9/871e31f9ebd833b3558021a70ce68b14/1413492238/28967/721611/pic2.png So here is the code:
Shader "Custom/Cel" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Toon
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
half4 LightingToon (SurfaceOutput s, half3 lightDir, half atten) {
half4 c;
half dotProduct = dot(s.Normal, lightDir);
dotProduct = floor(dotProduct * 0.5) * 0.5 + 0.5;
c.rgb = s.Albedo * dotProduct;
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
if anyone can give a solution, explanation how it works (even brief) will be greatly appreciated as i want to understand it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613165244im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Terrain Shading 1 Answer
cast shadow - export lightmap from 3ds max to unity 2 Answers
Silhouette Toon Shader 0 Answers
Point Light Behave different from editor and IOS device 0 Answers