Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (863)
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  
  Tile based terrain lighting  (Read 7467 times)
0 Members and 1 Guest are viewing this topic.
Offline Plutoniummatt

Senior Newbie

Medals: 1

« Posted 2014-03-30 12:03:02 »

Hi Guys,

So I've been trying to write a shader to light the terrain in my 2d tile based game, I'd like to achieve something that looks like Starbound's terrain lighting:

My attempts so far have not been so successful:

It's not as smooth as Starbound, plus it does not penetrate the ground as much.

My approach is something along the lines of:
Render transparent pixels to FBO, then apply some form of blur:

Blend this FBO with my foreground:

The performance isn't stella, ground penetration is low, the blur isn't smooth...

Does anyone have any pointers that could steer me towards a better solution?

Offline quew8

JGO Knight

Medals: 53

« Reply #1 - Posted 2014-03-30 13:52:08 »

What type of blur are you using? Because it seems to me that a Gaussian blur would look a lot smoother than what you are doing now.
Offline Plutoniummatt

Senior Newbie

Medals: 1

« Reply #2 - Posted 2014-03-30 14:05:16 »

I tried gaussian blur (standard 2-pass), but in order to achieve a blur as smooth with a high enough blur radius, I'd have to sample too many times, and again performance goes down the gutter....

The blur im using is similar, but achieved using less samples
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

« Reply #3 - Posted 2014-03-30 18:50:43 »

Whaaaa, don't create another thread if you posted in the wrong subforum, better ask for a mod to move the topic into another subforum :/

Anyways, I hope you have seen my answer in the other thread Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline kingroka123
« Reply #4 - Posted 2014-04-01 00:52:29 »

Would lighting my game suffice? It's not exactly like Starbound but it is very efficient and I can tell you how I did it if you want.
Offline Plutoniummatt

Senior Newbie

Medals: 1

« Reply #5 - Posted 2014-04-01 13:42:07 »

Yes please, that'd be much appreciated
Offline kingroka123
« Reply #6 - Posted 2014-04-01 21:01:50 »

Assuming that you are holding your blocks in a 2d array, all you have to do is create 3 variable to hold the rgb values of the block that has been lit and then sends a reduced amount of that light to the neighbors of the lighted block and repeat until too much light is lost;

float r,g,b;
Block north,south,east,west;
public void light(){


//...repeat for north and south

That's basically how I did it. It allows for colored lights that mix and create new colors.
- This does not use any rays of any kind so if you want walls to block light, this wont work
- if your game does not properly render and derender blocks, this will lag a bit.
Offline Grunnt

JGO Kernel

Medals: 143
Projects: 8
Exp: 5 years

Complex != complicated

« Reply #7 - Posted 2014-04-03 08:12:37 »

I think Craft the World uses a similar approach to lighting when zoomed out (i.e. per-block-lighting which is fast) combined with per-pixel-lighting (which is slow) that only kicks in when zoomed in. Works quite well.

Offline Plutoniummatt

Senior Newbie

Medals: 1

« Reply #8 - Posted 2014-04-17 21:01:38 »

Hey peeps,

After much coding and research, I've finally come up with a very efficient algorithm for lighting, its shader based, and looks quite close to that of starbound:

Thanks for the suggestions everyone.
Offline Longarmx
« Reply #9 - Posted 2014-04-18 02:19:15 »

Would you mind sharing the shader code? I am interested in what you came up with.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Plutoniummatt

Senior Newbie

Medals: 1

« Reply #10 - Posted 2014-04-18 10:12:42 »

The shader code itself is actually pretty simple, it uses a standard 2-pass gaussian blur.

But applying this to the entire screen would destroy performance, as the blur radius needs to be very large for this to look good.

The trick is to render the transparent pixels as solid pixels to a screen sized FBO, then down-scale this FBO to a smaller FBO, say 1/16 the original size.

Apply the 2-pass gaussian blur to the down-scaled FBO, I used a 21-sample gaussian blur.

Then use linear sampling and up-scale this FBO to screen size, you will now have a nice smooth blurred version of the transparent pixels with a large blur radius at 16x less GPU cost.

blend this FBO with the texture being drawn, voila
Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

nelsongames (3909 views)
2018-04-24 18:14:32
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

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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!