2
\$\begingroup\$

I'm looking into material translucency and I'm working through some GPU Gems documentation (http://http.developer.nvidia.com/GPUGems/gpugems_ch16.html).

In Example 16-4 it references matrices for both light space and light texture space.

   // Given a point in object space, lookup into depth textures    
   // returns depth

   float trace(float3 P,
            uniform float4x4  lightTexMatrix, // to light texture space                
            uniform float4x4  lightMatrix,    // to light space
            uniform sampler2D lightDepthTex)
{
  // transform point into light texture space      
   float4 texCoord = mul(lightTexMatrix, float4(P, 1.0));

  // get distance from light at entry point      
   float d_i = tex2Dproj(lightDepthTex, texCoord.xyw);

  // transform position to light space      
   float4 Plight = mul(lightMatrix, float4(P, 1.0));

  // distance of this pixel from light (exit)      
   float d_o = length(Plight);

  // calculate depth      
   float s = d_o - d_i;

  return s;
}

Can anyone explain to me what light texture space iS and how exactly I'd calculate a matrix for it? I think I'm OK getting the light matrix and it's projection matrix but a 4x4 light texture space matrix is blowing my mind.

I can't find anything else that specifically references those terms, but I'm well aware that terminology for shaders changes depending on who you speak to. They may well be better known as something else, though I'd hope Nvidia would be using well recognised terminology.

\$\endgroup\$
2
\$\begingroup\$

From quickly perusing the article, it sounds like the texture they're talking about is simply a shadow map for the light, although it stores linear world-space distance in a color channel rather than using the nonlinear post-projective depth. In any case, lightTexMatrix here is the same matrix you'd use for calculating the position to sample a shadow map—namely, it transforms the point to light space, then applies the shadow map projection matrix, then remaps the result from the [-1, 1] of NDC to the [0, 1] of texture coordinates.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Ok thanks, I'll have a look at that. I'm actually having problems with something else in the shader at the moment preventing it from compiling so I can't check it at the moment before I get that sorted. But from what I gather you mean something like: ` float4 point = mul( LightMatrix, input.position ); float4 texCoord = mul( LightProjectionMatrix, point ); float d_i = Linear01Depth( tex2Dproj( texCoord.xyw ).r );` \$\endgroup\$ – Dave Jan 11 '14 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.