Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [2D] Lights and Shadows  (Read 896 times)
0 Members and 1 Guest are viewing this topic.
Offline dime

Senior Newbie





« Posted 2010-09-18 09:01:20 »


Anyone have an articles/tutorials on top down lights/shadows?

This engine looks really nice:
http://sourceforge.net/project/screenshots.php?group_id=303720&ssid=128010
http://www.asantee.net/ethanon/

I don't even understand the basic concepts of this.   How are lights/shadows handled in games, specifically 2d.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #1 - Posted 2010-09-18 13:33:41 »

http://indiespot.net/files/shadowmap.png

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.


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline dime

Senior Newbie





« Reply #2 - Posted 2010-09-18 19:42:08 »


Thanks for  explaining that, but I'm not even familiar with that terminology.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #3 - Posted 2010-09-18 19:47:23 »

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)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline kulpae

Senior Newbie





« Reply #4 - Posted 2010-09-18 20:28:43 »

maybe worth checking orangy's article on gamedev about that?
http://www.gamedev.net/reference/programming/features/2dsoftshadow/
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
NegativeZero (4 views)
2013-06-19 03:31:52

NegativeZero (7 views)
2013-06-19 03:24:09

Jesse_Attard (13 views)
2013-06-18 22:03:02

HeroesGraveDev (57 views)
2013-06-15 23:35:23

Vermeer (57 views)
2013-06-14 20:08:06

davedes (55 views)
2013-06-14 16:03:55

alaslipknot (50 views)
2013-06-13 07:56:31

Roquen (71 views)
2013-06-12 04:12:32

alaslipknot (56 views)
2013-06-10 19:30:18

HeroesGraveDev (73 views)
2013-06-09 04:36:03
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!