I have a small block engine similar to a very early version of Minecraft using LWJGL. I now want to actually implement lighting. I understand how it works I'm just confused as to how I'm supposed to render lighting. Am I supposed to change the "brightness" of the texture to simulate bright terrain? I'm asking how to actually change the light value of a quad, maybe there are some tutorials out there? I want it to be block by block, no smooth lighting. I have figured out that blocks need to have a light value, and for every block next to it, you decrease that light value by a little bit until its "black".
1 Answers
(At least) two options, assuming a fixed-function renderer:
Use a single texture (your basic texture atlas, with the default
GL_MODULATE
texenv.) and set a per-vertex gray-scale color to darken the texture in proportion to the light level. WithGL_MODULATE
the texture RGB channels are multiplied by the vertex color RGB channels. So a vertex color of RGB(255,255,255) would be fully lit, RGB(0,0,0) would be pure black, and RGB(128,128,128) would be somewhere in the middle.Use two textures (appearance atlas and lightmap atlas) and multitexture. The light level is set for a given face by supplying texture coordinates that select the appropriate lightmap square. If you animate the lightmap you can get a day/night cycle "for free" without having to iterate over the entire volume fixing up vertex colors like in #1.

- 51,148
- 11
- 85
- 139
-
Sorry I forgot to mention I'm not actually using textures. I'm just using a VBO and I colored the faces with another VBO color array. Is there anyway to change the brightness of a color? – Feb 20 '13 at 18:00
-
Just multiply the RGB color triplets by a scalar, similar to #1. For instance RGB(255,0,0) * 0.5 = RGB(128,0,0), roughly half as bright. – genpfault Feb 20 '13 at 19:14
-
Thats all I have to do? Why do people say lighting is ridiculously hard then? I guess are there other more "professional" ways of doing it? – Feb 21 '13 at 11:11
-
(Very) basic lighting approximation *is* easy. Doing things like (fast) dynamic lighting and shadows is significantly harder with the fixed-function pipeline. – genpfault Feb 21 '13 at 20:43
-
Ah I see. So shaders wouldn't really help me then? And would I just modify the RGB values of the cube faces directly or would I still have to use GL_MODULATE? And (last question I promise!), do I have to re upload the buffer data for the color VBO and the geometry VBO or just the one holding the color data? – Feb 21 '13 at 23:05
-
Shaders would eliminate the lightmap in #2, though you'd still have to update the light level values when you add/remove local light sources like torches. `GL_MODULATE` only applies if you're using textures. If you have a separate color VBO you just have to reupload that. – genpfault Feb 21 '13 at 23:22
-