Pages

Sunday, May 16, 2010

Ambient Lighting Using Irradiance Environment Maps

Back when i was developing MageDx Tech Demo I & II, i had implemented the scene's ambient lighting using a precomputed diffuse convoluted environment map generated from a static HDR skybox. This solution worked fine until i have added dynamic sky to the engine. The precomputed diffuse convoluted environment map in this case is no longer valid for the scene because of the dynamic nature of the new sky lighting. As a simple temporary workaround, i have used a constant grey color to represent the ambient lighting for the entire scene.

Over the weekend, i had some free time to spare so i thought it would be a good time to revisit this problem and implement a solution for it. After thinking through some potential solutions, i ended up implementing a slimmed-down version of a rendering technique known as Irradiance Volumes.

In my implementation, instead of generating a grid of irradiance samples over the entire scene as described in the paper, i have just one sample measuring the irradiance from only the dynamic sky. This sample is updated whenever the sun moves beyond a certain threshold. Objects in the scene then samples from this irradiance sample using their world normal to get the ambient lighting contribution from the sky. Below is a screenshot showing the same scene in different ambient lighting conditions.


Ambient lighting in the scene under different sky lighting conditions

Because the irradiance sample is sampled using the world normal of an object (or in this case the per-pixel normal from a normalmap transformed to world space), the bumpy details of normal mapping are retained for objects in shadowed areas.


A constant grey color is used to represent the ambient lighting for the scene, objects in the shadows looks flat and dull


The same scene with objects sampling from the irradiance sample for ambient lighting. Notice how the details of normal mapping is still visible in shadowed areas

Although my implementation is not a full accurate ambient solution, it works well enough for the small outdoor scenes that i have been using so far. Perhaps in the future i might revisit and improve on this solution when i start having more complicated scenes.

Thursday, May 6, 2010

PhysX Cloth Physics


A screenshot of PhysX cloth simulation in MageDx

Cloth physics belongs to one of those features that i have been wanting to implement after seeing how they operate in games such as Mirror's Edge and Batman Arkham Asylum. So after spending a few hours coding after work for about a week or two, i finally managed to integrate cloth into MageDx using PhysX. In addition to traditional cloth simulation, i have also incorporated softbody and metal deformations, both using PhysX cloth as well. As usual i have uploaded a video showcasing cloth simulation in MageDx which you can find below. Note that the low framerate in the video was caused by FRAPS video capturing while running the tech demo and under normal circumstances the framerate is a steady >60 FPS. Anyway, enjoy the video!