Overhead Maze Lighting / Shadows

Hello all,

I’ve been working on a simple overhead maze game in OpenGL using lwjgl and would like some opinions here. I’ve got my maze randomly generating… I’ve got the thing showing on the screen. I even have a nice little minimap showing you where you’ve been, etc. So, now I’m at the point where I want to add lighting (to simulate a torch being held by the character.) I’ve added the light at the position of the character in the maze and adjusted light properties to give off the amount of lighting I’d like… Then the problem… The light goes through walls and so forth. :’(

Reading through the red and blue book and other various sources, I realized that my problem is shadows. So my question is, what technique would be appropriate to use? Any suggestions would be appreciated.

Regards,

– Renanse

Thought a screen shot might be helpful:
http://www.renanse.com/sample_shot_gl.jpg

No answers yet so let me ask in a different way. Has anyone done stenciled volumetric shadowing in lwjgl and has some sample code they’d like to share? I just can’t seem to get it. :-[

A little coaching would be awesome. Thanks!

There is the nehe shadow tutorial:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=27

Don’t know of a lwjgl port, but ther is a jogl one. A link can be found here:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=jogl;action=display;num=1064699713
Look for lesson 27.

Thanks Tom.

I have read the Nehe tutorial 27 and I’ve tried porting the jogl demo to lwjgl. I’ve got the basic scene there (sans the spheres since we don’t have those glu methods available) with all the keyboard commands working etc.

For some reason though, the thing is dog slow and does not cast shadows. I can fix the slow part by playing with the far and near clipping depth values or eliminating the stencil test, but I can’t seem to figure out how to get shadows running.

I’ve posted my code, as well as a binary and enough stuff to run it in win32 here:

http://www.renanse.com/lwjgl_nehe_27.zip

(sorry, it’s a bit rough but I was originally only porting for intent of learning how it worked…)

I think it would be a great tutorial for the lwjgl community to have access to. Anybody care to help troubleshoot?

Ugh an update: A friend of mine tried out the example I put together on his machine and it seems to work fine. Has shadows, good speed and all.

His machine:
1.2 GHz AMD Athlon… 512 MB Ram… 64 MB ATI Radeon 7200

My machine:
2.0GHz Intel P4… 512MB Ram… 128MB GeForce4 ti4600

Very frustrating! Any ideas?

Ok, me once again. Sorry! I’ve determined that the Jogl port also doesn’t cast shadows on my machine. Other demos (like the jogl - nvidia ports) cast shadows ok. Anyone with more info on all this, please let me know. In the meantime, I’ll try porting one of those demos to lwjgl…

You can tell me to shut up any time now. :slight_smile:

I’m not sure how old the Nehe 27 lesson is, but it seems to miss the latest development in shadow volume rendering like infinite far clipping planes and carmack’s reverse. There’s an interesting article on the nvidia site about it:

http://developer.nvidia.com/object/fast_shadow_volumes.html

and the original:

http://developer.nvidia.com/object/robust_shadow_volumes.html

Hope it helps.

  • elias

You could aways do a tile-based hack. I’ve done this before and it generally looks pretty good.

In map grid coordinates, scan a filled circle from the light position by scanning a square of map cells all around the light and using Bresenham’s algorithm to scan from the light source to each tile as you go. The distance to the light (in map units, not pixels) gives you the value to use for light attenuation. Assign this value to the map cell. If the scan out from the centre is blocked by a wall tile then stop the scan at that point.

When you render the map, use the light attenuation value calculated for the corners of the floor tile and modulate it as you draw it. The walls can be taken care of similarly.

Cas :slight_smile:

Looks like OrangyTang’s article on GameDev.net could be useful, find it here.

Thanks. It mentions being specifically for 2D, whereas I have sortof a isometric 3d viewpoint with some tiles having greater height than others… I wonder if I can bend his code to my will? :slight_smile: Worth a shot.