Monday, July 26, 2010

Shader Tips.


I've been working on a high end shader over the last few days. this particular shader needed a diffuse map, a normal map, a specular map (color and alpha mask), a cube map, and a fallback texture. The cube map provided reflections which were mapped over the normals (from the normal map) of the model. Here are some random things I've learnt.

1. Add ambient light, don't multiply.

2. To mix colours, multiply them together, then multiply by 2 to retain the same brightness.

3. Use the Unity3D macros in UnityCG.cginc, they make life much easier.

2 comments:

Anonymous said...

"2. To mix colours, multiply them together, then multiply by 2 to retain the same brightness."

"Same brightness" as what? Color1 or color2? The average? If you only want to mix the "color", not the brightness, you likely need to convert to a different color-space (like YUV or HSB).


I may be confused, but I think you're doing:
vec3 col0 = vec3(0.1f);
vec3 col1 = vec3(0.1f);

vec3 your_result = 2.0f*(col0*col1);
vec3 correct_result = mix(col0,col1,0.5f);

- giving
your_result = 0.02f
correct_result = 0.1f;

(the math works for 0.5 though :P )

Simon Wittber said...

LOL. I have much to learn. :-)

Popular Posts