Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  OpenGL and top down 2d lighting?  (Read 837 times)
0 Members and 1 Guest are viewing this topic.
Offline Dxu1994
« Posted 2013-10-10 00:31:15 »

Hey JGO,

I was wondering if anyone here knows how to do a "fake lighting" effect in OpenGL?

At the moment I'm raycasting rays in all directions from the centre of the player, making a list of the hit vertexes and drawing a TriangleFan with those vertexes.

I was wondering if anyone knew a better approach to this?

Thanks in advance!

Offline wessles

JGO Wizard


Medals: 77
Projects: 4
Exp: 3 years


Radirius Games


« Reply #1 - Posted 2013-10-10 00:49:05 »

Well, off the top of my head (but never tried), there is a HUGE page on just this here on JGO. It is great! It looks pretty complex though, but if you are up for the challenge: here.

Offline opiop65

JGO Kernel


Medals: 161
Projects: 7
Exp: 4 years


JumpButton Studios


« Reply #2 - Posted 2013-10-10 00:58:59 »

You should most likely use box2D.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 310
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2013-10-10 01:29:57 »

This is quite a nice technique, and can be done without complex raycasting.

Offline Abuse

JGO Knight


Medals: 15


falling into the abyss of reality


« Reply #4 - Posted 2013-10-10 02:32:33 »

Funnily, I've just implemented an algorithm to do this in Java2d Smiley

Though I'm rewriting it atm to change the way the level is represented, so it'll be simpler to procedurally generate level data.

I doubt it'll be of much use if you're using ogl, but if you like I can post the code once I've refactored & neatened everything up a bit.

A quick overview of the algo:

- map defined as a maze of interconnected convex polygons
- lights are arcs (mathematical 'sector'), with an origin, radius, start & end angles.
- lights are rendered as gradient fill circles (pre-rendered to an image if you want extra speed), and are drawn through a polygon clip.
- the polygon clip is constructed by:
   - cast 1 ray out from light origin along start angle, looking for edge intersection with the polygon currently containing the light.
   - If the intersected edge is a wall (rather than a doorway into another polygon), add the intersection point as a vertex to your clip polygon.
   - walk around polygon's vertices, adding each as a vertex to your clip polygon.
   - once you reach a vertex that that lies beyond the light's end angle, cast a 2nd ray to find the intersection point
   - for each edge you walk around that is a doorway into another convex polygon (and is inside the radius of the light), process it recursively using the same algorithm.

Computationally it's very cheap; my initial implementation could render 1000+ clipped light sources @ 60fps.

There are of course limitations; no spot effect (focal point), no smooth transitions at the start/end of the light arc (sector), no surface specific lighting.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
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.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!