Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 2391 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
« 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 Opiop
« 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: 382
Projects: 11
Exp: 4 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 Ninja

Medals: 66

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.
Pages: [1]
  ignore  |  Print  

EgonOlsen (78 views)
2018-06-10 19:43:48

EgonOlsen (58 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (260 views)
2018-05-13 18:23:11

nelsongames (158 views)
2018-04-24 18:15:36

nelsongames (157 views)
2018-04-24 18:14:32

ivj94 (898 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (811 views)
2018-03-24 14:43:53

Solater (175 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!