how to save pixel shader result to another texture?

Started by
12 comments, last by softimage 20 years, 3 months ago
i can only see the texture addressing instructions to load a pixel from a texture. how can i save the result of one frame for comparing when processing the next frame?
Advertisement
Render to texture.

Muhammad Haggag

Create a texture with the D3DUSAGE_RENDERTARGET usage. Then, when you render your scene, call GetSurfaceLevel() on the texture to obtain a surface object, then call IDirect3DDevice9::SetRenderTarget() with the surface. After rendering, your pixel shader output will then be written to this texture. Don''t forget to restore the render target before you use this texture as a source texture in a later pass.
You can also use ID3DXRenderToTexture, if you don''t want to do things manually.

Muhammad Haggag

quote:Original post by jacklin
Create a texture with the D3DUSAGE_RENDERTARGET usage. Then, when you render your scene, call GetSurfaceLevel() on the texture to obtain a surface object, then call IDirect3DDevice9::SetRenderTarget() with the surface. After rendering, your pixel shader output will then be written to this texture. Don''t forget to restore the render target before you use this texture as a source texture in a later pass.



i SetRenderTarget, then after DrawScene,
i use StretchRect(renderTarget, NULL, renderResult, NULL, D3DTEXF_NONE);
but the renderResult appear to contain only the left top part of the result seen on the screen,
since i use NULL to specify full-size source, maybe the renderTarget itself contains only partial image?
Are you trying to copy from renderResult to renderTarget? Check that you don''t have the order backward for StretchRect().

Do these two surfaces have the same size?
quote:Original post by jacklin
Are you trying to copy from renderResult to renderTarget? Check that you don''t have the order backward for StretchRect().

Do these two surfaces have the same size?


the sequence is right, copying rendertarget to renderresult.
the surface descriptions of this two including dimentions are the same.
and the StretchRect works fine when i change the source to another texture except renderTarget.
Did you setup new camera, projection and world matrixes before rendering to texture?
quote:Original post by Anonymous Poster
Did you setup new camera, projection and world matrixes before rendering to texture?


yes, and it works well when i project another texture.
seems so strange.
It may be because of the flags used when the textures were created. Are you running the Debug Runtime? Is there any output to the debug spew? Have you checked the HRESULT values? Many times, the debug spew will tell you if an error or even if something strange is happening.

neneboricua

This topic is closed to new replies.

Advertisement