Game Development Community

dev|Pro Game Development Curriculum

Shaders galore!

by Koushik · 09/20/2008 (9:54 pm) · 9 comments

I've been really occupied for the past many weeks, so a lot of things were put on the backburner for a bit. I've finally gotten around to finishing most of the shader-work that I had talked about. As I had promised, the multi-pass shaders are now complete, and whats more - they're compatible with the MK now!! Hurray!

I've tried to incorporate the entire shader source into the original MK's framework. I've removed most of my custom code in the process. As always, pictures speak louder than a thousand words, dont they?

First, some shots of the fur-shader again. I didn't have any models to really show them off, so poor old Kork was the scapegoat yet again.

Furry video

I am (finally!) using a GeForce 8600 with 13 render passes, and I got 45-50 fps. The results with fewer passes don't look all that bad, in fact 3 render passes work pretty well too, by just tweaking the shader parameters.

Second (there has to be a second, if there is a first, right?) there's another shader that I'd like to present. This one might find a lot more use - the sub-surface-scattering-approximation-texture-mapped-toner! Or for short - skin shader! Enough said, here are the screenies:

cowness.forever.googlepages.com/skin1.JPGcowness.forever.googlepages.com/skin2.JPGcowness.forever.googlepages.com/skin3.JPG
This actually works out of the box - no major material script changes and is single pass too!

Apart from this, the MK material system has been tweaked to now support uniforms and parameter passing via scripts! That means, you can have two different materials with the same shader, doing two different things. This was actually a precursor to my toon-shader. You can now pass-in the color of your object via the material script and have the shader perform NPR automatically, with just one shader!

cowness.forever.googlepages.com/toon1.JPGcowness.forever.googlepages.com/toon2.JPG
The green-head and the pink-ish kork are rendered using the same shader, but by specifying different color parameters in their respective material script definitions.

And finally, to top it all off - expect ALL of these in the next couple of days - as GG resources!!

Cheers and good luck with all your projects folks!

#1
09/20/2008 (10:55 pm)
Nice work, keep it up! I'm looking forward to the resources. I use MK in my current engine being used for development. The fur effect is pretty cool. Let me know if you need help having the fur shader carry over the texture color dynamically for a more color-realistic fur effect. Again, nice work!
#2
09/20/2008 (11:29 pm)
@Koushik - Could you show an example of how you setup passing shader constants via TorqueScript?
#3
09/21/2008 (5:42 am)
Oh great shader god, your greatness never ceases to amaze me! ;-)


Really sweet, keep it up!
#4
09/22/2008 (2:18 am)
@Trenton
The fur effect is texture-based. The rainbowy texture that I've used gives the expression that it is procedurally generated. If you check an older plan of mine, you'll see it applied to another model. Back then, I was using a different algorithm, fewer render passes and it would only run at 5 fps (that too in the show tool) given my graphics card's limitations. This is a variation of the same algorithm with more meat.

@Tom
As of now, there are 3 types of variables that you can pass into the shader - int, float and vec4. If you want a vec2 or a vec3, you'd just pass a vec4 with random values for the other components. Apart from that, the samplers are already handled by the MK out of the box.

Let me show you an instance:

(new material)
{
    (shader relations, like how you'd do it with the MK out of the box)
    textures[0] = "demo/client/data/tex.jpg";
    samplers[0] = "texture";

// Now the new stuff
    multipass = true;
    numPasses = 10;

    numIntParams = 1;
    numFloatParams = 1;
    numVecParams = 1;
    
    intUniforms[0] = "myVar1";
    intValues[0] = 10;

    floatUniforms[0] = "myFloat1";
    floatValues[0] = 1.5;

    vecUniforms[0] = "myVec1";
    vecUniforms[1] = "myVec2";

    vecValues[0] = "0.1 1.0 0.2 0.1";
    vecValues[1] = "0.4 0.1 0.3 0.5";
};

Now, I send the uniforms in the engine using the standard OpenGL uniform registration process. The first set of variables (intUniforms, floatUniforms, vecUniforms) store the variable name, which is stored as a const char*in the engine. The second set (intValues, floatValues, vecValues) store the corresponding values. While passing, we look up the variable name and send the corresponding value to it.

Also, for multipass shaders, each multipass shader receives a separate int variable denoting the pass number. So all shaders that have
multipass = true
set in their materials can define a variable as
uniform int passNumber
in the shader and this is automatically updated by the rendering system while rendering (which is done in tsMesh.cc) That, in effect, opens up a whole new world, so you could have shaders doing different things based on the pass. You could, in the shader, have a switch statement and do different things for different passes.
#5
09/23/2008 (9:20 am)
Brilliant stuff! You are a real hero, which I've said before, but now you're even more of a hero. Your heroism has no bounds, it seems ;)
#6
09/27/2008 (2:08 pm)
By the way - can shaders now control transparency?
#7
09/30/2008 (10:09 pm)
Yeah it can. It now supports custom blend modes as well. For general transparency, you'd use a different blend mode than for say, the fur shader's intermediate passes. Now you can set all of that stuff from script!!

EDIT: I just checked my account page and it doesn't show the resource I submitted in association with this. Shoot! There goes another resource lost to the web world, guess I'll have to resubmit it in a couple of days
#8
10/09/2008 (5:18 pm)
This is amazing, your cel shading looks ace. I can't wait for the resource ^^
#9
11/12/2008 (4:45 pm)
That fur effect is just plain awesome man.