Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 4859 times)
0 Members and 1 Guest are viewing this topic.
Offline Opiop
« 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:

You can use shaders if you want more definition, like giving a "3D" look to a brick texture.

Offline Opiop
« 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:

If you are making a 2D game, then the above is irrelevant. Instead, you should be doing research on 2D dynamic shadows:

One common solution is to use blend functions. This involves rendering your scene once, and then rendering your lights on top:

Another solution involving FBOs and shaders might look like this:

Read up on these subjects here:

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  

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

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

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

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

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

nelsongames (157 views)
2018-04-24 18:14:32

ivj94 (898 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (811 views)
2018-03-24 14:43:53

Solater (175 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!