Rendering Pt2

Published March 16, 2009
Advertisement
At the end of last entry (which was now a long time ago ... my journal entries are lagging months behind the code unfortunately), we'd decomposed the render system into a set of reconfigurable building blocks, but those building blocks were still using the default fixed function render pipeline. Today, we take a giant leap into the late 90s and add hardware shader support.

My goals for hardware shader support was simple: from the game's/designer's point of view, any Cg or HLSL effect should look like a native object/material (i.e. totally indistinguishable from a built in C++ class). I didn't want the designer to have to create a CgShader object and then assign the shader to it. I wanted the game to automagically create dynamic classes on the fly that represented each of the Cg/HLSL effects it finds, and those classes should expose properties for each of the Cg/HSLS uniform parameters.

This does two things: it hides "how" a material is implemented (fixed function vs shader, Cg vs HLSL, C++ vs effect, etc) so that I can change how a material is implemented without breaking files that use it, and secondly, it allows you to connect or animate shader parameters just like any other object in the game.

Here's a shot of the current integration:

Disabled

All the Shaders you see are just sucked right out of the Shader directory at startup (hence names like "shadow_PCSS" and "OldDepthOfField"). If you look at the Plastic object, you can see it has Specular and Diffuse powers, controls for the Fresnel reflection, etc all driven straight off Plastic.cgfx. It's actually pretty robust, you can drop most of the Cg effects off the web in and play with them.

Under the hood, this is built on top of a new "MetaObject" object that lets you dynamically build and then instantiate new types for the Object system on the fly. In this case, the CgShader class (indirectly) derives from MetaObject and uses it to dynamically register a new class for each .cgfx file it finds, creating properties for each Cg parameter in each effect. It then overrides all the Property methods to pipe them down into the Cg runtime (so that setting a game property will actually change the Cg program state if that instance is actually bound to the Cg program).

I also knocked up a quick DDS file reader so I could support some of the sample textures ... but there are still lots of limitation in texture support in general (no 1D, 3D or cubemaps, no hardware support for texture compression, etc).

Next time, we'll take a look at lighting. Keen eyed readers may already have found a clue in the screenshot (while the Metal shader has the typical hard coded light parameters, the Plastic one is strangely devoid of any light inputs).

Cheers!
0 likes 4 comments

Comments

Ravuya
Way cool - you could probably sell something like this. I'm just starting to set up my shader infrastructure myself, but it won't be as artist-friendly as yours is by far.

How'd you do the plastic shader? I like the effect.
March 16, 2009 03:40 PM
Aardvajk
I hope the only point of all this is so that when the elephants start disco dancing, you'll be able to easily create disco lighting for them? [smile]
March 16, 2009 06:22 PM
Milkshake
Quote:Original post by Ravuya
Way cool - you could probably sell something like this. I'm just starting to set up my shader infrastructure myself, but it won't be as artist-friendly as yours is by far.

How'd you do the plastic shader? I like the effect.


Thanks Rav. The plastic shader is just the one straight out of the nVidia dev kit examples. Take a look here:

http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html

It's the plastic on the robot arm thing a few screens down from the top.

Longer term, I'm hoping to move to a more graph-compiled way of authoring shaders, but for now, this lets me try things out (and I think it will always be useful to be able to drop full effects in off the web). As far as selling it, there are so many things that the engine "just has to know" - particularly around how to bind the lights and any per-vertex mesh data - that makes it pretty hard to re-use stuff outside any given engine. I'm still waiting for the DX/Cg/GL guys to try and standardise it.
March 17, 2009 07:54 AM
Milkshake
Quote:Original post by Aardvajk
I hope the only point of all this is so that when the elephants start disco dancing, you'll be able to easily create disco lighting for them? [smile]


Woah - you caught me off guard there! I recognised the icon and the question ... but did a bit of a double take when I saw the new name =)

So one of the other outstanding things I need to add is "gobo" support (projected light textures). I think I can fit this into my current architecture pretty easily, but haven't had time to try it. So I know I'll be able to do some nice animated spot lights for them to get funky with ... but the full disco effect really needs the colours and disco-ball glitter you can only get from a gobo! (and in case anyone is curious given I only learnt this a few weeks back, I think "gobo" is "GOes Before Optics")




March 17, 2009 07:58 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Moose Sighting

1334 views

Constraints

1502 views

Moose

1240 views

Melon Golf

1782 views

Toon

1304 views

Spaceships

1056 views

Rendering Pt2

1149 views

Hardware Shaders

1182 views
Advertisement