View Full Version : using a render target as an input in the shader
rouncer
01-01-2009, 11:25 PM
Can u use a render target as a texture resource? how does this work?
thankyou.
Im using direct x 10.
Reedbeta
01-01-2009, 11:30 PM
A quick google search turned up this (http://msdn.microsoft.com/en-us/library/bb205131(VS.85).aspx) (scroll down to "Rendering to a texture") and also this (http://msdn.microsoft.com/en-us/library/bb205128(VS.85).aspx).
Technically, you can't use a render target as a texture; you must use a texture as a render target. That is, you have to create it as a texture and then create a "render target view" of the texture.
rouncer
01-01-2009, 11:43 PM
Thanks for the reply.
I dont want to render to a texture, i want to use the render target AS the texture, you can do this in dx9.
Maybe it takes copying the render target texture to a normal one, so you can use it as an input.
JarkkoL
01-02-2009, 04:07 AM
You can't use render target (surface) as a texture in DX9. You have to create texture with render target flag (D3DUSAGE_RENDERTARGET) and then get surface from the texture (IDirect3DTexture9::GetSurfaceLevel() function) which you use as the render target. Anyway, I don't know about DX10.
rouncer
01-02-2009, 06:56 AM
I remember you could, i used to do it all the time, but maybe I'm remembering incorrectly.
Maybe in dx10 you cant (well it doesn't seem like you can from what I've tried.) Maybe it involves some
kind of video memory to video memory transfer, which wouldn't slow things down... Can anyone help me out?
I remember you could, i used to do it all the time, but maybe I'm remembering incorrectly.
Maybe in dx10 you cant (well it doesn't seem like you can from what I've tried.) Maybe it involves some
kind of video memory to video memory transfer, which wouldn't slow things down... Can anyone help me out?
I'm confused. You create a texture. You then create a render target view and you have your render target. You then can bind the texture to a shader input. Works for me.
Do you mean in DX9 you were using a render target as a shader input and output simultaneously? If so, you could do this under DX9 but the result was undefined (ie it may work as you expect but probably not). It wouldn't surprise me if DX10 was pickier about such things.
JarkkoL
01-02-2009, 07:53 AM
I remember you could, i used to do it all the time, but maybe I'm remembering incorrectly.
Most likely you are remembering incorrectly (: Only way you could do something similar is that you would create a texture and copy the surface with StretchRect() from render target surface to the texture surface, but that would consume twice the memory and wouldn't be as efficient due to the surface copy. Any reason why you don't just create the texture with the render target usage and render to it directly?
rouncer
01-02-2009, 08:22 AM
The situations this, I'm making a modeller with the gpu, and I need the displacement map (its a displacement map editor) as a render target so I can use the gpu to edit the surface, but I also need to display the data on the model. So if you understand that, thats what I'm doing.
Is there a stretch rect in dx10?
JarkkoL
01-02-2009, 08:48 AM
Yeah, well as far as I can tell, you should create the displacement map as a texture, but I can't really help with DX10 specific stuff. I had a quick look to DX10 docs though and there seems to be ID3D10Device::CopyResource() which might do what you want, but that's just a total guess.
rouncer
01-02-2009, 08:56 AM
I got it working with copy resource, thankyou. (Yeah I checked myself.)
But JarkkoL - you were allowed to blatantly use render targets as textures in dx9.
Its not in dx10, that means you have to waste ram if you want rendered computer terminals in your game like doom3, but its only a video memory to video memory copy so it wouldn't hamper speed much.
Sorry if this is a bit obvious, but I only just picked up dx10 properly yesterday, so I'm still stumbling around in it.
JarkkoL
01-02-2009, 09:20 AM
Well, good that CopyResource() worked (:
You can't use surfaces as textures in DX9. You have to have IDirect3DBaseTexture9 interface for IDirect3DDevice9::SetTexture(), which you can't get from a IDirect3DSurface9. You have to go other way around and use IDirect3DTexture9::GetSurfaceLevel() to get surface for IDirect3DDevice9::SetRenderTarget();
Yes, you can copy the surface but why would you since you can just directly render to the texture, which is 1) faster 2) uses less memory 3) the resulted code is simplier & more straight forward.
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.