Since there are a lot of cool screenshots flying around, here’s an update on Marathon’s very slow progress.
Three new features last week:
-
HDR rendering. Very easy to implement (with GLSL + EXT_fbo), but difficult to setup right. It’s the same problem FarCry had, once you’ve built something that assumes LDR rendering (e.g. lighting & material parameters), when you switch to HDR you just can’t expect a much better quality (actually it looked worse in most cases). So, we’re now in a process to modify how our materials are defined, how the sun light behaves in different conditions, etc. The first step will probably be adding a float “intensity” setting along each 24bit color (so that everything will look ok both with and without HDR rendering).
-
Bloom. Super cool!
Works with and without HDR, but obviously looks much better when you’re dealing with fp values. -
My favorite, gamma correction. When I started reading about HDR, it occured to me that I’ve never thought about gamma before. So, I started reading about that too.
a. You’re forced to do it when doing HDR (the 24bit colors are in 2.2 gamma space, but all the calculations are done in 1.0 linear space and then there’s tone mapping at the end, that brings it back to an appropriate space for viewing), else everything looks washed-out.
b. It is actually necessary without HDR too. If you multiply a 2.2 value with a 1.0 value in the shader (e.g. a modulation) it works, but when you’re adding it fails (e.g. 64 + 64 = 88, instead of a 128 final value :o). This affects anything involving an addition (specular addition, fog blending, etc). Of course, I couldn’t believe that all this time I was watching a wrong image, but when I tried it the difference was amazing! Before, the specular highlights were picking hues from the surface color, but now are crystal clear. Fog looks more natural too, before it was “blending” with the background colors. The only problem is how to do it in the register combiners path. I obviously can’t raise to a 2.2 power (but a power of 2.0 is a simple multiplication, very good compromise), I’m not sure if the internal precision will be good enough and I still have to do a final fragment shader pass to do the sqrt. We’ll see.
c. Gamma-correct mipmap creation!!! That made a huge difference with most textures! Before, I was using Java’s built-in scaling for rgba values and a custom filter for normal maps. But, guess what, you’re adding values in the process! So, the proper way to do it is this (for RGB colors): Degamma the image and save the result in floating point precision, do the filtering and downscaling in fp precision, re-gamma and convert each LOD back to 24bits. Here’s the difference:
Photoshop’s filtering:
http://www.zdimensions.gr/spasi/public/050614/GammaWrong.gif
Marathon’s filtering:
http://www.zdimensions.gr/spasi/public/050614/GammaCorrect.gif
The original image contains black and white stripes (0 & 255). Photoshop is creating a, seemingly correct, 128 value. But that’s not what the eye sees as half the intensity of black + white, but something much darker. The proper value is 186, which is produced if you do the gamma correction.
The coolest thing though is how I actually implemented the above. When I was deciding how to do it, I thought it was too much for a 100% Java implementation and it would slowdown the process (especially, since I had to do my own fp filtering now, without Java2D’s very good implementation). So, I hacked the Marathon Engine to start without a window (just a pbuffer to get a GL context) and used GLSL, fp textures and EXT_fbo for off-screen rendering! A few hours later, after working around some of EXT_fbo’s currect bugs/limitations and learning how cubic filtering works, it was ready. We now have an almost instantaneous, gamma-correct, mipmap creation process! 8) And since it is so fast, I also ported the simpler normal map mipmap creation and I plan to do the height-map => normal-map conversion, add more texture types/targets, etc. Very helpful.
Here’s two HDR screenshots:
Without soft shadows
http://www.zdimensions.gr/spasi/public/050614/shadows_1.jpg
With soft shadows
http://www.zdimensions.gr/spasi/public/050614/shadows_2.jpg
Back to my boring, non-Marathon related, work now…
