Better solution for boolean mixing?
- by Ruben Nunez
Sorry if this question has been asked in the past, but searching Google and here didn't yield relevant results, so here goes.
I'm working on a fragment shader that implements both conditional/boolean diffuse and bump mapping (that is to say, you don't need a diffuse texture or a normals texture, and if they're not present, they're simply changed to default values).
My current solution is to use a uniform float to say "mix amount". For example, computing the diffuse texel works as:
// Compute diffuse amount scaled by vCol
// If no texture is present (mDif = 0.0), then DiffuseTexel = vCol
// kT[0] is the diffuse texture
// vTex is the texture co-ordinates
// mDif is the uniform float containing the mix amount (either 0.0 or 1.0)
vec4 DiffuseTexel = vCol*mix(vec4(1.0), texture2D(kT[0], vTex), mDif);
While that works great and all, I was wondering if there's a better way of doing this, as I will never have any use for in-between values for funky effects.
I know that perhaps the best solution is to simply write separate shaders for mDif=0.0 and mDif=1.0, but I'd like a more elegant solution than splicing shaders before compiling or writing multiple shader files and keeping each one updated.
Any ideas are greatly appreciated. =)