-1
\$\begingroup\$

So I was looking on how to create a minecraft - like lighting engine and I found the following post:

How can I implement lighting in a voxel engine?

The answer to it was incredible and perfectly detailed I would love if you the person who wrote it @Byte56 or anyone who knows how @Byte56 achieved the shadow effect that he called "a little more advanced"? If you do know how to achieve it can you please detail the way to create it like he did in his post?

This was the part I found really useful:

Here are a few things to keep in mind.

We're going to keep a list of cubes that need their lighting values checked Only transparent cubes and light emitting cubes have lighting values The first cube we add is the light source. A source is a special case. It's light value is set accordingly to the light source type (for example torches get a brighter value than lava). If a cube has its light value set above 0, we add all the transparent cubes adjacent to that cube to the list. For each cube on the list, we set its light value to its brightest neighbor minus one. This means that all the transparent cubes (this includes "air") next to the light source get a light value of 15. We continue walking the cubes around the light source, adding cubes that need to be checked and taking lit cubes off the list, util we no longer have any to add. That means that all the latest values set have been set to 0, which means we've reached the end of our light. - Byte56

This is the effect desired: [I have already implemented the normal lights]

enter image description here

EDIT:

I basically want guidelines to implementing the "shadow effect" of the light. As you can see the light being on the bridge casts light onto the ground in-front of the bridge as well even though its "out of the range" of the light. This creates an illusion that there is a shadow underneath the bridge. That is what I am looking to implement. I already have implemented the basic lighting that every block away from the light is the max neighbour minus one. This works great however I would love to implement this "shadow illusion"

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks. Though it's not really clear what you're asking. Please edit the post to include more details about what you want to do, what you've tried, and what isn't working. Just asking to expand on a single sentence is pretty open-ended. \$\endgroup\$ – MichaelHouse Aug 26 '14 at 1:07
  • \$\begingroup\$ @Byte56 I have expanded on the topic. \$\endgroup\$ – gopgop Aug 26 '14 at 11:26
2
\$\begingroup\$

The shadow effect in that image is created with rays and is somewhat imperfect. When calculating the light for each face, I check to see if the face of that block has line-of-sight to the center of the block containing the torch. The line-of-sight check is performed with a ray cast. If the block does not have line-of-sight, the amount of light is reduced by a significant amount, but not removed entirely. Most of this is explained in the post I linked along with the answer you quoted.

enter image description here

In the image you have in your question, you can see the lighting directly under the light source on the bridge is actually a little bit brighter than the light at the edge of the shadow. This is a defect caused by the light value only being reduced, and not removed entirely.

This can be fixed by not lighting the faces at all if they don't have line-of-sight, but this produces much harder shadows.

All-in-all, the lighting system is not perfect, but it suits the needs of the game well enough.

\$\endgroup\$
  • \$\begingroup\$ Interesting! I will definitely try this method. Although it seems quite a performance hogger \$\endgroup\$ – gopgop Aug 26 '14 at 13:49
  • \$\begingroup\$ Also what do you mean by baked into the texture of the cube here: This is a bit more processing intensive. However, what’s cool is we only have to do it once! We only have to compute it again if a cube in range of the light is added or removed. Otherwise the light is “baked” into the texture of the cube. \$\endgroup\$ – gopgop Aug 26 '14 at 13:52
  • \$\begingroup\$ It's sort of like baking because it's something that's done once and saved. It doesn't have to be recomputed every frame, or for different camera angles. It's actually pretty fast if you have a good raycast. Considering that it only takes about 30 seconds to light an entire world like this (when loading the world), it's a decent enough method. \$\endgroup\$ – MichaelHouse Aug 26 '14 at 14:06
  • \$\begingroup\$ But you do have to recalculate it when placing a block correct? You have to recalculate the light for the "chunk" the block has been placed and the 8 neighbouring chunks? Wouldn't that be quite intensive for block placement? I will give it a try anyways, maybe I can do it on a separate thread or something.. \$\endgroup\$ – gopgop Aug 26 '14 at 14:22
  • \$\begingroup\$ Lighting has to me recalculated for additions and removals, yes. You only need to rebuild the chunks the light touches. \$\endgroup\$ – MichaelHouse Aug 26 '14 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.