Personal tools

Screen Space Dynamic Lighting

From PagodaWiki

Jump to: navigation, search

Quarter long project for Computer Graphics 2

Contents

Screen Space Ambient Occlusion

Demo In Crysis

First done by the game Crysis, this algorithm allows an ambient occlusion pass to be calculated in real time, solely on the GPU by means of a pixel/fragment shader. Ambient occlusion in a general sense attempts to account for the attenuation of light causes by the contours of surfaces occluding themselves and creating soft diffuse shadows. In its simplest form, SSAO is computed by comparing depth values of the screen depth buffer in order to see how much a surface is occluded by surrounding geometry


Screen Space Indirect Lighting

Real-time Dynamic Indirect Lighting [pdf]

Similar to photo mapping (global illumination) for inter-object reflections or the final gathering, which deal with diffuse color bleeding, SSIL uses ambient occlusion calculations to determine the locations of an object that will receive diffuse color from nearby objects.


Status

The first step is to perform SSAO. From this AO computation we can then approximate crude global illumination in a later step. I'm going to start really basic though, and try to get a GLSL shader to simply compile and maybe even do Phong shading.


Image:SSDL_GLSLPhongShader.jpg

Here you can see I've loaded in a model that I feel will demonstrate the effects of an AO pass well. I'll probably grab something even better for the final demo. I managed to get Phong shading to work using a vertex and (mostly) fragment shader.


Image:SSDL_FBOManglesLeopard.jpg

Although I have a lot of the math converted to code (and hopefully straight in my head), a good deal of the functionality comes from reading textures passed in from OpenGL. Currently I'm trying to get a depth and normal map passed in as a uniform sampler2D variable to the fragment shader using frame buffer objects. You can see the FBO works...kind of. It is sampling a chunk of my screen and applying it to the ground plane. However, it seems to be sampling portions of the screen not part of my application, as you can see from the mangled scraps of the OS X Leopard dock and Xcode next to those hairy fingers.


Image:SSDL_NormalMap.jpg

This is a normal map output by a shader in a render pass before SSAO is computed. The pipeline as of now is as follows:

  • Attach texture to RGB color component of the FBO
  • Bind FBO and use normal/depth map shader program
  • Draw world the first time (shader writes out normal values in rgb channel and depth values in alpha
  • Unbind the FBO (following calls will render to screen instead)
  • Use SSAO shader and pass normal/depth map texture in as uniform sampler2D
  • Calculate Phong with SSAO component


Banding artifacts that occur due to self occlusion. I was able to take care of banding on the ground plane by reflecting the sample vector around the surface normal if the dot product between the two was less than 0, but I am still receiving similar artifacts that warp and turn depending on the camera angle and distance.

Image:SSDL_handBanding.jpg

Image:SSDL_columnBanding.jpg


Raw ambient occlusion on the left and gaussian blur applied on the right. Graininess is due to random normal texture used to prevent noise. I need to mess with my convolution filter more to get a more useful blurring.

Image:SSDL_aoWithBlur.jpg


Intensity turned up so that effect is a bit exaggerated. You can see contact shadows form the fingers on the floor and diffuse color bleeding off of the walls onto the hand and floor.

Image:SSDL_contactShadowIndirectLighting.jpg

Midterm Status Report

Project Objectives

  • Learn about GLSL shaders
  • Learn about ambient occlusion, global illumination and final gather
  • Learn about real time approximations for the above techniques
  • Implement screen space ambient occlusion using the Horizon Split approach (almost)
  • Implement screen space indirect lighting

Revised Project Timeline

only a minor adjustment because of my multi-pass pipeline mixup and final presentations got moved sooner

1 week - setup the OpenGL scene with a fly camera and model, and get a basic GLSL shader running

1 week - implement Phong shader and setup multi-pass rendering pipeline with FBO to pass normal/depth map to SSAO shader

3 weeks - implement Horizon Split ambient occlusion in a pixel shader

1 week - integrate the shader into a nice looking scene for demonstration

[optional]1 week - extend my AO pass to support indirect lighting (should be able to get something at least)

Status Update

It turned out that there were a lot of additional smaller components that make the rendering pipeline work for SSDL. I have spent quite a bit of time toying around with those. First off, after I got a shader to compile and link in, I implemented Phong. After this worked, I realized that there were certain pieces of data that the fragment shader would need to know and could only really access were this data written to texture and passed in as a uniform sampler2D variable to the shader. This of course meant that I needed to implement a multi-pass rendering scheme. I rewrote my drawing method so that it would first draw the world into a frame buffer object with a shader attached that spit out normal and depth map information into the FBO's color component. Then, the world is redrawn with the SSDL shader attached, at which point it can read from the normal/depth texture which has been previously written. The SSDL shader itself, although showing good progress and having not only the skeleton but a lot of math transposed to shader code, does not show any results conducive to actual ambient occlusion.

Progress Assessment

I think that considering all I have learned so far and the fact that I have pushed through the obstacle of getting a multi-pass rendering pipeline to work, in addition to nearly having ambient occlusion working, I am doing pretty well and am on track. As for indirect lighting, I am not too worried as, if worse comes to worse, I can still get color bleeding results by sampling color values in a very unsophisticated way that will require little additional time from the base SSAO computation. I should be able to get something reasonably accurate in any case.


Project Proposal

Project Summary

Although real time ray tracing is beginning to look like a feasible solution in the future, it is not quite there in terms of performance on consumer machines. Due to this, there are many heuristic algorithms employed by game developers in order to fake the effects of the attenuation of light and its diffuse color bleeding in a global sense. Having been pioneered by the CryEngine 2 in Crysis, both screen space ambient occlusion and screen space indirect lighting were achieved in real time by using pixel shaders on the GPU in dynamically-light scenes. My project focuses on doing the same. I have condensed the term to Screen Space Dynamic Lighting (SSDL) for ease of use, and will attempt to write a pixel shader that is able to add an ambient occlusion pass to an OpenGL scene in real time, and from this AO pass, also derive the global contribution of indirect lighting per surface sample (per fragment) in order to achieve diffuse color bleeding.

Project Objectives

  • Learn about GLSL shaders
  • Learn about ambient occlusion, global illumination and final gather
  • Learn about real time approximations for the above techniques
  • Implement screen space ambient occlusion using the Horizon Split approach
  • Implement screen space indirect lighting

System and Software

  • Mac OS X 10.5 Leopard
  • Objective-C and Cocoa for user interface
  • C++ for primary programatic control
  • Autodesk Maya for exporting test scene models
  • OpenGL to render the scene in real time
  • GLSL (OpenGL shading language) to define fragment shader routines

Project Components

The GUI will be constructed using Objective-C and Cocoa. It will consist of a basic first person perspective fly camera view in which the user can navigate a 3D world using their mouse and keyboard. Menu items or a floating HUD window will provide users easy controls for switching on and off the SSDL and loading in different scenes. The project will be comprised of an OpenGL scene with various 3D objects that I feel best demonstrate the improvements made as a result of SSDL. I have quiet a few Maya models lying around, as well as a Maya binary file to vertex array exporter which I plan to use in order to bring these models into the scene. I plan to implement Phong illumination since the shortcomings of OpenGL's default may take away from the overall effect. As far as the actual SSDL is concerned, the approach that seems to make the most sense uses the Horizon Split ambient occlusion algorithm, which adds both a hemispheric and normal contribution to real time ambient occlusion calculations. After adding these terms together to get the final AO value, we cast multiple randomly generated rays from the sample point into the non-occluded space, transposing these vectors through the appropriate matrices, and figuring out where they intersect in the depth buffer in order to average indirect lighting contribution from the scene.

Project Timeline

1 week - setup the OpenGL scene with a fly camera and model, and get a basic GLSL shader running

3 weeks - implement Horizon Split ambient occlusion in a pixel shader

2 weeks - extend my AO pass to support indirect lighting

1 week - integrate the shader into a nice looking scene for demonstration

Final Presentation

I plan to simply use an overhead projector connected to my laptop to demo a few different scenes with and without SSDL. Each step of the process will be explained and shown before the final result.

References

Dimitrov, R, Bavoil, L, and Sainz, M. "Horizon-split Ambient Occlusion." ACM
     SIGGRAPH (2008): Article No. 5. ACP Portal. The ACM Digital
     Library, New York. March 2009. <http://portal.acm.org/citation.cfm?id=1357017>.

Mitchell, Kenny. "Screen-Space Occlusion Methods." GPU Gems 3.
     Ed. Hubert Nguyen. 3rd ed. Boston: Addison-Wesley Professional, 2008. 281-282.

Shanmugam, P. and Arikan, O. "Hardware Accelerated ambient occlusion techniques on
     GPUs." ACM SIGGRAPH (2007): 73-80. ACP Portal. The ACM Digital
     Library, New York. March 2009. <http://portal.acm.org/citation.cfm?id=1230100.1230113>.