Currently three demos are available for download with source code:

 

Light Propagation Volumes

 

Spherical harmonic lighting

 

Sky Rendering

 

 

 

 

 

spherical harmonic lighting

 October 2009

 

this program demonstrates spherical harmonic lighting (SH lighting) calculated per pixel on the GPU.

please refer to Robin Green's "Spherical Harmonic Lighting: The Gritty Details" for more details about spherical harmonics.

normally you would calculate SH coefficients per vertex on the CPU.

I decided to move some calculations to the GPU to speed it up.



description of the steps to calculate the shadowed diffuse transfer function SH coefficients of each pixel in a scene using a GPU:

(the demo takes advantage of the ability of GPUs to process data very fast using rasterization)

1. precompute the SH basis function values using jittered sh samples on a sphere. in my case I will generate 2025 sh samples

2. each sh sample (from previous step) will be applied to each pixel using rasterization:

first render pass:

select next sh sample and perform a parallel projection of the scene along the direction of the current sh sample and store the depth (most distant depth layer)

in a depth map, this depth map will be used in the next render pass to make a visibility test

second render pass:

if this render pass is called for the first time then render the scene into geometry buffers (vertices and normals)

draw a full screen quad sampling the geometry buffers and check for each sample if it is occluded by another object along the direction of the current sh sample

by sampling the depth map, if it is occluded then discard the sample otherwise output the contribution to the light transfer function SH coefficients,

alpha blending is enabled to add the contribution to the light transfer function SH coefficients

my pixel shader outputs 16 sh coefficients for each pixel using 4 render targets (each one has four channels)

if not last sh sample continue



it will take some seconds or minutes (depending on your GPU and complexity of the scene) to process the steps described above

once the sh coefficients have been calculated the scene can be rendered in real time by sampling the sh coefficients of each pixel and calculating

the dot product with sh coefficients of a light source

the program shows this by using different light directions.

 

since this demo has been written in Python you must install Python, PyOpenGL, numpy and PIL to run it you also need a GPU with OpenGL 2.0 support

the demo is platform independent. I used Windows XP and an NVIDIA Quadro NVS 160M with Forceware 6.14.11.7968 (3-11-2009)

 

Installation guide for Windows:  

Step 1:

Download Python 2.5

http://www.python.org/download/

and install

Step 2:

Download “PyOpenGL-3.0.0b1-py2.5.egg” or higher from http://pyopengl.sourceforge.net/ or download it from my site      

Step 3:

Before installing the PyOpenGL package you need to install the setuptools (easy_install) from http://pypi.python.org/pypi/setuptools/0.6c8 or download it from my site

Step 4:

Execute easy_install from the command line to install the PyOpenGL package. Make sure that Python and easy_install are added to the PATH environment variable (on Windows: c:\Python25\;c:\Python25\Scripts\)

call easy_install:

easy_install PyOpenGL-3.0.0b1-py2.5.egg

Step 5:

Download numpy from

http://numpy.scipy.org/

and install

Step 6:

Download PIL from

http://www.pythonware.com/products/pil/

and install

Step 7:

download GLUT and GLU and copy the glut32.dll and glu32.dll to your system folder

Running the demo:

download the python scripts from the download section below and unzip to any folder. Then execute the batch file "launch.bat" from the folder where you copied

the demo files.



Downloads

source code

Movie (IrfanView Slideshow)



Screenshots 





-----------------------------------------------------------------------------------------

Sky Rendering

December 2008



This demo uses the method proposed by Nishita in his specification 'Display of The Earth Taking into Account Atmospheric Scattering' to determine the color of the sky. Sky color in this demo depends on sun direction, viewer position and view direction.

The demo uses the GPU for most of its calculations. Nishita's specification can be downloaded from the internet, search for the file 'sig93_nis.pdf'.

The procedure:

Two lookup tables get created to speed up the integration of Rayleigh and Mie inscattering in a pixel shader.

To precalculate the lookup tables an atmosphere is used which is devided into multiple spherical-shells. Each spherical-shell is assigned an altitude and density ratio. The most outer spherical-shell is the top of the atmosphere.

Since the earth in this demo is assumed to be a sphere one can precalculate for each spherical-shell optical depths by defining a number of rays i.e. the first of these rays points to the center of the earth.

The other rays get created by rotating the first ray until reaching the last ray which is the ray rotated by 180 degrees.

For each ray one can calculate the optical depth by finding the intersection points of the given ray with all spherical-shells and integrating densities assigned to the intersected spherical-shells. This way the optical depth

along each ray will be precalculated. The lookup tables are two dimensional matrices. Each column contains precalculated optical depths for a given view direction (ray).

Two lookup tables are being used, one to determine optical depths from arbitrary view directions and one to determine the optical depths between the sun and arbitrary points on spherical-shells.

The precalculated lookup tables get copied into textures to make them accessable to shaders which calculate the color of the sky.

The pixel shaders determine from clip space positions view rays in world space (a full screen quad gets drawn) then they calculate at each intersection with spherical-shells along that rays the amount of inscattered light and sum them up.

To run the demo you must install Python, PyOpenGL, numpy and PIL you also need a GPU with OpenGL 2.0 support.

The demo is platform independent I used Windows XP and an NVIDIA Quadro NVS 160M with Forceware 6.14.11.7968 (3-11-2009)

Once the demo has been started it will slowly change the altitude of the sun (you will see the sun sinking) and thus altering the direction of the sun and updating the sky color by passing current sun direction, viewer position and direction to the shaders. Finally you will see how the horizon becomes reddish when the sun will be very low.

Installation guide for Windows:

Step 1:

Download Python 2.5

http://www.python.org/download/

and install

Step 2:

Download “PyOpenGL-3.0.0b1-py2.5.egg” or higher from http://pyopengl.sourceforge.net/ or download it from my site

Step 3:

Before installing the PyOpenGL package you need to install the setuptools (easy_install) from http://pypi.python.org/pypi/setuptools/0.6c8 or download it from my site

Step 4:

Execute easy_install from the command line to install the PyOpenGL package. Make sure that Python and easy_install are added to the PATH environment variable (on Windows: c:\Python25\;c:\Python25\Scripts\)

call easy_install:

easy_install PyOpenGL-3.0.0b1-py2.5.egg

Step 5:

Download numpy from

http://numpy.scipy.org/

and install

Step 6:

Download PIL from

http://www.pythonware.com/products/pil/

and install

Step 7:

download GLUT and GLU and copy the glut32.dll and glu32.dll to your system folder

Running the demo:

download the python scripts from the download section below and unzip to any folder. Then execute the batch file "launch.bat" from the folder where you copied

the demo files. First an intro will be shown which takes 15 seconds. Then the demo will run for three minutes showing how the sky color changes as the sun goes down.



Downloads

sourcecode and media

movie (sunset) IrfanView Slideshow



Screenshots