title: shadow mapping - transforming a view space position to the shadow map space
body: <p>I use deferred rendering and I store a fragment position in the camera view space. When I perform a shadow calculation I need to transform a camera view space to the shadow map space. I build a shadow matrix this way:</p>
  
  <pre><code>shadowMatrix  = shadowBiasMatrix * lightProjectionMatrix * lightViewMatrix * inverseCameraViewMatrix;
  </code></pre>
  
  <p>shadowBiasMatrix shifts values from [-1,1] to [0,1] range.
  lightProjectionMatrix that's orthographic projection matrix for a directional light. lightViewMatrix looks at the frustum center and contains a light direction.
  inverseCameraViewMatrix transforms a fragment position from a camera view space to the world space. </p>
  
  <p>I wonder if it is correct to multiply the inverse camera view matrix with the other matrices ? Maybe I should use the inverse camera view matrix separately ?</p>
  
  <p>First scenario:</p>
  
  <pre><code>vec4 shadowCoord = shadowMatrix * vec4(cameraViewSpacePosition, 1.0);
  </code></pre>
  
  <p>Second scenario, a inverse camera view matrix is use separately:</p>
  
  <pre><code>vec4 worldSpacePosition = inverseCameraViewSpaceMatrix * vec4(cameraViewSpacePosition, 1.0);
  vec4 shadowCoord = shadowMatrix * worldSpacePosition;
  </code></pre>