Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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 3751 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  
You cannot reply to this message, because it is very, very old.

numerical (285 views)
2017-02-21 07:32:16

numerical (283 views)
2017-02-21 07:31:46

theagentd (395 views)
2017-02-18 13:42:33

theagentd (394 views)
2017-02-18 13:35:16

h.pernpeintner (1561 views)
2017-01-24 22:39:11

h.pernpeintner (1548 views)
2017-01-24 22:38:32

Galdo (2112 views)
2017-01-12 13:44:09

Archive (2109 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2644 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2349 views)
2016-12-15 21:50:57
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!