Can you leave textures empty in the shader?

Started by
0 comments, last by MJP 11 years, 8 months ago
For instance,in my HLSL code I have:

Texture2D diffuseMap : register(t0); //The basic texture
Texture2D normalMap : register(t1); //The bump map thing
Texture2D displacementMap : register(t2); //For the tessellated ones
Texture2D effectMap : register(t3); //Each channel contains different info like: R/G/B/A:glow/waves/transparency/ect.

and I have one shader that I use for all geometry,where each model I render has a few bools:

bool tessellated;
bool glowing;
bool transparency;bool animated;

so for instance when I pass a model with animated == true and some bones,it does skinning in the vertex shader,otherwise it ignores the skinning part and carries on forward.I want to do the same thing with the textures - if it isn't tessellated and doesn't have glow or any special effects,I just set only the first 2 textures like this:


texturePointers[0] = material.diffuseMap;
texturePointers[1] = material.normalMap;
gD3DImmediateContext->PSSetShaderResources(0, 2, texturePointers);


And I ignore the glow and transparency calculation parts in the shader.

My question is - will that work?Because in the HLSL code it's written to expect 4 textures,however I don't want to waste time passing 4 when I'll only use 2 in some cases.
Advertisement
You can do this, and it will work fine in the shader assuming that you never sample those textures when the corresponding bool set to false. One issue you may run into in more complex scenarios is that the debug device may emit warnings if you end up with a type mismatch between bound textures. So for instance say you bind a multisampled texture to slot 3 for a shader, which accesses it as a Texture2DMS. Then after this you render with your example shader and you don't use effectMap, so you don't bind it. When you then render with that shader you'll get a warning saying that a Texture2D is expected but a Texture2DMS is bound.

This topic is closed to new replies.

Advertisement