shaders - multiple techniques in one pass

Started by
5 comments, last by Striken 16 years, 9 months ago
Hi, was wondering if anyone knew if it's possible (and could possibly explain how) to combine multiple seperate techniques into a single render pass with shaders, without writing a collection of shaders for different scenarios. I've had a fiddle with cgFX but as far as I can tell, it's not possible. e.g. Shader 1 - Diffuse map Shader 2 - Specular map Shader 3 - Normal map
[Source]

//Prefered method, bit of pseduo code.
//Load in model.3ds
model.Load()
if(diffusemap)
 - bind shader1
if(specularmap)
 - bind shader2 
if(normalmap)
 - bind shader3

//Want to avoid:
if(diffusemap && specularmap && normalmap)
 - bind_fulldetail_shader
else if(diffusemap && specularmap)
 - bind diffuse_specular_shader
else if(diffusemap)
 - bind diffuse_shader
//...etc

[/Source]
thanks in advance.
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
Advertisement
You could send a uniform unsigned int to the shader and use that as a bit field to switch stuff on and off. That's what I usually do - it's not very pretty, but it's very simple and it works.
-------------Please rate this post if it was useful.
Ok, thanks.

I had considered that as an option, but I had read somewhere that conditional statements in shaders should be avoided like the plague. I might just do it anyway for the sake of getting things running.

Any one else have any variations?
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
GPU Gems has a good chapter entitled "An Introduction to Shader Interfaces" which may provide what you want. I haven't implemented any of it, I just read it after trying to find another chapter I thought was in GPU Gems 1/2 called something like "Composeable Shaders" which I was going to point you to. The shader interface solution sounds pretty neat, but it still requires some management on the client side.
Quote:Original post by bluntman
I haven't implemented any of it, I just read it after trying to find another chapter I thought was in GPU Gems 1/2 called something like "Composeable Shaders" which I was going to point you to.

I think you are referring to the "Recombinant shaders" article in Game Programming Gems 5 (Chapter 5.10). Even if you didn't have that in mind i suggest reading it (if you have the book), because i think it's pretty good, as the "shader interfaces" one.

HellRaiZer
HellRaiZer
Yeah that was the one!
cheers guys, rating+
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.

This topic is closed to new replies.

Advertisement