Reputation: 6345
Is it possible to determine if a sampler is actually attached to a texture unit versus being simply unset?
sampler2D mySampler : register(S0);
...
if(mySampler == 0)
value = const_value;
else
value = tex2D(mySampler, uv);
This is for a WPF effect (PS 3.0) if that makes any difference.
Upvotes: 2
Views: 1597
Reputation: 3180
Afaik there is no direct way to check this. In my experiences uninitialized shaderconstants can behave very strange, e.g. one system drawed my scene all fine with an uninitialized texture, because tex2D returned simply black. But on another system the whole scene looked awful, because it returned other values then 0.
So you have to handle this cases from your other code. Either with with a global variable, which is set by yourself:
bool mySamplerisset;
sampler2D mySampler : register(S0);
...
if (mySamplerisset)
value = tex2D(mySampler, uv);
else
value = const_value;
Or for maximal performance, with avoiding the branch, with preprocessor directives, so you compile two versions of your shader (one time with #define one time without) an use the appropiate:
#define SAMPLERISSET
sampler2D mySampler : register(S0);
...
#if defined(SAMPLERISSET)
value = tex2D(mySampler, uv);
#elseif
value = const_value;
#endif
Upvotes: 1