Spotlighting

Monkey Forums/Monkey Programming/Spotlighting

Raz(Posted 2013) [#1]
How would you go about doing the following with Monkey?

Turning this



into this



are there any particular techniques?

Ta! :)


GfK(Posted 2013) [#2]
The way I did this in Dr Mal was to have a (I think) 128x128 image which is basically the transparent circle, with black around it. Draw that where you want it, then fill in the surrounding area with four DrawRects with the color set to 0,0,0.

Mind you, in Dr Mal, I had solid black instead of semitransparent, so you won't get away with even a tiny overlap of the DrawRects here without ruining the effect.


Paul - Taiphoz(Posted 2013) [#3]
Yeah I do the same sort of thing, I split my screen up into 64*64 tiles/grid and I offset the grids x,y position so that I can center a single tile directly over the hot spot, where I place my hole, the other tiles get filled with alpha'd black squares.

with that system I can also add other black shapes to do fog of war stuff.


Gerry Quinn(Posted 2013) [#4]
I have done similar. Draw the first image, then set alpha to what you want, and draw a solid black object with a hole.

As Gfk says, you will need to have exact values if you are using DrawRects() for efficiency. An alternative would be to draw everything first with intermediate alpha on a black background, then brighten the spotlighted area using ReadPixels() and WritePixels.

Or you could draw everything first half-bright as above, then use SetScissor() and redraw the spotlighted area in full brightness, then draw a black rect with a hole in half-brightness on the scissored area.


Raz(Posted 2013) [#5]
Thanks y'all :)

Will give drawing a square "hole" image and 4 drawrects a go!


EdzUp(Posted 2013) [#6]
The main problem I had with doing this was spotlight overlap things I tried was

1) a lighter circle placed over the area to be lit worked OK but washes out the image

2) the darkened screen approach, can't have spotlights overlap

3) light set by tile location from light source computed at time of creation of the level and when a light changes (everything within the light radius) works OK but looks tiled.

I went with 3 in the end with some extra tiles for working out the light level of surrounding tiles looks OK. I would love someone to write a fog of war tutorial for monkey and max that would be brilliant :)


Paul - Taiphoz(Posted 2013) [#7]
fog of war is really simple, well I should say there are really simple ways of doing it its all just a matter of how or what method will fit with your game or project.

I think a solution I tend to use the most is the grid, if my game uses tiles like lets say something like zelda, then I have a fog of war layer in my tile engine which is filled with black tiles, then as the player opens up the area you just swap out the black tiles for either none at all or some alpha to blend it out, the last time I used it I created a set of 15 or so black tiles with which border into visible space and I just tiled the world making sure that any border between fog of war and visible space used the appropriate black border tile.

not sure if any of that helps lol. hope it does. I really dont have time to do a demo or tutorial :(


EdzUp(Posted 2013) [#8]
Yeah I did the same in the end, in a realtime lighting setting its not practical as it does require a lot of calculations for loads of lights.