Friday, April 11, 2008

Materials and Shaders

For those of you implementing a material system, this may be useful. I'm going to share my experiences making my "uber" shader. Well to be honest, its not as "uber" as it sounds, but nevertherless, it gets the job done. I created 1 effect with all my per pixel lighting code. (CgFX, I'm using NVIDIA Cg). In that effect I simply made a permutation of passes for all the possible materials we'll be using in our game/engine. The scene manager binds the appropriate pass and efficiently batch renders everything. For example, if my material had a diffuse map, gloss map (specular map) and it was parallax mapped, then, I'd name my pass DGNP, D for diffuse, G for gloss, N for normal required, and P for height map (required for parallax mapping). So what you notice here is, all the letters in the pass' s name are in accordance with the ordering of the English Alphabet. This makes it easy for the scene manager to refer to materials based on letters.

Here are some screens, the FPS is pretty low because I had some processes and graphics applications running in the background.

No comments: