Render to Texture and Shaders

Hi!
I created a volume fog shader, i have 2 passes where i need to render depth of object to textures.
How i can pass render targets from DX to shader?

simple:
effect.BeginPass(1);
effect.SetValue("back_Tex", backTex);
effect.SetValue("ViewProjection", device.Transform.World * device.Transform.View * device.Transform.Projection);
mainMesh.DrawSubset(0);
effect.EndPass();

dont work :(

[438 byte] By [Xadja] at [2007-12-23]
# 1

Ok,

you have to do some steps:

1) Ensure that you texture are render targets:

LPDIRECT3DTEXTURE9 myRenderTexture;

D3DXCreateTexture(m_pd3dDevice, xres, yres, 1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &myRenderTexture);

Verify that your video card can use the format X8R8G8B8 as render target (use GetCaps). Some video cards need other formats like D3DFMT_A8R8G8B8.

2) Get the surface from your render texture:

LPDIRECT3DSURFACE9 texSurf;

myRenderTexture->GetSurfaceLevel(0, &texSurf);

3) Set the surface as render target, but BEFORE save your original target! :

LPDIRECT3DSURFACE9 oldTarget;

m_pd3dDevice->GetRenderTarget(0, &oldTarget);

m_pd3dDevice->SetRenderTarget(0, texSurf);

4) Now you call your drawing function.

5) Restore your render target:

m_pd3dDevice->SetRenderTarget(0, oldTarget);

You can use multiple render target as well.

Hope this help,

Happy coding!

AGPX

AGPX at 2007-8-30 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 2

Ok! thanks that was very useful :)

Xadja at 2007-8-30 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...