Skip to main content
gamedev.net
🔒 Locked

Render to texture

Started by sri Oct 30, 2005 at 11:41 PM 2 replies 450+ views
Original Post
sri
sri
Hello, I have just started learning dirextX shaders(HLSL). I wrote a simple shader for diffuse, ambient and specular lighting. It worked fine. Now I want to learn the tecnique of rendering to a texture which can then be used as a buffer of information for a lot of things. So I wrote a test program in which I had two textures of format D3DFMT_A32B32G32R32F. One to store some data and other as a render target I intialize the first texture with some data and then render it to the second texture using a pixel shader then I try to copy the data to a third texture from the rendered texture. But the data I am getting back is not the same as the data I had input. What could be the problem. The pixel shader is very simple as it just copies the input data. sampler tex; float4 PSMain( float2 tex0: TEXCOORD ) : COLOR { tex2D( tex, tex0 ); } It is a simple program in which some data in stored in a texture, copied as it to some texture(render target) using a pixel sahder and then coping it back to the another texture. I am learning this stuff by reading the documentation and studying the sample programs on the net as I am in no position to by books and study. Thanks
circlesoft
circlesoft
What do you mean by "not the same"? Some ballpark troubleshooting:

(1) Are you just copying these render targets by drawing a textured quad? If so, make sure that you are performing that step correctly (ie the texture coordinates are correct, ect...)

(2) What type of texture filtering do you have enabled in your sampler? Perhaps your pixels are getting filtered during the sampling read. Of course, this wouldn't really account for a huge alteration of data.
Keba
Keba
just a thought, shouldn't it be "return tex2D( tex, tex0 );" ??
sri
sri
Hello,

Thanks for the reply. Yes I am coping by simply drawing the quad. I rechecked
my code but its not working.
The following are the details of the render functions

SetStreamSource( 0, quadBuffer, 0, sizeof( CTexVertex ) );
SetFVF( D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0) );
SetPixelShader( pixelShader );
SetTexture( 0, positionTexture );
SetSamplerState( 0, D3DSAMP_MAGFILTER, LINEAR );
SetSamplerState( 0, D3DSAMP_MINFILTER, LINEAR );
SetRenderTarget( 0, pRenderTargetTexture );
Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 0 ),
1.0F, 0 );
BeginScene(),
DrawPimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
EndScene(), Present(),
Resetting the rendertarget back to what it was before

The world, View, Projection transform, Back face culling to none,
zbuffer enabled, lighting false.
All the above mentioned setting have been set properly.

When I try to read the values from the render target all the values are
zero. These are the values it is getting from the Clear calls.
I am telling this because when I put the values of 255 for the Red component
in the clear function call I get the x component of 1 on reading the values from the render target.
This means that nothing is being written to the render target. What could be the problem.

Could anybody provide me the complete source code along with the direct3D device
setting or direct me to a tutorial that explains this stuff. It would be very helpful.

Thanks again.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.