Sign in to follow this  

PS2.0 can't support " if" instruction???

This topic is 3586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a simple PS shader, //effect.fx .... if(g_bUseTexture) { return tex2D( g_samScene, Tex0); } else { return diffuse; } ... i use SetBool("g_bUseTexture",TRUE) in main function , it works fine with PS1.4 or PS3.0,but when use PS2.0, it looks like doesn't run tex2d(g_samScene,Tex0). but the same code in dxsdk HDRLighting is OK. what's wrong??? Videocard:GF6600 DirectXSDK:9.0c2006Aug

Share this post


Link to post
Share on other sites
I seem to remember that previous versions of the FX compiler didn't allow for multiple returns, and it's possible there is a bug in the code for handling it. Try

if(g__bUseTexture)
diffuse = tex2D( g_samScene, Tex0);
return diffuse;


Another option would be run w/ the reference rasterizer. nVidia has several shader bugs in their drivers. If the refrast outputs the expected result, then you may have found a driver bug. If you're familiar with shader assembly, you could check the assembly output you get when you run fxc. If the assembly looks fine, it would point towards a driver issue. If the assembly looks broken, it would point towards a compiler issue.

Newer SDKs changed compilers, and there were several known issues with the new compiler. The old one is still available via a flag. What happens if you use the older compiler? If it works with the older compiler, post the full fx file here and we'll ensure it makes it to the DirectX compiler team.

Share this post


Link to post
Share on other sites
And in case it really doesnt support if instructions (AFAIK it does but just in case) then you can use:
return tex2D( g_samScene, Tex0 ) * bUseTexture + diffuse * (1-bUseTexture);


Share this post


Link to post
Share on other sites
thanks a lot.

i use fxc.exe compile the hlsl code to the asm,i didn't find any error.
then i try to change the sample BasicHLSL,
////BasicHLSL.fx
//add a new variable
bool g_bTexture;
//change the PixelShader:

PS_OUTPUT RenderScenePS( VS_OUTPUT In,
uniform bool bTexture )
{
PS_OUTPUT Output;

// Lookup mesh texture and modulate it with diffuse
if( g_bTexture )
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse;
else
Output.RGBColor = In.Diffuse;

return Output;
}


////BasicHLSL.cpp

...

V_RETURN( g_pEffect->SetValue("g_MaterialAmbientColor", &colorMtrlAmbient, sizeof(D3DXCOLOR) ) );
V_RETURN( g_pEffect->SetValue("g_MaterialDiffuseColor", &colorMtrlDiffuse, sizeof(D3DXCOLOR) ) );
V_RETURN( g_pEffect->SetTexture( "g_MeshTexture", g_pMeshTexture) );
//set the g_bTexture
V_RETURN( g_pEffect->SetBool("g_bTexture",TRUE));

// Setup the camera's view parameters
D3DXVECTOR3 vecEye(0.0f, 0.0f, -15.0f);
D3DXVECTOR3 vecAt (0.0f, 0.0f, -0.0f);
...


it has the same bug with mine. i can make it use other way like Guimo's,
but i want to know why?

Share this post


Link to post
Share on other sites
PS 2.0 doesn't support real flow control. 'if' is implemented by executing both paths and choosing the result. Boolean constants are only usable with real flow control. Uniform ones are processed at compile time, so work with every shader version. Global constants will only work with PS 2.0a or PS 3.0.

(You say that this also works with PS1.4. I don't know what SDK you're using, but current SDK's, since December 2006, don't compile PS1.x unless you specify to use the old compiler or promote them to 2.0.)

Share this post


Link to post
Share on other sites

This topic is 3586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this