Friday, April 2, 2010

2010-04-01. Deferred shading

HDR shading improved

I spent a few days improving the conversion curve from HDR to LDR [see previous post]. I divided the screen into 5x5 sub-screens and rendered the same view with five different curve types and parameters. Then I dropped the worst looking curves, saved the best ones and "zoomed in" to fine-tune the parameters.

The HDR->LDR conversion system also includes a dynamically changing shutter time of the camera. It's not very visible in this homogenous lighting but it makes the scene look very beautiful in darkness too. Think of entering a dark tunnel... Yum!

Here's a shot with an abstract skeletal animated worm.

Deferred shading

When I uploaded the last video the frame rate was around 20 fps at resolution 1280x800 on my ATI Mobility HD 4650, which is around half speed of GeForce 8800 GT. Even though it's clear there was a bottleneck, most of the time was spent in constant time postprocessing effects. This is good because it means adding triangles won't make it slower.

I was able to remove many rendering steps by entering the world of deferred shading. This means I no longer render the objects straight, calculating the lighting as I go. Instead I save vertex normals, texture colors and material parameters of each pixel into textures, and then in another pass I calculate the lighting for each pixel based on these. This way I only need to calculate lighting for those pixels that are actually shown.

On top of this I took the edge detect shader (sobel) and combined it with the blur shader; they both need to be applied to make good edges. For those interested in details, I just combined the sobel kernel and the blur 1-2-1 kernel, resulting in a single rendering pass. I went even further and combined this blurred sobel shader with the HDR->LDR conversion shader into a single rendering pass. In the end I had FPS 35, which is a HUGE improvement. Yippee!


Next up is showing some terrain with adaptive tessellation. Without the fancy words it means the triangle mesh will be more accurate where needed, just like it should. And the terrain will be rendered in less accuracy when it's far away. Wish me luck.

1 comment: