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 (408)
games submitted by our members
Games in WIP (293)
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 881 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.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 439
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!
Play the free demo of Revenge of the Titans!
Online Riven
« League of Dukes »

JGO Overlord


Medals: 439
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!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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!
cubemaster21 (108 views)
2013-05-17 21:29:12

alaslipknot (117 views)
2013-05-16 21:24:48

gouessej (146 views)
2013-05-16 00:53:38

gouessej (141 views)
2013-05-16 00:17:58

theagentd (154 views)
2013-05-15 15:01:13

theagentd (138 views)
2013-05-15 15:00:54

StreetDoggy (182 views)
2013-05-14 15:56:26

kutucuk (206 views)
2013-05-12 17:10:36

kutucuk (205 views)
2013-05-12 15:36:09

UnluckyDevil (212 views)
2013-05-12 05:09:57
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

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.144 seconds with 20 queries.