Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
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]
  ignore  |  Print  
  Tile based terrain lighting  (Read 1977 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:
http://flamingbard.files.wordpress.com/2013/12/starbound_mushrooms.jpg

My attempts so far have not been so successful:
http://i258.photobucket.com/albums/hh258/Plutoniummatt/Capture_zpsb146e4eb.png

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?

thanks.
Offline quew8

JGO Coder


Medals: 31



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

JGO Ninja


Medals: 35
Projects: 6
Exp: 1 year


Gamer's Helmet


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

http://i.imgur.com/ALQZzyJ.png

http://i.imgur.com/ALQZzyJ.png

Offline Plutoniummatt

Senior Newbie


Medals: 1



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

Yes please, that'd be much appreciated
Offline kingroka123

JGO Ninja


Medals: 35
Projects: 6
Exp: 1 year


Gamer's Helmet


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

So:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
float r,g,b;
Block north,south,east,west;
public void light(){

if(r>0||g>0||b>0){
   east.r=r/4;
   east.g=g/4;
   east.b=b/4;

   west.r=r/4;
   west.g=g/4;
   west.b=b/4;
//...repeat for north and south
}
}


That's basically how I did it. It allows for colored lights that mix and create new colors.
Note:
- 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 Wizard


Medals: 84
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  
 
 
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.

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

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

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

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
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!