2D terrain lighting similar to starbound

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

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

I have also implemented some shadow casting shaders:

However, im more interested in how to light the terrain (without needing a light source)

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. :frowning:

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

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.

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

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

Anyways, back on topic.

  • Jev

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

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: