HDR tutorial

Started by
10 comments, last by GameDev.net 19 years, 9 months ago
I'm talking about the tutorial recently added in GDNet. In this page the author explains how to suppress LDR values,so you don't blend the whole scene,just the pixels that are above 1.The way he does it,is:If one of the color components is >1,then keep the whole color,else return 0.This is kind of weird.If we had (0.8,0.8,0.8),the program would dismiss it,but if we had(1.2,0.8,0.8),it would keep the whole color,not just the red channel.I thought the proper way to do it was to subtract 1 from all components and clamp to 0. Does anyone knows about this and can explain to me why the author's way is correct?
Advertisement
yes, the way he does this is quite weired. unless it's for some sort of special effect.
but ideally, you only want overbright pixels (> 1 after exposure multiplication) to produce a glow, so you should clamp to 1 and substract 1 (or the other way round, then blur and add it to the frame buffer)
Ok,I looked it a little bit longer,and he doesn't seems to do additive blending,instead he uses a function named "lerp" bettween the two textures.What is that?But,either way,his SupressLDR function still bugs me.It's just not seems right.
ah, yes, a lerp could explain it, although I don't really see the benefit, it just seems overkill
lerp is slang for linear interpolation. Basically, it's a function that lets you transition smoothly from color a to b. So, it you lerped between a pixel with color 0,0,0 and a pixel 0,0,200, the pixel halfway between them would be 0,0,100.
Okay...
So if the color on the normal framebuffer is (0.8,0.8,0.8),the color on the blended buffer would be (0,0,0).If he linearly interpolates between these 2 values,the final image will be darker than the original.And it seems to me that if you're using interpolation,and not additive blending,you don't even have to supress LDR values.It just seem strange that minor changes in one channel can cause huge changes in the other channels.
The final image has to be darker than the original, so we can display it. As he says, the step where lerp is used is the tone mapping step, which is used to make the map displayable.

Edit - with regards to your first question. Maybe I'm getting confused from your use of the word blend. But in this particular example, the only suppresion of LDR values is when creating the image to be blurred. So he takes the original, removes LDR values, then blurs it. Then lerps the original values with the blurred values, and since LDR values were removed from the image that was blurred, we have very little if any blur around the LDR values in the resulting image, which stands to reason.
Quote:Original post by digitec devil
The final image has to be darker than the original, so we can display it. As he says, the step where lerp is used is the tone mapping step, which is used to make the map displayable.


I just gave an example when the original color of the pixel whould be (0.8,0.8,0.8).We can display that.But,the way he supresses LDR,it will be lerped with (0,0,0),thus darkening it for no reason.
-EDIT:Yes I meant blurred,not blended.And,don't we want blur around the LDR values?I mean that's why HDR is used,to create that nice glow around very shiny objects.
Quote:Original post by mikeman
Quote:Original post by digitec devil
The final image has to be darker than the original, so we can display it. As he says, the step where lerp is used is the tone mapping step, which is used to make the map displayable.


I just gave an example when the original color of the pixel whould be (0.8,0.8,0.8).We can display that.But,the way he supresses LDR,it will be lerped with (0,0,0),thus darkening it for no reason.


The middle step you're leaving out is the blurring step, while in some cases you're right it may be lerped with (0, 0, 0), we can't guarantee that.
ah, I just had a look at the code of that tutorial.

I didn't understand you when you said this:
"If we had (0.8,0.8,0.8),the program would dismiss it,but if we had(1.2,0.8,0.8),it would keep the whole color,not just the red channel.I thought the proper way to do it was to subtract 1 from all components and clamp to 0."

if you're wondering why he does this:

float4 SuppressLDR( float4 c )
{
if( c.r > 1.0f || c.g > 1.0f || c.b > 1.0f )
return c;
else
return float4( 0.0f, 0.0f, 0.0f, 0.0f );
}


it's just to keep a correct glow colour. you can't consider each pixel's channels separately (if that's what you wanted to do), it will produce incorrect colors.
if you've got a color shade that goes from 0.9, 0.5, 1.6 to 2.3, 1.2, 3.1 (r ,g ,b)

considering each color separately will produce color bands in the glow, as each channel will go above 1.0 separately, not at the same time. the first glow color you'll get for low intensities will be blueish, then when the red overflows it will look purple-ish, then after the green component overflows you'll have to add it to the glow color too, and each time a component gets above 1, you will get color banding. (not really as noticeable as regular color banding of course, as there is a blur applied to it, but still)

EDIT: formatting

This topic is closed to new replies.

Advertisement