Sign in to follow this  
Striken

shaders - multiple techniques in one pass

Recommended Posts

Striken    110
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.

Share this post


Link to post
Share on other sites
Hnefi    386
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.

Share this post


Link to post
Share on other sites
Striken    110
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?

Share this post


Link to post
Share on other sites
bluntman    255
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.

Share this post


Link to post
Share on other sites
HellRaiZer    1001
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this