Tuesday, November 01, 2005

HDR to LDR Reflection Hack


I was sitting and staring (in awe) at our flooded golf-course demo again and I noticed that even though we have fresnel falloff on the water surface, the relative brightness of the sun's reflection never changes no matter where I move to. So I thought about it some more and it turns out, assuming a flat reflection plane, an infinitely distant object will only ever be viewed under one incident eye angle. The fresnel term (the amount of light reflected off the water surface, determined by the angle of incidence) will never change for the sun's reflection, nor for any other texel in the environment map. The diagram illustrates that the eye can be placed anywhere. The reflection angle R is always equal to the angle of incidence, I, and R has to be the same for the reflected vector to sample the same texel in the environment.


This means the fresnel falloff effect can be preprocessed on the environment map and baked directly into the texture. The resulting environment would remain bright at the horizon and get darker and darker towards the top and bottom. Aside from cutting precious shader instructions, this technique also allows us to take our high dynamic range environment map, bake the fresnel into it, and save it as a low dynamic range image without loss of quality! Because the benefits of HDR images are very noticeable when the images are modulated, fresnel falloff on the sky reflection really stands out in HDR. At greater angles of incidence the sky gets relatively dim but the sun remains blown out. When fresnel faloff is baked into the environment texture, there is no longer a need for any modulation, just a straight-up texture lookup will do. This means LDR will be as good as HDR.

Now, there are some minor drawbacks. When you give up true HDR you give up hopes of doing post processing effects like exposure, etc. It's also going to be difficult integrating the fresnel-baked skybox with reflections of the rest of the world, which is why we are only going to implement this algorithm in the environment-reflection-only render path. Also, the algorithm makes the assumption that the reflecting surface is a flat plane. It does not hold true for normal-mapped water because different surface normals combined with different eye positions can lead to the same texel being looked up.


However in practice (I'm hoping as we haven't actually tried this) the difference should be negligible. The overall effect is still there. Objects close to the horizon reflect more than those directly above the viewer and localized bumps in the normal-map will also appear to have fresnel falloff, it just won't be as accurate as it could be.

In other HDR news, the Lost Coast Half Life 2 level finally came out. It's a small technology demo for HDR support in the Source engine, complete with commentary from artists and programmers at Valve. The commentary is pretty cool, though they make it seem as if they invented ... any of the HDR stuff in the demo. The visual quality is quite impressive though, the weapons and water look a lot better. Even their use of bloom, also known as the chlorine-in-the-eyes effect, is relatively tasteful. One artifact that became very apparent was the transition between reflection maps on the guns. It just snaps from one cubemap to the next and can be quite distracting at times. We had talked about this too, as we will have to transition between both diffuse and specular irradiance maps when walking into, say, a densely wooded area.

I also liked their use of dynamic tone mapping (retinal response, dynamic exposure, whatever you want to call it). It was more subtle than other demos I've seen and did not look like someone was dimming the lights randomly. It was still a little touchy. There were times where it looked like the sun was being periodically blocked by clouds rather than exposure adjustment but it was unobtrusive. I would have liked to see it change through a wider exposure range and take longer to adjust though. It was also interesting how they weighed the brightness of pixels towards the center more heavily than those around the outside of the screen. I wonder if the exposure fluctuated too randomly otherwise. Anyway, props to Valve for talking about technical and game design decisions openly, and in a neat format too.

1 Comments:

Anonymous Anonymous said...

i'm wondering if additional texture lookups are cheapier than realtime fresnel calculations

9:05 AM  

Post a Comment

<< Home