Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
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 9778 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


Could anyone shed some light on any alternative approaches?

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

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

Senior Devvie

Medals: 11

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
« 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: 138
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:

The algorithm I came up with to use it in WorldOfCube was the following:

But davedes' suggestion was very interesting, too, though I'm not that good with GLSL, so I wasn't using that one...:

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:

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  

hadezbladez (2614 views)
2018-11-16 13:46:03

hadezbladez (940 views)
2018-11-16 13:41:33

hadezbladez (2567 views)
2018-11-16 13:35:35

hadezbladez (506 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (4340 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 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!