Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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 Sandbox game  (Read 6017 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Devvie


Medals: 2



« Posted 2015-06-03 21:44:46 »

Hi,

Been working on this game for around two weeks on and off when I have time, doing the procedural landscape generation which is using
a mix of perlin noise and cellular automata. 

My blog website with latest screen shot is at:

https://sites.google.com/site/sterrialand/development/news/cavesarelookinggood

Next is to add trees on the grass level, easy enough working out where to place them, but guess should use sprites for them and not add to tile array...

Any advice on how I could add some tile lighting? Maybe use shaders?

I'm using Libgdx and OGL.

Thanks,
Steve
Offline chrislo27
« Reply #1 - Posted 2015-06-03 23:35:24 »

Tile lighting? I've covered this practically the same amount of times I have with basic cave systems, so I will dump an older post here and go over it more in depth.

Quote
You could have a 1x1 texture generated at runtime (or even stored if you wanted) and draw black tiles (with different alpha) on top of each block. This would also allow you to "light" entities.

I know you did want a blockier look, but you could even use gradients to smooth it out:


I know that your game is top down, but if you're going for a "gravity-down" (I can't remember the term for it right now, but a game like Terraria) game, you will need to use a shader to mask the lighting onto the world terrain so the "shadows" you drew don't interfere with the background (this guy had that problem in this thread).

Performance wise, this isn't all that bad if you only render the blocks around you. In your image, you are rendering 20x13 (ish) blocks. I'm rendering a lot more and it still does quite decent even on old machines.

Each block has a byte of data (I only use half a byte b/c I don't use the negative part). That byte corresponds to the "brightness" of each block. There is also a float for each block but that's for colour, which I won't go over.

Lighting is calculated with light sources and a recursion method at each source. The recursiveness of the lighting gives it that diamond shape.
My code is here.

This does use one shader, and it's to mask the lighting buffer onto the world without covering up the background. The smoothness is merely a gradient quad.

This is what the lighting looks like without gradients:


This is what the lighting looks like without masking:

As you can see the moon and the stars have the "shadow" effect as a result.
Offline steg90

Senior Devvie


Medals: 2



« Reply #2 - Posted 2015-06-04 09:50:46 »

Thanks for that.

Quite a lot of code there to look through ;-)

Do you have any video's of your game?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline steg90

Senior Devvie


Medals: 2



« Reply #3 - Posted 2015-06-04 14:36:02 »

Hi,

I've got this shader to do the whole screen:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
varying LOWP vec4 vColor;
varying vec2 vTexCoord;

//texture samplers
uniform sampler2D u_texture; //diffuse map

//additional parameters for the shader
uniform LOWP vec4 ambientColor;

void main() {
   vec4 diffuseColor = texture2D(u_texture, vTexCoord);
   vec3 ambient = ambientColor.rgb * ambientColor.a;
   
   vec3 final = vColor * diffuseColor.rgb * ambient;
   gl_FragColor = vec4(final, diffuseColor.a);
}


with a default vertex shader.

This just sets my whole screen lighter or darker dependant on the ambient colour that is passed in.
How could I apply the lighting to just parts of the screen?  Would I need to use a fbo?

Any help is much appreciated,  knew to shaders.

Thanks
Offline chrislo27
« Reply #4 - Posted 2015-06-08 14:26:22 »

I drew gradients over the blocks with their corresponding light levels. The corners of the gradients were the surrounding 3 adjacent blocks (counting diagonal) averaged with the block itself.
If you want simple blocky lighting, all you have to do is draw a 1x1 texture (either generated at runtime or read from file) and stretch it over your blocks. I myself haven't worked too much with shaders, but if you need a good resource, mattdesl has an awesome starting guide here.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (581 views)
2019-09-04 15:33:17

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

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

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

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

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

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

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

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

nelsongames (5115 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

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