サンプラーが実際にテクスチャ ユニットにアタッチされているかどうか、または単に設定されていないかどうかを判断することはできますか?
sampler2D mySampler : register(S0);
...
if(mySampler == 0)
value = const_value;
else
value = tex2D(mySampler, uv);
これは、違いが生じる場合の WPF 効果 (PS 3.0) 用です。
サンプラーが実際にテクスチャ ユニットにアタッチされているかどうか、または単に設定されていないかどうかを判断することはできますか?
sampler2D mySampler : register(S0);
...
if(mySampler == 0)
value = const_value;
else
value = tex2D(mySampler, uv);
これは、違いが生じる場合の WPF 効果 (PS 3.0) 用です。
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