PyOpenGL Shadows

Started by
11 comments, last by Geometrian 16 years, 1 month ago
Hello. I've been trying for about 4 months to make shadows--any kind of shadows in PyOpenGL. I'm using Python and PyOpenGL and Python 2.5.1. In the course of my study, I've downloaded about 50 different demos and looked at about 100 different tutorials and have had no success whatsoever. I know it can be done, and I know my computer supports it, but I cannot get the code working, and so I can't reverse engineer them. I believe most of the problems lie in the dependencies. Some tutorials require outdated versions of OpenGL or libraries which I cannot find anywhere. I'm really sad and frustrated that after having come so far in OpenGL and programming, I have run into this obstacle which I seemingly cannot surpass. I have games built and working which need only shadows to be perfect. I must know how to do them. I'm asking for a small example of shadows. Something that works. Something that someone with ONLY PyOpenGL, Python, and Pygame (for loading textures, if necessary) can run and have work the first time. Preferably, it should be a modernish algorithm, with self-shadowing, if at all possible. It could render a single quad's shadow on another. That would be fabulous. I can't get anything at all. It's pathetic. Help, please! Thanks, Geometrian

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
There are different techniques for doing shadows. The most well known is stencil volume shadows and the other shadow buffers.
There are enough demos out there and many documents describing the concept and advantages and disadvantages.
developer.nvidia.com has a few. They code in C++ but the language doesn't matter. Be warned that most of the demoes there require nVidia.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Okay there are about 3 basic types of LI shadowing methods

Geometry Based - Stencil Shadow Volumes and the like
Image Based - Shadow Mapping type
Projection Based - Planar Projected Shadows / Vertex Projection

Now the first two are hard to implement and a lot can go wrong with them. The third is easy and requires a simple projection matrix to be created, first two can self shadow, third cannot so its a choice of simplity or realism.

It might be better to implement and then ask why stuff doesn't work and its very unlikely I could link to a PyOpenGL tutorial specifically for shadows.

Neutrinohunter
I think I was trying the shadow mapping type mostly. Self-shadowing is a must.
:-(

You're right. I did run into a lot of problems. Mostly they had to do with wanting dependencies that didn't exist anywhere. I could usually track the problem down to here, but then I'd be stuck because there would be nothing I could do about it.

Most required modification to make them work with OpenGL, too. I don't really know enough OpenGL to be able to derive the shadow code, so I have to try to work with the buggy code.

A couple of the tutorials were really quite small. They looked sort of redundant too, so maybe they could be cut down a bit. So I know that shadows can be done with a pretty small amount of code.

I was hoping, here, for a short piece of code that works.

Thanks for the answers.

G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Well I haven't experienced much of PyOpenGL or PyGame, only from what I've tested at work so I can't speak for the code, but I wouldn't have thought there is much difference between gl code and its pyOpenGL implementation.

I'm presuming its importing modules and stuff when it runs and can't find them?

If you were looking into SM, this is a normal OpenGL tutorial but it has information on what is happening and explains the lines of code
http://www.paulsprojects.net/tutorials/smt/smt.html

It might be a good read.

Neutrinohunter
Quote:http://www.paulsprojects.net/tutorials/smt/smt.html
I've seen that before. I couldn't get it working. I'd also prefer not to use GLUT.
Quote:I'm presuming its importing modules and stuff when it runs and can't find them?
Yep. And I know why--I don't have them. And I know why I don't have them--they don't exist (at least on the net, or I can't find them)!

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

OK, we can try fixing a broken demo. Here's the one that works the most:
www.geometrian.com/Programs/ShadowsBrokenDemo.zip
I included a .png showing the problem I experience--the shadow doesn't really work and only sometimes makes a garbled image on the floor. I at least got the demo to run...

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Instead of trying to reverse-engineer demos and tutorials you should really try to understand the theory behind it and write your own code, solving problems as they arise in the process (i'm sure people here on forum will be happy to help you with that) - it's the best way to learn in the long run.

Quote:Original post by Geometrian
OK, we can try fixing a broken demo. Here's the one that works the most:
www.geometrian.com/Programs/ShadowsBrokenDemo.zip
I included a .png showing the problem I experience--the shadow doesn't really work and only sometimes makes a garbled image on the floor. I at least got the demo to run...


Well, here goes: I used the original sources from web instead of your modified version (if you don't mind) - it depends on obsolete version of cgkit which i was unable to get working properly, but since the shadows demo uses the kit only for simple matrix multiplication i used opengl matrix functions instead of that (and ARB_transpose_matrix extension for simplicity). After that the demo seems working fine. From the picture you included i'd say the problem was solely in matrix format (row-order vs. opengl's column-order).

Here is the fixed demo: http://napalm.sf.cz/tmp/shadows.zip
With removed dependence on cgkit, you should need only pyopengl and pygame to run it.
OMG! THANK YOU SO MUCH!
It works! The shadows now maps correctly!
One small thing however...
It looks like, where the shadow is, the landscape is dark, but there are lines:
www.geometrian.com/Programs/Shadows 2.png
Thank you so much everyone for helping me get that working!

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

There are no lines on my machine, just shadow



On your screenshot it looks like wire-frame of the model gets involved in the shadow rendering pass, perhaps you have some debugging functions turned on ? I have only little experience with pyopengl and pygame so i can't help you with this one, sorry.

This topic is closed to new replies.

Advertisement