Shadow mapping: project world-space pixel to light-space


I'm writing shadow mapping in deferred shading.

Here is my depth map for directional light (orthogonal projection):

<a href="https://i.imgur.com/PSVGuRq.png" rel="nofollow"><img alt="depth map" class="b-lazy" data-src="https://i.imgur.com/PSVGuRq.png" data-original="https://i.imgur.com/PSVGuRq.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Below is my full-screen quad shader to render pixel's depth in light view space:

#version 330 in vec2 texCoord; out vec3 fragColor; uniform mat4 lightViewProjMat; // lightView * lightProj uniform sampler2D sceneTexture; uniform sampler2D shadowMapTexture; uniform sampler2D scenePosTexture; void main() { vec4 fragPos = texture(scenePosTexture, texCoord); vec4 fragPosLightSpace = lightViewProjMat * fragPos; vec3 coord = fragPosLightSpace.xyz / fragPosLightSpace.w; coord = coord * 0.5 + 0.5; float lightViewDepth = texture(shadowMapTexture, coord.xy).x; fragColor = vec3(lightViewDepth); }

Render size is 1280x720, depth map's size is 512x512 and look like it is repeating the depth map in my scene. I think my projection for coord isn't right. I want to see if the depth from pixel to light is correct. Could someone give me some suggestions?


Solved myself, the problem is depth saving. I saved wrong depth value, should have used gl_FragCoord.z instead.


  • OpenGL Reflection shader showing only grey
  • Draw 2 cubes in OpenGL using GLM
  • OpenGL ES 3.0 matrix array only using first matrix
  • Return Type as a result of Term or Value calculation
  • c++/OpenGL/GLSL, textures with “random” artifacts
  • OpenGL shaders questions
  • OpenGL ES 2.0 Shader on Texture not working
  • C++ Conditional Templates Compilation based on data type
  • Calculate Normals Geometry Shader
  • WebGL heightmap using vertex shader, using 32 bits instead of 8 bits
  • Position a body in cannon.js relative to local rotation
  • glLinkProgram crashes even though glCompileShader does not return any error
  • GLSL : accessing framebuffer to get RGB and change it
  • Windows-specific issue when rendering WebGL… attribute set to zero?
  • How to avoid patterns when making random perlin noise
  • How to translate the projected object in screen in opengl
  • in/out variables among shaders in a Pipeline Program
  • Taking logcat and kernel logs simultaneously
  • How to blur image using glsl shader without squares?
  • How to define a static const variable of a template class
  • How to save a large fractal image with the least possible memory footprint?
  • OpenCV OpenNI calibrate kinect
  • Undefined navigator.push React-native 0.43.4
  • redirect_to root_url and return unless @user.activated
  • Django model inheritance, filtering models
  • Django invalid literal for int() with base 10
  • Converting a WriteableBitmap image ToArray in UWP
  • How to define and use opencv mat of user type
  • Splitting given String into two variables - php
  • Modifying destination and filename of gulp-svg-sprite
  • Deserializing XML into class C#
  • 0x202A in filename: Why?
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to include full .NET prerequisite for Wix Burn installer
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • How does Linux kernel interrupt the application?
  • costura.fody for a dll that references another dll
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?