Torch Light Effect
BlitzMax Forums/BlitzMax Programming/Torch Light Effect
| ||
Hi All, I'm trying to achieve a torch light effect around some sprites. I've tried using SetBlend SHADEBLEND and this works okay, as long as I dont have a background image.... but I want a background image! Heres some code: When you first run it, you can see the desired effect (although the player at px2,py2 should have alpha too...). Then place F1 and F2 to turn on the backgrounds. When the backgrounds are on the tiles become transparent which I dont want and the light effect is ruined... any solutions? Thanks |
| ||
is this what you are trying to do? |
| ||
Thanks Nate, but not quite. I actually tried that way first. It doesnt shade the level tiles and it looks light the brightness is wrong on the lighted part... Any other ideas? |
| ||
A bit more like this... Drawing a light/shadowmap over the whole scene. In this example it's grabbed at 1/10th scale for performance. Using an image with blending edges for the highlight will improve the look of it. |
| ||
Excellent! Thanks alot matibee! Would never have thought of doing it that way! |
| ||
Tided the code up a bit and added an "image" with blended images (but looks like grab image doesnt grab the alpha correctly at the edges) - Thanks again matibee! |
| ||
Happy to help :) I'm a bit rusty with my blend modes, but I think I've fixed your other issues too.. GrabImage won't grab any alpha values since there's no alpha stored on the rendertarget (IIRC). To get round that, draw the light image in various shades of grey without any alpha involved. Now when you draw them to your lightmap, draw them in LIGHTBLEND mode and when you draw the lightmap, there's no need to set/unset any alpha values since there's no alpha involved with the shadeblend. Finally, if you want the two lights to interact, try turning down the maximum grey value in the CreateLight function Local grey% = Min ( i * i, 128 ) Personally I think there should be more of a drop off in light values as it moves away from the centre, so experiment a little more with the CreateLight func (or I'd have used in image I could get right in Photoshop). |
| ||
Thanks again matibee! I'm a bit rusty with my blend modes Ive only really used ALPHABLEND and LIGHTBLEND the blend modes... Cool example using LIGHTBLEND to use the grey to fade out, although in my game Ive actually created an image with alpha, but Ill see which is better :) |
| ||
One other thing I wanted to try.. If your tiles are 32x32, and you make the shadow map 1/8 th scale, you could occlude the lights using 4x4 rects of solid black drawn onto the lightmap after the lights have been drawn. If you had a quick visibility test, you could fill in all the 4x4 cells that are not visible from the light position, creating a very cool dynamic lighting effect :) |