Anyone have an articles/tutorials on top down lights/shadows?
This engine looks really nice:
http://www.asantee.net/ethanon/
I don’t even understand the basic concepts of this. How are lights/shadows handled in games, specifically 2d.
Anyone have an articles/tutorials on top down lights/shadows?
This engine looks really nice:
http://www.asantee.net/ethanon/
I don’t even understand the basic concepts of this. How are lights/shadows handled in games, specifically 2d.
The algorithm is rather simple: the only occluders are 2D lines. A triangle is comprised of 3 lines. Every line results in a quad that is the shadow. You create this quad by taking the vector from the light source to the edge of the line (edges are P1 and P2), and projecting a point much further (beyond the viewport), call it P3. Do the same for the other edge, P4. Now ‘connect the dots’ and you have your quad.
The soft shadows are generated by using 8 lights in a circle, around the ‘real’ light. For every light, for every quad, I fill the light-framebuffer with a (greyscale) color (no blending) then I add all light-framebuffers together (no blending), then I multiply (no blending) the result with the background/scene.
The above screenshot is a software renderer, with a lot of overdraw, yet still rendering >100fps. Naturally you don’t need to calculate the shadows every frame, making the overhead negligible.
Thanks for explaining that, but I’m not even familiar with that terminology.
A line connects two points: P1, P2.
Your light source is at P0.
Calculate the vector from P0 to P1: v1 = (p1.x-p0.x, p1.y-p0.y, p1.z-p0.z)
Calculate the vector from P0 to P2: v2 = (p2.x-p0.x, p2.y-p0.y, p2.z-p0.z)
Make the vectors longer by some big factor:
v1 *= 10000
v2 *= 10000
Add the vectors to P0
P3 = P0 + v1;
P4 = P0 + v2;
Draw a quad using the points P1,P2,P4,P3 (in that order)
maybe worth checking orangy’s article on gamedev about that?
http://www.gamedev.net/reference/programming/features/2dsoftshadow/