ShadowMapping using shader Issues

BlitzMax Forums/OpenGL Module/ShadowMapping using shader Issues

KronosUK(Posted 2011) [#1]
I am trying to replicate the code from this page
http://fabiensanglard.net/shadowmapping/index.php
in Blitzmax.

Edit: Working now:). Self-Shadows on the spheres looks a bit ugly though. Need to figure out how to stop this.

Press M to hide shadowmap and arrow keys to move camera

Main code.


Last edited 2011


TWH(Posted 2011) [#2]
If I remove the following line in shadowmap_frag.txt
	shadowCoordinateWdivide.z += 0.0005;


And add the following in the renderScene-method when doing the first pass (front faces, render to z/depth-buffer only )
	offsetFactor = 1;
	offsetUnits = 2;
        ' http://www.opengl.org/sdk/docs/man/xhtml/glPolygonOffset.xml
	glPolygonOffset(offsetFactor, offsetUnits);
	glEnable(GL_POLYGON_OFFSET_FILL);
	drawObjects(True) ;
	glDisable(GL_POLYGON_OFFSET_FILL);


Self-shadowing goes away.

Edit: added simple point-light code to the shader... Shadows are still ugly when the light is at extreme angles compared to the geometry:


How can you improve the image quality? Use two lights slightly apart?

Edit2: I'm told that some kind of filtering VSM or PCF could help...

Last edited 2011

Last edited 2011


KronosUK(Posted 2011) [#3]
How would one go about applying this into a game with a moving camera? Any thoughts?

Last edited 2011


col(Posted 2011) [#4]
Hiya, the
shadowCoordinateWdivide.z += 0.0005;


is a depth offset when reading from the depth map to help stop the self shadowing z fighting when the light is facing towards the polygons. Have you tried adjusting it to a bigger value? The bigger the value the more offset you will get until the point there is actually a gap between the shadow caster and the shadow itself.

The artifacts on the right hand pic are quite normal for shadow mapping when the polygon and light are almost or at parallel to each other. Its simply an error because of the depth precision. Have you tried a 32 bit 1 channel depth buffer?, it may or may not help, and yes some kind of filtering to ultimately blur the precision may help.

This post may help explain (in)accuracies with using different types of texture formats for precision for the depth buffer :-
http://mynameismjp.wordpress.com/2010/03/22/attack-of-the-depth-buffer/

EDIT - This could help too:-
http://www.gamedev.net/blog/73/entry-2006307-tip-of-the-day-logarithmic-zbuffer-artifacts-fix/

I don't use OpenGL, but shadow mapping is shadow mapping :D

EDIT2 - If you look at the depth buffer generated before and after those modifications by TWH you can the difference in shading ( representing depth ) around the spheres edges as opposed to a flat sphere.

Last edited 2011


AdamRedwoods(Posted 2011) [#5]
Self-shadowing errors:
http://takinginitiative.net/2011/05/25/directx10-tutorial-10-shadow-mapping-part-2/

For reference:

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch08.html

http://msdn.microsoft.com/en-us/library/windows/desktop/ee416324%28v=vs.85%29.aspx


I'll be tackling shadows soon.