Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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 terrain lighting similar to starbound  (Read 2024 times)
0 Members and 1 Guest are viewing this topic.
Offline Plutoniummatt

Senior Newbie


Medals: 1



« Posted 2014-03-30 01:23:17 »

So, I've been trying for a while to write something that achieves TERRAIN lighting similar to that of starbound:



But I'm not very good and the ones i manage to come up with are pretty inefficient and the framerate end up being rather poor using Java + openGL, shader based solutions.
Plus it doesn't look very smooth around the edges

My general approach has been:

Render transparent pixels to occlusion FBO
sample 8 times to achieve blur
render foreground blended with FBO

Result:


Could anyone shed some light on any alternative approaches?



Thanks
Offline The Lion King
« Reply #1 - Posted 2014-03-30 01:49:42 »

I personally use the lighting model described here with some of my own features on top to make it more realistic

http://archive.gamedev.net/archive/reference/programming/features/2dsoftshadow/

the game you linked has a different lighting model tho

"You have to want it more than you want to breath, then you will be successful"
Offline Plutoniummatt

Senior Newbie


Medals: 1



« Reply #2 - Posted 2014-03-30 01:54:19 »

I have also implemented some shadow casting shaders:



However, im more interested in how to light the terrain (without needing a light source)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kpars

JGO Kernel


Medals: 107
Projects: 4
Exp: 4 years


Extreme Typist.


« Reply #3 - Posted 2014-03-30 04:05:00 »

While I personally feel that Java2D and Graphics2D are fine for games and are generally underrated, you're going to have a tough time getting lights like that to render at a smooth framerate.

If you want something similar to Java2D, I must recommend a little thing called GLG2D. You can read about it on from link I added, and you may have better luck using that.

If you really want to achieve similar light effects though, it would be best to use OpenGL. Sorry. Sad

I really apologise if this post seemed useless, but there's not a lot of advice I can really give. How are you currently setting up these current lights again?

- Jev

Offline ewg

Junior Devvie


Medals: 8


Java games rock!


« Reply #4 - Posted 2014-03-30 05:09:08 »

I think he already is using opengl.

I think you could cache in each of your tile object the filled or empty state of each of that tiles neighbors and itself(and neighbors neighbors if you want a more gradual fade to black) and only update that data when a block is created or destroyed.
Then when sending your vertex data to the gpu add a vertex attribute with this neighbor data encoded into it (how it is encoded will vary based on how you currently send you map data and how wide you want that fade to black to be.)
Then in the frag shader figure out the distance that pixel is from the box representing the closest empty neighbor to that pixel to determine how dark that pixel of the map should be.

This should allow you to draw your map in one pass without any alpha blending. 

Offline SHC
« Reply #5 - Posted 2014-03-30 05:58:29 »

If you are using OpenGL, then why did you post in Java2D board?

Offline kpars

JGO Kernel


Medals: 107
Projects: 4
Exp: 4 years


Extreme Typist.


« Reply #6 - Posted 2014-03-30 07:05:57 »

I'm going to assume he confused Java2D with the subject of Java 2D (Game) Development.

Anyways, back on topic.

- Jev

Offline Plutoniummatt

Senior Newbie


Medals: 1



« Reply #7 - Posted 2014-03-30 11:51:39 »

Apologies if this was in the wrong forum, I have indeed misunderstood Java 2D to be a general 2D Java game dev forum Smiley
Offline matheus23

JGO Kernel


Medals: 113
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2014-03-30 17:28:33 »

Asked myself that question, too, see this thread:
http://www.java-gaming.org/topics/starbound-lighting-techneques/26363/view.html

The algorithm I came up with to use it in WorldOfCube was the following:
http://www.java-gaming.org/topics/starbound-lighting-techneques/26363/msg/240098/view.html#msg240098

But davedes' suggestion was very interesting, too, though I'm not that good with GLSL, so I wasn't using that one...:
http://www.java-gaming.org/topics/starbound-lighting-techneques/26363/msg/230988/view.html#msg230988

He also posted some more about that algorithm later, together with an implementation, I can't find the link though...
You can have much more information here:
http://www.java-gaming.org/topics/2d-dynamic-lighting/27012/view.html

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
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.

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

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

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (28 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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!