title: glsl sampler2DShadow and shadow2D clarification
body: <p>Quick background of where I'm at (to make sure we're on the same page, and sanity check if I'm missing/assuming something stupid):</p>
  
  <ul>
  <li>Goal: I want to render my scene with shadows, using deferred lighting
  and shadowmaps.</li>
  <li>Struggle: finding clear and consistent documentation regarding how to use shadow2D and sampler2DShadow.</li>
  </ul>
  
  <p>Here's what I'm currently doing:</p>
  
  <p>In the fragment shader of my final rendering pass (the one that actually calculates final frag values), I have the MVP matrices from the pass from the light's point of view, the depth texture from said pass (aka the "shadow map"), and the position/normal/color textures from my geometry buffer.</p>
  
  <p>From what I understand, I need to find what UV of the shadow map the position of the current fragment corresponds to. I do that by the following:</p>
  
  <pre><code>//Bring position value at fragment (in world space) to screen space from lights POV
  vec4 UVinShadowMap = (lightProjMat * lightViewMat * vec4(texture(pos_tex, UV).xyz,1.0)).xy; 
  //Convert screen space to 'texture space' (from -1to1 to 0to1)
  UVinShadowMap = (UVinShadowMap+1)/2;
  </code></pre>
  
  <p>Now that I have this UV, I can get the percieved 'depth' from the light's pov with</p>
  
  <pre><code>float depFromLightPOV = texture2D(shadowMap, UVinShadowMap).r;
  </code></pre>
  
  <p>and compare that against the distance between the position at the current fragment and the light:</p>
  
  <pre><code>float actualDistance = distance(texture2D(pos_tex, UV).xyz, lightPos);
  </code></pre>
  
  <p>The problem comes from that 'depth' is stored in values 0-1, and actual distance is in world coordinates. I've tried to do that conversion manually, but couldn't get it to work. And in searching online, it looks like the way I SHOULD be doing this is with a sampler2DShadow...</p>
  
  <hr>
  
  <p><strong>So here's my question(s):</strong></p>
  
  <p>What changes do I need to make to instead use shadow2D? What does shadow2D even do? Is it just more-or-less an auto-conversion-from-depth-to-world texture? Can I use the same depth texture? Or do I need to render the depth texture a different way? What do I pass in to shadow2D? The world-space position of the fragment I want to check? Or the same UV as before?</p>
  
  <p>If all these questions can be answered in a simple documentation page, I'd love if someone could just post that. But I swear I've been searching for hours and can't find anything that simply says what the heck is going on with shadow2D!</p>
  
  <p>Thanks!</p>