- In the first pass, render the scene to the geometry buffers (see Using deferred shading for details).
- In the second pass, we'll use this fragment shader code to compute the AO factor. To do so, we first compute a matrix for converting the kernel points into camera space. When doing so, we use a vector from RandTex to rotate the kernel. This process is similar to computing the tangent space matrix in normal mapping. For more on this, see Using normal maps:
// Create the random tangent space matrixvec3 randDir = normalize( texture(RandTex, TexCoord.xy * randScale).xyz );vec3 n = normalize( texture(NormalTex, TexCoord).xyz );vec3 biTang = cross( n, randDir );// If n and randDir are parallel, n is in x-y planeif( length(biTang) ...