Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
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  
  Interpolating 2D tile lighting  (Read 1621 times)
0 Members and 1 Guest are viewing this topic.
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Posted 2013-08-15 11:55:36 »

I'm a little confused about "smooth lighting" and how to implement it. I'm using LibGDX and just doing simple tile by tile lighting right now, and I want to smooth it out to look nice. When I got to thinking, however, I first thought of Minecraft's smooth lighting system, and that made me realize something. Minecraft doesn't use shaders, so you cannot access individual pixels (I think), so how does the lighting work? I always imagined that you start with a light value like 12, get the light value of the block next to it, then create a gradient of pixels for the light and render it on the two block. However, you would have to modify individual pixels to make this work, so I'm confused here. Unless of course I'm wrong and you can play with pixels in old OpenGL.

But now I'm wondering how to implement my own system. I need to get the average, or interpolate, the light values of my tiles. But how do I do this? Do I need to use shaders or is this something I need to code by hand? I'm using LibGDX but that shouldn't matter. Also, in smooth lighting systems do you do a lighting pass and render tile based lighting and then do another pass and interpolate the lighting?

Offline davedes
« Reply #1 - Posted 2013-08-15 12:14:23 »

Can you point to an image of what you mean? From all the screens I've seen, Minecraft doesn't really have "smooth lighting" -- it just has per-face lighting. But maybe I'm wrong.

In any case, you can do it fairly easily with vertex colors, and let GL do the interpolation for you. Each tile has four vertices, and if you give them different values, OpenGL will interpolate each. GL does this for any vertex attributes passed to the fragment level, e.g. texture coordinates.

You can use corner colors like so:
http://www.badlogicgames.com/forum/viewtopic.php?p=42550#p42550

You can use shaders if you want more definition, like giving a "3D" look to a brick texture.
https://github.com/mattdesl/lwjgl-basics/wiki/Shaders
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6

Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #2 - Posted 2013-08-15 12:33:19 »

Ok, I found an example of minecraft's lighting system and then what I kind of want my 2d light to look like.
Click to Play

And the 2d lighting:

As you can see, the lighting is interpolated between tiles so that it looks smooth and you can't see the individual tile lighting. I don't know if your first link will provide this feel, but I'll take a look at it. I cannot actually code right now, so sorry about the lack of code. I'm currently just researching and creating psuedo code for when I have access to a computer next.

Edit: oh sorry I just re read your post and realized you gave me an answer. So OpenGL will do that automatically for me? How do I do this exactly? When I was using straight LWJGL the interpolation would happen without me actually calling a function for it to do so, so I can't remember how to do this. If I'm correct, I believe I just gave each vertex a color using a color function (can't remember what it was) and since its state based, it would use that color for each vertex until I changed it. Note: I was using the fixed function pipeline so I've never actually dealt with shaders. Is my lighting only possible using shaders?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-08-15 15:44:23 »

Firstly; are you making a 3D or 2D game? Don't use Minecraft as a reference if you are making a 2D game, as the rendering process will be much different.


If you are making 3D cubes and want them to be very smoothly shadowed, you need to use per-fragment lighting (i.e. shader-based).
The LibGDX 3D API includes lighting, or you can do it yourself with shaders like this:
http://www.arcsynthesis.org/gltut/Illumination/Tut10%20Fragment%20Lighting.html

If you are making a 2D game, then the above is irrelevant. Instead, you should be doing research on 2D dynamic shadows:
http://www.java-gaming.org/topics/2d-dynamic-lighting/27012/view.html

One common solution is to use blend functions. This involves rendering your scene once, and then rendering your lights on top:
https://gist.github.com/mattdesl/5957929

Another solution involving FBOs and shaders might look like this:
https://gist.github.com/mattdesl/6241893

Read up on these subjects here:
https://github.com/mattdesl/lwjgl-basics/wiki

If you are using LibGDX it would be better to use something like Box2DLights. It already includes a lot of optimizations
(for example, using disc meshes to reduce fill-rate on mobile) and is easy to set up. It implements all the OpenGL/shaders for you.

Offline lcass
« Reply #4 - Posted 2013-08-20 21:33:03 »

maybe instead of using it on each tile do an overlay of light that does it say every 4 pixels? then update that and then modify the tiles color in the locations that the light was.
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.

TehJavaDev (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

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

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

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

lcass (43 views)
2014-10-15 16:18:58
My New Android Sudoku 2d Game
by gamerfan
2014-10-31 06:12:26

My New Android Sudoku 2d Game
by gamerfan
2014-10-31 06:05:29

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