Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 1050 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: 605
Projects: 4
Exp: 16 years


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
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: 605
Projects: 4
Exp: 16 years


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
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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (50 views)
2014-04-15 18:08:23

BurntPizza (46 views)
2014-04-15 03:46:01

UprightPath (62 views)
2014-04-14 17:39:50

UprightPath (44 views)
2014-04-14 17:35:47

Porlus (61 views)
2014-04-14 15:48:38

tom_mai78101 (84 views)
2014-04-10 04:04:31

BurntPizza (142 views)
2014-04-08 23:06:04

tom_mai78101 (242 views)
2014-04-05 13:34:39

trollwarrior1 (201 views)
2014-04-04 12:06:45

CJLetsGame (208 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!