View Full Version : Rendering To floating point render target
Phlex
12-11-2008, 07:01 PM
Hey there,
I'm trying to render a scene to a floating point render target, I have functions to decode and all, but I don't know how to create a render target of say D3DFMT_A16B16G16R16F or setting it to RGBE8. Can someone help me?
EDIT: forgot to mention, I'm using DirectX9
starstutter
12-11-2008, 08:50 PM
Do you know how to create a normal render target? if so its not any different than declaring any other type:
LPDIRECT3DTEXTURE9 texture;
LPDIRECT3DSURFACE9 surface;
d3ddev->CreateTexture(sizeX,sizeY,1,D3DUSAGE_RENDERTARGET, D3DFMT_A16B16G16R16F,D3DPOOL_DEFAULT,&texture,NULL);
texture->GetSurfaceLevel(0,&surface);
keep in mind though that not all cards fully support floating point render targets. What kind of card are you using? Any relativley modern card should work.
Phlex
12-11-2008, 09:28 PM
Hey startstutter,
Thanks for the reply and help. Using the D3DUSAGE_RENDERTARGET enum will acutomatically set it as the render target? Because I'm working on an HDR app and I need to render to a floating point texture and then I will tone map etc then convert it back to an integer value texture.
Also, I am aware some cards don't support floating point textures, I use the D3DCAPS9 structure to check before intialising :)
starstutter
12-11-2008, 09:39 PM
Using the D3DUSAGE_RENDERTARGET enum will acutomatically set it as the render target?
Yup, it's that easy :) And yeah, I didn't belive it either lol
Because I'm working on an HDR app and I need to render to a floating point texture and then I will tone map etc then convert it back to an integer value texture.
Should work fine, but out of curiosity, why do you need to convert it back to an interger value texture? It should display fine as HDR if you just draw the target as a fullscreen quad to the back buffer
Phlex
12-11-2008, 09:50 PM
"Should work fine, but out of curiosity, why do you need to convert it back to an interger value texture? It should display fine as HDR if you just draw the target as a fullscreen quad to the back buffer"
I thought that after tone mapping, you had to convert back to an integer value texture?? Could you please explain the last part?
starstutter
12-11-2008, 10:10 PM
I thought that after tone mapping, you had to convert back to an integer value texture?
nope, should display fine on the moniter. Converting it back would just be an extra rendering pass. All the color values must be between 1 and 0 on the screen, but thats done automaticly by the graphics card and manually converting it back would just be a waste of resources.
All you need to do to display it is set up 2 polygons on the screen to make a square in 2D space (so their coordinates would be
(0,0)
(screenwidth, 0)
(0, screenheight)
(screenwidth, screenheight)
If you've programed in 2D I'm sure you've made 2D quads before. Then just set the render target as the texture and draw away.
Phlex
12-11-2008, 10:29 PM
That won't work so well you see. I'm not sure if you know much about HDR, but it requires you to use values well beyond the usual 0.0 - 1.0 limits. These can go up to thousands! This would be just too much for the monitor. What happens is anything above 1.0 is clamped to 1.0 and anything below 0.0 is clamped to 0.0. Usually if you don't tone map it will be nearly completely white, or is that what you are saying? Tone mapping will bring it down to a manageable brightness anyway?
Thanks
Reedbeta
12-11-2008, 10:44 PM
You do tone map, but it's fine if the output of tone mapping is still a floating point texture. In other words it needs to be brought within the 0-1 range but does not need to be converted to integer.
Phlex
12-12-2008, 02:50 AM
So if I render like this it should work?
render to floating point texture
downsize to new texture and surface and keep the first render there
calculate measured Luminance
bright pass the downsized texture using the measuered Lumminance
bloom filter the above result
upsize the bloomed texture
compose the bloomed texture and the first render pass
????
starstutter
12-12-2008, 07:02 AM
yup, you got it :)
The only thing I would be careful of is, how are you planning to extract the luminance? If you lock the texture, that's really not a good idea. Personally what I do is about 3 passes, which each one progressivley smaller, of downsampling the rendered scene untill its only 1x1 pixel.
Then I render the 1x1 texture onto a non-opaque background, so the result of the eye adaption is not instant (you get a smooth fade transition effect). The next step is to take that and just stretch it back over the final image, like you do with the bloom image, and use a multiplication style blending.
Above all though, just avoid locking it, it's easy to cause stalls in your engine by doing so.
Phlex
12-12-2008, 09:22 AM
I sample the average log log() values into a 64x64 texutre then down sample another 2 times till I have a 1x1 texture then perform and exp() operation on the result.
What do you mean when you render the 1x1 texture onto a non-opaque background?
Reedbeta
12-12-2008, 09:58 AM
I think he means he blends it with the previous frame's luminance value, so you get a smooth change in exposure over a few frames.
Phlex
12-12-2008, 05:59 PM
Ahhh ohk I see, thanks for your help guys :)
starstutter
12-12-2008, 07:49 PM
I think he means he blends it with the previous frame's luminance value, so you get a smooth change in exposure over a few frames.
precisley
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.