Advertisement

Shaders and Lesson 47

Started by December 07, 2004 10:22 AM
0 comments, last by RipTorn 19 years, 11 months ago
Hi all, I've just started working with shaders and I've a couple of general questions, plus some regarding the tutorial itself. Starting from the tutorial: - I've reworked the code so that I can apply a shader on a per-model basis in my pre-existing engine and I tested it on a skinned (and animated) textured mesh. tha shader was applied successfully but I got no textures, so I read some documentation and I found out the TEXCOORD0-7 thing. I added tex parameters in the in and out structs and copied their values from the first to the latter and I got my texture working but it's not lighted. now, is this the way to go? does the shader have to take care of everything from lighting to texture? is it possibile to avoid some of these passages (for example using standard lights, preserve existing texture etc)? - I was thinking about having some shaders applied to single meshes and sometimes more than one shader per mesh to have particular effects (a glowing *something*, a blurring *somethingelse* etc). I know I can have at most 1 vertex and 1 fragment shader at a time si I'd have to do a multipass render of those objects, but can a shader that moves vertexes around interfere with that (I've never had to manage multipass rendering)? should I manipulate vertexes manually before applying shaders? anyway is it something feasible to have a global shader that takes care of, let's say, lighting or bump mapping for the whole scene and then 10 to 15 small meshes (100-300 polys) each with an additional and different from the others effect applied on it? or the shader switching would cause too much overhead? in this case should I just try to implement what I can without shader and just forget the rest?
You have touched on the two biggest problems with shaders.

No, unfortunatly, you cannot activate only some of the fixed function pipeline.. It's all or nothing.

And also, combining shaders can only be done the difficult way, by either writing a special format for mini-shaders that just do one thing, or writing variations (this is where lighting gets tough, eg, accounting for spot, directional, infinite, and more than one light...)

however, Direct3D 9.0c has added the ability to use 'shader fragments' and stitch them together -eg, an animation shader combined with a lighting shader at runtime.. Which I'm currently looking at with very keen interest.


What you could do, though, is with languages like DX HLSL and Cg, you can make functions of everything you want to do, then make individual shaders that call sets of these functions.. Naming the shaders appropriatly (eg, LightAnimateBendy shader, whcih calls light(), animate() and bendy()... [smile])

Cg also comes with a source file that does all fixed-function operations in shaders btw.... but it's not exaclty small

This topic is closed to new replies.

Advertisement