Jump to content

  • Log In with Google      Sign In   
  • Create Account

Shadowmapping in Camera-Space


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 yonarw   Members   -  Reputation: 109

Like
0Likes
Like

Posted 20 November 2012 - 02:58 PM

Hello,
while continuing my work on my deferred shader engine I descided to implement a shadowmapping feature.

Here is the process i do for each light that casts shadows:
1. render the scene from light point of view to create depth-shadowmap
2. store modelview and projection matrix
3. draw light to lightmap using g-buffer and shadowmap
3.1 build transformation matrix that goes from cameraspace to light-view-clipping space by using this matrix:
transformation-matrix = light_projection_matrix * light_modelview_matrix * camera_modelview_matrix_inverse
3.2 In the shader: read fragment position from gbuffer, calculate shadowmap_texture_coordinate with:
shadowmap_texture_coordinate = transformation-matrix * gbuffer_pos
3.3 do the is-in-shadow check stuff

I have several problems:
1. The shadowmap_texture_coordinate does not seem to have an orthographic projection. I fixed this by applying this to the shadowmap_texture_coordinate (sc):
sc.xy = sc.xy / sc.z
This is not correct in any way I think but I have no idea what else could cause the projection-bug.

2. When I read from the shadowmap I get values in [0,1]. How do I transform these to compare them with the distance of a fragment from the light-position since those are given in engine-units.

I hope someone will understand what I am doing Posted Image sometimes I'm not sure my self Posted Image

Sponsor:

#2 Lauris Kaplinski   Members   -  Reputation: 841

Like
0Likes
Like

Posted 20 November 2012 - 11:56 PM

When calculating shadowmap coordinates you have to exactly replicate the "light-camera" transformation.
In your case you have to perform perspective division:

Shadow.xyz = shadow.xyz / shadow.w

Then you have to do the viewport transformation to get proper texture coordinates and depth value:

Shadow.xyz = vec3 (0.5, 0.5, 0.5) + 0.5 * shadow.xyz

Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

#3 yonarw   Members   -  Reputation: 109

Like
0Likes
Like

Posted 21 November 2012 - 04:35 AM

Wow thanks that worked!
Now one step further: Is there a more efficient way of rendering a cubemap than rendering all 6 directions seperately ? I found something that uses a geometry shader to render to all 6 faces of the cube at one time but that looks to complicated for me.

#4 larspensjo   Members   -  Reputation: 1557

Like
0Likes
Like

Posted 21 November 2012 - 02:53 PM

It is possible to use a spherical mapping. That is, drawing only once, but map the sphere onto a quadratic texture. The advantage is that you only need to do one drawing. The advantage is that you don't get the same resolution in the shadow map everywhere. It will have lowest resolution at the equator, and a singularity at the poles. This may be acceptable, depending on your requirements. Search for "spherical shadowmaps" and you will find a lot.

See also for an illustration and idea how to improve on the singularities at the poles.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

#5 yonarw   Members   -  Reputation: 109

Like
0Likes
Like

Posted 21 November 2012 - 03:05 PM

ok, I guess I will be fine with my cube map for now ... with a little bit of optimization it will only draw visible objects for each side of the cube and I share one FBO for the shadow map. Thanks for your help!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS