Sign in to follow this  
newltf

Does input variable must affect output in shader?

Recommended Posts

I found an oddness when i write a shader. i declare a variable (vector temp) which value was determined by my application, i use this variable to compute something but have nothing to do with the output. The program was crashed when i run it but it works well if i use the variable do some calculate to affect the output. Who can tell me why? Does the input variable must affect the output?

Share this post


Link to post
Share on other sites
Hey bud,

I can't say why it is crashing, but the compiler will optimise out any code you have that does not affect teh output of the shader.

Dave

Share this post


Link to post
Share on other sites
You need to provide us with lots more information if you want any sort of a decent answer from people...

I guess you're using HLSL, but you've not provided a code snippet (post this inside [ source ] tags) for us to look at. You've also not specified if its through the FX framework or if you're directly working with the PS/VS objects.

You've not specified what line your error occurs on. I've never managed to make D3D crash by using a variable that was optimized out - generates a lot of debug output, but doesn't crash. We need more details here.

Have you tried running with the debug runtime? This usually gives you information on why functions are failing.

Have you tried using reflection data (in the effects framework) or examining the ID3DXConstantTable for "pure" shaders to see if your variable exists? You can also do this by writing the results of fxc.exe to an HTML file (see the docs for details)...

hth
Jack

Share this post


Link to post
Share on other sites
i use the vectex shader.i think the problem may be variable was optimized out
as Dava says. i use debug and find the crash expression is
DiffuseConstTable->SetVector(Device,DiffuseMtrlHandle,&diffuseMtrl);
and the DiffuseMtrlHandle is the Handle of the variable that was not used to
affect output.
here is the shader:


matrix ViewProjMatrix;
vector AmbientMtrl;
vector DiffuseMtrl;

vector DiffuseLightIntensity = {0.0f, 0.0f, 1.0f, 1.0f};
vector AmbientLightIntensity = {0.0f, 0.0f, 0.2f, 1.0f};


struct VS_INPUT
{
vector position : POSITION;
};

struct VS_OUTPUT
{
vector position : POSITION;
vector diffuse : COLOR;
};

VS_OUTPUT Main(VS_INPUT input)
{

VS_OUTPUT output = (VS_OUTPUT)0;

output.position = mul(input.position, ViewProjMatrix);

vector x=DiffuseMtrl;

output.diffuse = (AmbientMtrl * AmbientLightIntensity);


return output;
}



Share this post


Link to post
Share on other sites
Yes, well it would make sense that the variable is optimized out. Although it shouldn't be a fatal crash - if it's just throwing an exception, handle it and move along. If that doesn't work then you're going to have to post the error details - otherwise no one here can help you [smile]

hth
Jack

Share this post


Link to post
Share on other sites

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