Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I wrote a pixel shader for my game and when I tried to compile it an error occurred:

ID3DXEffectCompiler::CompileEffect: There was an error compiling expression

When I removed all the saturate functions from the shader it compiled without problems. Strangely the saturate function works for all techniques in this effect file but one.

This code worked for me:

float4 PixelShader(VertexToPixel PSIn) : COLOR0
{
    return xAmbientColor * xAmbientIntensity;
}

And this didn't work:

float4 PixelShader(VertexToPixel PSIn) : COLOR0
{
    return saturate(xAmbientColor * xAmbientIntensity);
}

-EDIT-

When I added some diffuse lighting the saturate function worked perfectly for the diffuse lighting calculation while it still didn't work for ambient lighting. This is really strange and I hope you can help me with this problem.

share|improve this question

2 Answers 2

The result must be store in a separate variable before return like

float4 c = saturate(xAmbientColor * xAmbientIntensity);

return c;

share|improve this answer
    
Why does that have to done? –  Jaakko Lipsanen Feb 9 '13 at 10:32
    
This also didn't work when I used saturate, again it worked without saturate. –  eagle999 Feb 9 '13 at 11:34
up vote 0 down vote accepted

I solved my problem:

float4 PixelShader(VertexToPixel PSIN) : COLOR
{
  //calculation of ambientColor and diffuseColor without using saturate
  return saturate(diffuseColor + ambientColor);
}

I don't know why, but this worked in my case. I hope I helped someone who is having the same problem. I think XNA can't handle saturate for calculations using only effect parameters.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.