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.
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:
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: