Search code examples
openglopengl-esglslglsles

Approximate Indirect Diffuse


Im working on implementing indirect diffuse in my renderer and Im looking at section 8.4.1 of this paper from Valve.

In my renderer Im having a voxel grid of 256x256x256 with radiance and shadow injected and Im trying to convert/use this snippet from the paper to calculate ambient lighting against my voxels:

float3 AmbientLight( const float3 worldNormal )
{
  float3 nSquared = worldNormal * worldNormal;
  int3 isNegative = ( worldNormal < 0.0 );
  float3 linearColor;
  linearColor = nSquared.x * cAmbientCube[isNegative.x]   +
                nSquared.y * cAmbientCube[isNegative.y+2] +
                nSquared.z * cAmbientCube[isNegative.z+4];
  return linearColor;
}

The problem is that cannot figure out what is cAmbientCube in the calculation...

What is this variable and where it come from?


Solution

  • The 8.4.1 section of the paper, where you copied the code from, pretty much explains it. cAmbientCube is an array of six light values, one for each principal direction: negative x, positive x, negative y, positive y, negative z, positive z. Whereas typical ambient term is assumed to be a constant light that illuminates from all directions, the Ambient Cube technique described in the paper is a generalization of this which assumes a different light coming from each of those directions. The code you posted is responsible for sampling from this ad-hoc six-sided cube-map texture.