Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  2D Lighting System  (Read 10576 times)
0 Members and 1 Guest are viewing this topic.
Offline CodeBunny
« Posted 2012-06-19 03:47:03 »

Well, currently I'm working on a top-down, 2D action RPG. Things are interesting.

While getting things going for that, I've put together a little 2D lighting system that I'm really happy with - it's pretty, simple, and fast.

Here's a screenshot:



I also made a dev video here:

<a href="http://www.youtube.com/v/GI63eeaXbWs?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/GI63eeaXbWs?version=3&amp;hl=en_US&amp;start=</a>

What do you guys think?
Offline Longarmx
« Reply #1 - Posted 2012-06-19 04:04:32 »

Looks like a nice engine that will be very useful in your game. Might I also say that you talk very well, giving detailed instruction with clear pronounciation and no stuttering. As you develop your game more and make more development videos, people's interest will grow more because of how you address them with new features in your game. I wish you the best of luck in making your game and hope that this will turn out to be awesome! Grin

Offline CodeBunny
« Reply #2 - Posted 2012-06-19 05:01:12 »

Thank you. Smiley It actually took me a lot of re-recordings because I kept on flubbing. I'm glad that I managed to get a decent take, though.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #3 - Posted 2012-06-19 05:41:28 »

Very pretty!  Right now it looks like the lights act as pinpoints -- you planning on adding penumbra as well?
Offline CodeBunny
« Reply #4 - Posted 2012-06-19 12:56:49 »

I'm not sure - quite probably not.

Right now, the algorithm is just not set up to handle that whatsoever; the reason it's so fast is that I can cut corners (ensure that the geometry of the light is always clockwise, know that you never have to fade the light, just clip geometry, etc) - I'd probably have to do a full redesign to properly allow for that.

I also really like the look of hard lighting; I think it gives a scene a really sharp, edgy look, while soft shadows usually just make things look less dramatic.

That said, it's something I can come back to at any point in time; my lighting system is separate from everything else so I don't think there will be a major problem if I decide to upgrade.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2012-06-21 11:08:38 »

If it is fast enough to render a bunch of lights, you can simply fake soft shadows by creating a tiny circle of lights.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online matheus23

JGO Kernel


Medals: 110
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2012-06-21 13:49:51 »

That renderer looks pretty good, but you should render things in a differend order, maybe?

Currently it has this:


Also: this one was drawn in a minute with a mouse...

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline CodeBunny
« Reply #7 - Posted 2012-06-21 21:15:27 »

@Riven
Eh, I'm not sure it would be a significant enough jump in quality to warrant the extra render costs. I'll probably look back into this later to see if I can change the algorithm to make the lights have a penumbra, but it's not a high priority.



@matheus23
Haha yeah, that's one of the main issues with pillars in my lighting engine. Straight-line terrain is fine, but curves are difficult, because the entire algorithm is based on line-segment polygon clipping.

The way that the lights work is that I render my scene normally into a texture, like this:


Then, I render my lights into a lighting mask texture:


And then I render the two buffers together in a shader, to make something this:


Voila. Easy-peasy lights.

To create the geometry for each light, I create the base geometry of a point light (a textured quad), and then I clip out sections using line segments as barriers. So, for the columns, I take the most efficient route and use the cross-section of the column as the barrier.

It looks great except for the top of the object. Sad

It's possible that I can get away with this - one thing I did not show in the video was a "line of sight" mask that doesn't allow you to see through walls. The tops of the pillars will be covered, so the glaring discrepancy won't be as obvious.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2012-06-21 21:46:32 »

@Riven
Eh, I'm not sure it would be a significant enough jump in quality to warrant the extra render costs. I'll probably look back into this later to see if I can change the algorithm to make the lights have a penumbra, but it's not a high priority.

I did something similar, with infinitely long shadows and a bunch of point lights:

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #9 - Posted 2012-06-21 23:10:02 »

I'm sorry, what am I looking at exactly?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2012-06-21 23:10:48 »

I'm sorry, what am I looking at exactly?
Emo Triangles casting shadows.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #11 - Posted 2012-06-21 23:12:14 »

Could you make the shadows darker? I think I can see the shadows, but they look almost identical to the white background...
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2012-06-21 23:15:49 »

Could you make the shadows darker? I think I can see the shadows, but they look almost identical to the white background...
Calibrate your monitor Smiley

The shadows are grey-scale 223/255 (87% white).
If that shows up as white on your monitor, it's way off.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #13 - Posted 2012-06-21 23:17:46 »

Ah, got it now.

How'd you go about doing this, may I ask?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2012-06-21 23:20:36 »

Ah, got it now.

How'd you go about doing this, may I ask?
My shadow-caster only knew about lines. Every line casts a shadow (a quad) that extends beyond the viewport. Obviously there is a lot of overdraw, but it was fast enough. I wrote a simple software rasterizer for it.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #15 - Posted 2012-06-21 23:21:43 »

Ah...

So you rendered the light and then cast shadows from it? How did you handle multiple lights?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2012-06-21 23:26:18 »

Every light is rendered into a 'texture' (int[w*h]) Note that you can fit 32 lights in each 'texture', if you set (binary OR) 1 bit per light.

It's either 1 (shadow) or 0 (lit). As a final pass I subtract the shadows from the scene.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #17 - Posted 2012-06-22 05:19:43 »

Ah... that's an interesting technique. I would not have thought of that.

However, I don't think that would work very well with what I'm trying to do. Colored lights, for example, wouldn't work, and it could potentially add up to a ridiculous amount of texture memory being used. One of the big things I am trying to do with my current setup is to keep my lights as lightweight as humanly possible (both from an API standpoint and used resources); I'm pretty close to that right now and don't want to add to it.

Still, thanks for the insight. Always good to see difference techniques.
Offline davedes
« Reply #18 - Posted 2012-06-22 05:28:01 »

Riven -- any code? Sounds intriguing. Is the shadow casting (the "lines" you described) similar to OrangyTang's method for shadow geometry?
 

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #19 - Posted 2012-06-22 12:34:54 »

I don't know whether I still have the code, I'll look into it.

And no, it's not anything like described by OrangyTang. It's really as simple as it can possibly be:

  • take 1 light (L1)
  • take 1 line (P1 -> P2)
  • draw a line from L1 to P1, and extend it (to infinity) and call it P3
  • draw a line from L1 to P2, and extend it (to infinity) and call it P4
  • the quad P1,P2,P4,P3 is the shadow area.
  • for each pixel in the shadow area, set the n-th bit to 1.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online matheus23

JGO Kernel


Medals: 110
Projects: 3


You think about my Avatar right now!


« Reply #20 - Posted 2012-06-22 12:47:27 »

I don't know whether I still have the code, I'll look into it.

And no, it's not anything like described by OrangyTang. It's really as simple as it can possibly be:

  • take 1 light (L1)
  • take 1 line (P1 -> P2)
  • draw a line from L1 to P1, and extend it (to infinity) and call it P3
  • draw a line from L1 to P2, and extend it (to infinity) and call it P4
  • the quad P1,P2,P4,P3 is the shadow area.
  • for each pixel in the shadow area, set the n-th bit to 1.
  • <- This is awesome, riven... Have you seen the "Egit-tutorial-post" I wrote? The list codes are aweful...

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline mike_bike_kite
« Reply #21 - Posted 2012-06-27 20:20:12 »

What do you guys think?
It looks great! Are you likely to make it freely available?

Arcade swarm
Board Chess - Checkers - Othello
Offline CodeBunny
« Reply #22 - Posted 2012-06-27 20:34:15 »

Probably - however, I'm probably going to finish my current game before I do anything like that.

I've been putting together a proto-version of jRabbit 2.0 as I go - there's a lot of very massive changes I need to do, so everything is being built again from the ground up. What I will probably end up doing is creating a series of "plugin" libraries that easily integrate with the base distribution. The lighting engine will be one of those, so you would be able to very simply add lighting to any game, but don't need to have unnecessary jars bloating your end product.
Offline CodeBunny
« Reply #23 - Posted 2012-07-05 04:38:37 »

Welp, I put together a video that explains my general methods for 2D lighting. http://youtu.be/0FZIKX1Y_8I
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #24 - Posted 2012-07-05 04:54:44 »

Welp, I put together a video that explains my general methods for 2D lighting. http://youtu.be/0FZIKX1Y_8I
Too bad that you don't actually explain anything regarding the actual lighting, except rendering a texture with multiplication. Sad

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #25 - Posted 2012-07-05 12:28:26 »

This seems to be the general consensus. Cry I'm putting together an addendum video that shows how I do shadows. My bad.
Offline davedes
« Reply #26 - Posted 2012-07-05 12:53:17 »

Don't bother with videos... just post code and explain it. Cheesy

Offline CodeBunny
« Reply #27 - Posted 2012-07-05 13:16:24 »

Eh, I think videos are more accessible to more people. It also allows people to directly see what I'm talking about - they don't have to put out any effort and mess with it themselves.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #28 - Posted 2012-07-05 13:34:16 »

they don't have to put out any effort and mess with it themselves.
I think your audience (programmers) want to copy and paste your code and see it work.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeBunny
« Reply #29 - Posted 2012-07-05 17:43:30 »

Good point. However, while I'm willing to explain my techniques, I'm keeping my code proprietary at the moment. I'll release it (along with tutorials and examples) later.

Basically, I want to finish my current game (since it's going to be commercial, I'm not going to be releasing code). Then, once I get jRabbit v2.0 released, I'll have my lighting system be an open-source plugin for that.
Pages: [1] 2
  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.

TehJavaDev (31 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (40 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (26 views)
2014-10-26 10:14:04

theagentd (32 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
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

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