Question

I've got a bit of a problem when using the FX framework to bind textures to samplers using the FX framework:

ID3DXEffect->SetTexture(FXShadowtex,Lights->sunlight->ShadowTex)

Once that texture is bound to a sampler I'm not allowed to render to it again (let's say, when the sun changes position). When I do, this errors comes up:

Direct3D9: (WARN) :Can not render to a render target that is also used as a texture. A render target was detected as bound, but couldn't detect if texture was actually used in rendering.

However, I can't find out how to 'unset' a texture using the FX framework or anything else reliably. I've tried a few things:

  • ID3DXEffect->SetTexture(FXShadowtex,NULL). This causes a crash.
  • ID3DXEffect->SetTexture(FXShadowtex,SomeDummy). This is really ugly.
  • Find out which sampler index corresponds with the sampler defined in the fx files after compilation, and set that to NULL: IDirect3DDevice9->SetTexture(i,NULL). This is obviously not very practical.
  • Forget about the warning. This makes the D3D debug output useless thanks to the endless amounts of spam, and too is quite ugly.
  • Before doing any rendering, loop from zero to the number of samplers defined in the fx files, and set them all to NULL. This is ugly too.

Is there any other approach that I'm forgetting about? Explaining why any of the above 'solutions' are a necessary evil would be fine too. :)

Was it helpful?

Solution

Find out which texture unit is bound to that sampler uniform (see ID3DXEffect class on msdn), then simply unset the texture with IDirect3DDevice9::SetTexture().

I think this solution is the least ugly in this case. However, you can always write your own effect class (which is pretty straightforward btw).

Use for example D3DXCompileShaderFromFile then you can go through the returned constant table and set uniform values with IDirect3DDevice9::SetPixelShaderConstantF. Note that matrices are set column-major in this case (which means you have to multiply the vector from the left in the shader). An effective solution is to allocate a continous space for the constants and set them in one call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top