Archived

This topic is now archived and is closed to further replies.

softimage

how to save pixel shader result to another texture?

Recommended Posts

softimage    122
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?

Share this post


Link to post
Share on other sites
jacklin    124
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.

Share this post


Link to post
Share on other sites
softimage    122
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?

Share this post


Link to post
Share on other sites
jacklin    124
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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Did you setup new camera, projection and world matrixes before rendering to texture?

Share this post


Link to post
Share on other sites
softimage    122
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.

Share this post


Link to post
Share on other sites
neneboricua19    634
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

Share this post


Link to post
Share on other sites
softimage    122
quote:
Original post by neneboricua19
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


the debug messages include nothing special, and the return value is D3D_OK.

i noticed that in
StretchRect(m_renderTarget, NULL, m_renderResultSaved, NULL, D3DTEXF_NONE );

from GetDesc(), i can see that the two surfaces are of the same size, 592*466,which is equal to the
size of the client window.
the m_renderTarget is got by IDirect3DDevice9::GetRenderTarget(), not by CreateTexture.
even if i specify the 592*466 instead of NULL, i can only get
the left-upper part of renderTarget.
and at this place StretchRect works well stretching other textures.

Share this post


Link to post
Share on other sites
neneboricua19    634
What about the "renderResultSaved" variable? How was this one created? I ask because I''ve run into some issues with StretchRect depending on if a texture is created to be dynamic, or in a specific memory pool, etc...

neneboricua

Share this post


Link to post
Share on other sites
softimage    122
quote:
Original post by neneboricua19
What about the "renderResultSaved" variable? How was this one created? I ask because I''ve run into some issues with StretchRect depending on if a texture is created to be dynamic, or in a specific memory pool, etc...

neneboricua


GetDisplayMode(NULL, & dm );
CreateTexture(592, 466, 1, D3DUSAGE_RENDERTARGET, dm.Format,
D3DPOOL_DEFAULT , & m_renderResultT.p, NULL );

Share this post


Link to post
Share on other sites
softimage    122
got the answer:

i copied the code from the sample vmr9allocator in DXSDK, which
change the u,v values of triangle points to be less than 1,
so i can see only a part of the texture i posted onto that
triangle.

sorry for making such a long thread.

Share this post


Link to post
Share on other sites