# How does Minecraft compute lighting for it's non-block objects?

I was wondering how the creator of Minecraft went about lighting the objects (player and pickaxe) based on the lighting level around the player. I have implemented the ability to light the blocks around the player but I can't really think of anyway to implement with objects. Also, when I the player moves and the lighting values change will I have to rebuild it's vertexbuffers? Or is there some other way?

Any ideas?

Simplest option is to grab the lighting from the block your standing on (or if possible the lighting on the block in the air that corresponds to the block the pickaxe is in) and use that for lighting the pickaxe/player. Or in other words, calculate the lighting for the pickaxe as if it was a block in that position.

To get more realistic shadows you would need to look up Shadowmapping or similar techniques, but given the nature of the project I expect using the previous one will give you good results.

• The first is what Minecraft does — you can see that if you find a lighting glitch, your tool becomes dark, and if an entity's origin enters an opaque block (this can happen with minecarts) it turns black. Feb 29 '12 at 15:56
• Would minecraft rebuild the objects every time the lighting value changed? Mar 1 '12 at 5:25
• i.e like when the player moves into a different block with a different lighting value do I have to rebuild the buffers? Or is there another way? Mar 1 '12 at 6:57
• @Darestium Set the lighting information as shader parameter and set it using Effect.Parameters[name].SetValue. This way you dont have to rebuild any vertex or index buffers, simply update a variable as the player moves around. Mar 6 '12 at 12:36

(Expanding on my older comment...)

From observation while playing the game, I believe that Minecraft's lighting works in the following way:

• The world grid includes a light level for each cell. This is used to determine the base brightness of an entity whose origin lies in that cell. You can see that if you walk into a lighting glitch, your tool becomes dark, and if an entity enters an opaque block (this can happen with minecarts and arrows) it turns black.

• In addition, there is global directional lighting (in classic OpenGL style), which causes adjacent faces of objects to not have exactly the same color, adding definition to corners.

Thus the final displayed color of a textured surface would be

     worldBrightness * directionalLight * texel