Previous Blog Next Blog
Prev/Next Blog
by date

Shaders galore!

Shaders galore!
Name:Koushik 
Date Posted:Sep 21, 2008
Rating:4.5 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Koushik

Blog post
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:





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!




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!

Recent Blog Posts
List:09/21/08 - Shaders galore!
08/05/08 - Major announcements!
06/16/08 - ...And the sun shines again!!
04/26/08 - TGE fur-rendering!
04/08/08 - TGE normalmapping take 2 (image heavy)
03/25/08 - TGE Bump mapping - first screens!
03/10/08 - Shaders and Shiny pictures!!

Submit ResourceSubmit your own resources!

Trenton Shaffer   (Sep 21, 2008 at 05:55 GMT)   Resource Rating: 5
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!

Tom Spilman   (Sep 21, 2008 at 06:29 GMT)   Resource Rating: 4
@Koushik - Could you show an example of how you setup passing shader constants via TorqueScript?

Nathan Kent   (Sep 21, 2008 at 12:42 GMT)
Oh great shader god, your greatness never ceases to amaze me! ;-)


Really sweet, keep it up!

Koushik   (Sep 22, 2008 at 09:18 GMT)
@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.

Daniel Buckmaster   (Sep 23, 2008 at 16:20 GMT)
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 ;)

Daniel Buckmaster   (Sep 27, 2008 at 21:08 GMT)
By the way - can shaders now control transparency?

Koushik   (Oct 01, 2008 at 05:09 GMT)
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

Benjamin L. Grauer   (Oct 10, 2008 at 00:18 GMT)
This is amazing, your cel shading looks ace. I can't wait for the resource ^^

Scott Wilson   (Nov 13, 2008 at 00:45 GMT)
That fur effect is just plain awesome man.

You must be a member and be logged in to either append comments or rate this resource.