1
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

9
\$\begingroup\$

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.

\$\endgroup\$
4
  • 5
    \$\begingroup\$ 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. \$\endgroup\$
    – Kevin Reid
    Commented Feb 29, 2012 at 15:56
  • \$\begingroup\$ Would minecraft rebuild the objects every time the lighting value changed? \$\endgroup\$
    – Darestium
    Commented Mar 1, 2012 at 5:25
  • \$\begingroup\$ 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? \$\endgroup\$
    – Darestium
    Commented Mar 1, 2012 at 6:57
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Mar 6, 2012 at 12:36
0
\$\begingroup\$

(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
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .