Saturday, May 21, 2011

Shader - Color Shading

This time I will talk about color shading in shader.

Before I start to talk more about it, let me illustrate what it is used for.

I believe most of you did play racing game before. Now I will take Need For Speed as an example. Do you remember that you can change the color of the car to whatever color you want in Need For Speed? You can even add some graffiti on the car skin too. Question is, how can all these effects be done?

The answer is very simple, you need SHADER!
All you have to do is creating masking for each model.
*Sample masking map for Lamborghini model.

As you can see, there is only black and white color in the map (you can do grayscale level if you want to)

So what is this map used for? Basically your shader program will use this map as a reference, white color part will be affected (means it will change color) and black color part will not be affected (it won't change color).

The formula to change the car skin color is:
CurrentColor = CurrentColor * Masking.a

You will notice that Masking.a, how about r,g and b?
The answer is, you can actually put 4 maps on 1 complete texture, which means you can do 4 different pattern of masking on a 3D model. Cool isn' it?

Example:
Car skin masking will be stored in R channel.
Car rim masking will be stored in G channel.
Car window masking will be stored in B channel.
Car bumper masking will be stored in A channel.

All you need to do is creating masking map to whatever pattern you want :)

Sample screenshots:
*Default Lambo with white color

*Lambo in red color

*Lambo in green color

*Lambo in blue color

Notice that all the color changes only applied on the car skin but not the whole car. This is the power of using masking :)

Video demo:



Here's the download link:

Key control:
1 - Default model
2 - Model with diffuse map only
3 - Complete model

Once you are in complete model, you can press the following keys to change color.
R - Red color
G - Green color
B - Blue color
Y - Yellow color
P - Pink color


CREDIT: Thanks to Mr.Hiew Sau Fung sponsored me all these 3D models.

No comments:

Post a Comment