Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL PyOpenGL Shadows

This topic is 3774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)!

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!