pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
demo shadows

demo shadows - 0.2

Alessio (alexius75)

Tags:

Description

source to use shadow map in pyOpenGL using extention.. a lot of people ask me something like this.. i hope it works :D you need pyOpengl, pygame, OpenGL.GL.ARB.shadow, OpenGL.GL.ARB.depth_texture and mat4 from cgtypes.. and the right hardware.. have fun...

Changes

added some hints to know what download to see that demo..

Links

Home Page: http://digilander.libero.it/alexius75/
Source: http://digilander.libero.it/alexius75/DEMOshadows.rar

Screenshot


click to view original size

Releases

demo shadows - 0.2 - Dec 17, 2007
demo shadows - 0.1 - Dec 4, 2007

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

August 16, 2009 10:58pm - Ian Mallett - nickname: (geometrian)
René, my OpenGL library provides faculty for easily making OpenGL effects. The new version, available soon, uses shaders and is much better. The secret to increasing resolution is to increase the size of the framebuffer; i.e., FBOs or larger window. One pass shadowmapping is too tricky to be worthwhile. As for your method, try caching the display list the first time. I.e.: build dl, then in the main: draw from light, draw from camera.
April 25, 2008 11:34am - jan jordan - nickname: (logotomie)
Hi tried it and it works. i am always astonished how well this works in python by now. 2 things though:
Somebody wondered why he was not able to increase shadow map resolution. Thats because shadow map is rendered into the regular framebuffer which is only 800x600. For higher res you would need to render in an offscreen buffer

Its hard to extend the code for multiple shadow casting lights, i prefer rendering the first pass with ambient only and the second pass with diffuse and specular using additive blending and setting the shadow comparion for true outside shadow (GL_LESS)
March 13, 2008 7:14pm - Rene Dudfield - nickname: (illume)
Hello,

I found some things to improve the quality of the shadow mapping, and
written in more comments.

http://rene.f0o.com/~rene/stuff/shadows_rd.zip


It also by default uses a polygon as a floor, and a teapot from GLUT.
There's a constant at the top of demoShadows.py which changes this.
However the objects you draw are a very simple part of this demo, they
could be anything really. The complexity comes from the other code.

I haven't managed to increase the resolution of the shadow map successfully.

I think maybe the glPolygonOffset call may have something to do with
it... but haven't managed to get the call to do anything. I tried
glScale, and glTranslate, but that seems to be wrong - and in one
paper it says you can't use translate/scale but have to use
glPolygonOffset.


The main thing which improved quality for me was to use
GL_DEPTH_COMPONENT32 instead of GL_DEPTH_COMPONENT with the
glTexImage2D call. GL_DEPTH_COMPONENT lets the driver pick the
resolution (which for this Imac as only 8 bit).

Apparently it's possible to do shadow mapping in one pass... but it's
more complicated.

However I think using display lists will be quite quick even though
it's done in 3 passes.

eg.
# 1. draw stuff first time, and create display list at the same time.
# 2. second pass reusing display list.
# 3. third pass reusing display list.


Another improvement would be to anti-alias the shadows some how.
There's a whole bunch of different methods for doing this mentioned in
the literature, but I haven't tried anything yet.
March 12, 2008 1:13am - Rene Dudfield - nickname: (illume)
I had to change the glAlphaFunc to use GL_LESS... which I think is because of float inaccuracies.

#Set alpha test to discard false comparisons
#glAlphaFunc(GL_EQUAL, 1.0)
glAlphaFunc(GL_LESS, 1.0)

Any ideas on how to make the shadows softer? Either by making the shadow map a higher resolution or some other algorithm?
February 18, 2008 9:27am - Ian Mallett - nickname: (geometrian)
Here's the same tutorial with no dependencies other than Pygame and PyOpenGL:
http://napalm.sf.cz/tmp/shadows.zip
February 15, 2008 11:49pm - Ian Mallett - nickname: (geometrian)
Where can I get vec4?
January 8, 2008 3:20pm - Ian Mallett - nickname: (geometrian)
I found cgkit, which includes cgtypes, so:
from cgkit import cgtypes
Then mat4 function says something about mat4 vs. mat4(). I'm not at home, maybe I can be more specific later.
December 28, 2007 3:03am - muntygames - nickname: (muntygames)
note to those who are having problems running this demo. if your like me, using the new ctypes based pyopengl, and python2.5, the demo will crash. you must make some minor changes to the code to cast a few variables to int and tuple because the new pyopengl is very picky about what can be passed to its functions.
in cameraLoop, line 74, cast the window sizes to int
in RenderShadowCompareBefore, cast all rows to tuples
December 5, 2007 5:11pm - pymike - nickname: (pymike)
I found a really good free program called "WinImp" that extracts just about anything I want. Microsoft recommends it too.
December 5, 2007 11:24am - pymike - nickname: (pymike)
Argh...I guess I just need the latest version of PyOpenGL. I put in the shadows and the depth_textures modules in and they needed a bunch of other pyopengl modules. I'll just wait for a windows binary py25 release. Btw, did you use this code for your Eva Demo game?
December 5, 2007 10:57am - Alessio - nickname: (alexius75)
you need OpenGL.GL.ARB.shadow, OpenGL.GL.ARB.depth_texture and mat4 from cgtypes.
you can find these modules using google. good luck :)
December 5, 2007 10:06am - pymike - nickname: (pymike)
Okay I uninstalled that program and I restarted the computer from task manager. Everything seems to be okay now. Okay, I can't run your game! I have OpenGL 2.0.2.01 and Numeric 24.2, Python 2.5 and a coupple other things. What do I need?
December 5, 2007 9:56am - pymike - nickname: (pymike)
My computer is acting really weird and I can't restart it or log off.
December 5, 2007 9:41am - pymike - nickname: (pymike)
Something weird happened to my folders when I installed it. Now the details bar at the left of the folder is gone. Do you know how to fix it?
December 5, 2007 2:23am - Paul Davey - nickname: (technomancer)
go get this really useful program called 7zip then you can decompress almost anything!!
December 4, 2007 2:29pm - pymike - nickname: (pymike) - 4/5
Looks nice. Unfortunately I can't decompress .rar files so can you release a zip download?
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Oct 28, 2014

Oct 21, 2014

Oct 20, 2014

Oct 16, 2014

Oct 9, 2014

Oct 8, 2014

Oct 7, 2014

Oct 4, 2014

Oct 1, 2014

Sep 19, 2014

Sep 17, 2014

Sep 9, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)