Problems to make optimized logic to work? [SOLVED]
I solved the problem by changing tex2D to tex2Dproj. This behaviour is slightly undefined in my opinion (since tex2D worked fine with the if-else approach). But problem solved, so I'm happy
Hi
I have implemented a CSM system and I got a problem to make the logic work in the pixel shader. DX9 is the technology. This is the code that I was intended to implement:
But it doesn't work (but the application executes). Strange enough, following code works that's logically equivalent but much less effective:
The input to the pixel shader is defined as:
I tried to solve the logic with different approaches such as switch-case but wasn't able. I stepped through the code in PIX and everything seamed alright. I experienced the same on both nvidia and ati cards. Does anybody know why this thing happens and how to solve it?
Thank you very much.
I solved the problem by changing tex2D to tex2Dproj. This behaviour is slightly undefined in my opinion (since tex2D worked fine with the if-else approach). But problem solved, so I'm happy
Hi
I have implemented a CSM system and I got a problem to make the logic work in the pixel shader. DX9 is the technology. This is the code that I was intended to implement:
Code:
float3 comparision = In.TextureUV.www > g_vecCsmSplitDistances.xyz;
int index = comparision.x + comparision.y + comparision.z;
shadow = tex2D( ShadowBufferSampler, In.LightSpacePos[index]);
But it doesn't work (but the application executes). Strange enough, following code works that's logically equivalent but much less effective:
Code:
float3 comparision = In.TextureUV.www > g_vecCsmSplitDistances.xyz;
int index = comparision.x + comparision.y + comparision.z;
if( !index)
shadow = tex2D( ShadowBufferSampler, In.LightSpacePos[0]);
else if( index == 1)
shadow = tex2D( ShadowBufferSampler, In.LightSpacePos[1]);
else if( index == 2)
shadow = tex2D( ShadowBufferSampler, In.LightSpacePos[2]);
else
shadow = tex2D( ShadowBufferSampler, In.LightSpacePos[3]);
The input to the pixel shader is defined as:
Code:
typedef float4 lightspacepos[CSM_NUM_SPLITS];
struct VS_OUTPUT
{
float4 Position : POSITION;
lightspacepos LightSpacePos : TEXCOORD0;
float4 TextureUV : TEXCOORD4;
};
I tried to solve the logic with different approaches such as switch-case but wasn't able. I stepped through the code in PIX and everything seamed alright. I experienced the same on both nvidia and ati cards. Does anybody know why this thing happens and how to solve it?
Thank you very much.
Last edited by a moderator: