Jump to content
  • Advertisement
Sign in to follow this  
freeworld

using a texture as a render target

This topic is 3814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get some post processing to work, by setting up a texture as a render target, drawing to it, then using it as a texture to apply a shader to and draw it to the back buffer. This is how it should look Photobucket This is how it does look, useing the render to target method, and the exact same shaders as above. Photobucket Here how I setup the texture to be used as a render target.
result = D3DXCreateTexture((*m_d3ddev), 
		                       CGraphics->Width(), CGraphics->Height(), 
		                       D3DX_DEFAULT,       D3DUSAGE_RENDERTARGET, 
							   D3DFMT_A8R8G8B8,    D3DPOOL_DEFAULT, 
							   &texture.texture);

it's created to be the same size as the backbuffer. I then aquire the surfaces like so and set the render target to be the texure.
// save the current render target
	(*m_d3ddev)->GetRenderTarget(0, &m_prev_buffer);
	// get and set our new render target
	m_temp_texture->texture->GetSurfaceLevel(0, &m_new_buffer);
	(*m_d3ddev)->SetRenderTarget(0, m_new_buffer);
	// clear the texture before rendering to it
	(*m_d3ddev)->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 255), 1.f, 0);

// temp texture is the IDirect3DTEXTURE9 of the texture I'll be using as a
// render target

// prev_buffer is a SURFACE representing the main backbuffer
// new_buffer is the texture surface 

Am I setting the render target right, or do you need any more info?

Share this post


Link to post
Share on other sites
Advertisement
I don't see you actually rendering the texture?
Did you leave that code out on purpose?

The steps you need to take in this approach is the following

1: Render your normal scene
2: Save the old back buffer
3: Set the new render surface (texture)
4: Render to that surface and reset the old back buffer
5: Apply effects to texture and render that texture as a full screen quad.

I hope this helps.
Take care.

Share this post


Link to post
Share on other sites
Quote:
Original post by Armadon
I don't see you actually rendering the texture?
Did you leave that code out on purpose?

The steps you need to take in this approach is the following

1: Render your normal scene
2: Save the old back buffer
3: Set the new render surface (texture)
4: Render to that surface and reset the old back buffer
5: Apply effects to texture and render that texture as a full screen quad.

I hope this helps.
Take care.


I figured it would be assumed but yeah, this is basically my order of doing things...psudeo code


1: Get old rendertarget
2: Set new rendertarget
3: fill vertex buffer
4: drawprimitives
5: reset rendertarget to old one
6: add the texture to my render que
7: repeat steps 3 and 4 with the normal render target.




I'm new to most these techniques, so I'm shooting in the dark when looking through the docs for stuff to try out to fix it.

Share this post


Link to post
Share on other sites
how are you setting up your texture when you render it out? It looks like just the particles there are corrupted, not the rest of the scene, I don't know how you have the rest of your code structured, but is it possible you set everything up to render out the texture for post processing, then forget to change it back before using that same texture slot (I dont know how you are setting your textures, but it is possible that your particle texture is being set in the same place as your backbuffer texture) to render your scene the next frame?

Just throwing out a thought I had.

Share this post


Link to post
Share on other sites
Are you getting any messages from the debug runtime?

I'd recommend taking a PIX capture to check the state of the device after you've set up the render target.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promethium
Do you call BeginScene()/EndScene() between setting the render target and using the texture?


I use the setrendertarget functions outside of the end/begin calls.

Also after drawing to the texture I reset the render target by calling.

(*m_d3ddev)->SetRenderTarget(0, m_prev_buffer);

And like said before push the texture onto my render que to be drawn like normal.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lazerbeard
how are you setting up your texture when you render it out? It looks like just the particles there are corrupted, not the rest of the scene, I don't know how you have the rest of your code structured, but is it possible you set everything up to render out the texture for post processing, then forget to change it back before using that same texture slot (I dont know how you are setting your textures, but it is possible that your particle texture is being set in the same place as your backbuffer texture) to render your scene the next frame?

Just throwing out a thought I had.


I didn't quite understand what you were saying? Do you mean, am I switch back to the back buffer before trying to draw the texture?

OK your reply got me thinking, I was using the texture I'm rendering to, to render to it's self, I swear I gotta stop coding past 10pm I just keep making the silliest of mistakes.

Share this post


Link to post
Share on other sites
The problem must lie somewhere else because at this high level, things look just fine. As someone suggested, try turning the debug runtime on to see if you get any messages. Also, make sure you're not _using_ your texture render target when you're rendering into it (ie: you can't use and render to the same texture at once...obviously).

Time to start using those handy debugging tools! I'll say that my favorite is NVPerfhud. It shows exactly how your scene is rendered and can help you spot problems really quickly; it saved me tons of time already.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!