Hey. So awhile ago I started a project to get a baked but real shadow map in the BGE.
A shadow map is usually a technique of making realtime shadows in a 3D engine involving GLSL shader capbilities. I wanted to have a shadow for a project, but the distance to cover with a GLSL shadow map would be very great. So, a baked shadow map may have been a good idea. But, I wanted to still retain the capability to go into shadows and be shaded. So, I've implemented a method of getting shading for a baked shadow map that actually isn't too complex, and it's both GLSL-less and fairly flexible in terms of capability.
First, I use the bge.texture module (VideoTexture for less recent Blender builds) to grab the shadowmap image file externally. Why grab the image externally instead of just applying it to the mesh before running the game? Well, by getting the shadow map texture externally, I can convert the image to an array of colors.
After this, I use a function that I made to find the color value of an image given its array of color values, X and Y position, and size. By getting the color of the lightmap, the Player object can discern whether he's standing in a shaded area or a lit area. After this, it's just a simple matter of changing his color to fit his lighting environment. It works very well.
A nice addition is that because the external image is obtained through code, the texture doesn't even have to be visible on the mesh - you can have an image just for data and reference to shade characters, while having the much more attractive texture be present on the mesh in-game. So, that's about it. Download the Realtime Shadowmap file here, and as always, have fun!
EDIT: I found after posting this that this method didn't work in a standalone executable because of how I set up my script - I fixed it and updated the download. Now you can make a standalone executable that should use this baked shadowmap method flawlessly.
Just the thing i was looking for.
ReplyDeleteThis is very useful!!!!
ReplyDeleteThanks for share with us!!!!