Hey, I'm trying to have the Toon Lighted Shader increase/decrease the size of the ramp depending on the main light's intensity. Any ideas how I'd go about this? I'm considering changing the line below to multiply by something, but I'm not sure what.
^ This line because when I mess with the 0.5 numbers, it increases/decreases the ramp size.
asked Jan 21 '12 at 08:19 PM
You're on the right track. If you know what the old code was doing, makes it easier to modify. The code above looks up a 0-1 ramp value from the White/Black Ramp texture. You're allowed to not look it up, and instead just compute the ramp. In the old code, these two lines compute ramp:
The dot-product of your normal and the lightDir computes the percent of light you should get: 1 if you are facing, 0.7 for 45 degree angled away, 0 for an edge, and -1 for facing away. The range is -1 to 1. It's a really common value in lighting math.
Texture lookups think 0 is the left side and 1 is the right. So, DP*0.5+0.5 scales the -1 to 1 dot-prod into a 0-1 for the lookup. Since we aren't doing a texture lookup, we can ignore that. In math, a ramp looks like this (imagine low is black and high is white, so this represents black on the left, a short ramp to white, then white on the right):
Assume we have the raw -1 to 1:
For CENTER, 0 means the lightwise edge, positive (up to one) brings it towards the light, negative (down to -1) brings it to the unlit side. Interesting numbers for SPEED are 1 (very wide) to huge. Of course, anything more than about 20 will be almost an instant change between colors. The 0.5 makes CENTER be the center (without it, CENTER is the left edge, and changing SPEED makes it grow to the right. With the 0.5, changing SPEED grows both ways.)
answered Jan 22 '12 at 05:39 PM