Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/133413220399595520
deleted 37 characters in body; edited title
Source Link
user1430
user1430

Voxel How can I implement voxel-based lighting forwith occlusion in a Minecraft clone-style game?

Im going to say this first- I am making this for fun, no profit. I am using C# and XNA.

  My current algorithm for lighting is a recursive method. However, it is expensive, to the point ofwhere one 8x128x8 chunk calculated perevery 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

  • Are there other lighting methods that will make variable-darkness shadows?
  • Or is the recursive method good, and maybe I am just doing it wrong?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracingray tracing, but I have no idea how this would work. Another thing I tried was storing lightsourceslight sources in a List, and for each block getting the distance to each lightsourcelight source, and using that to light it to the correct level, but then lighting would go through walls.

My current recursion code:
Notes: is below. This is called from any place in the chunk that does not have a light level of zero, after clearing and re-adding sunlight and torchlight.
world.get___at

world.get___at is a function that can get blocks outside of this chunk (this is inside the "chunk"chunk class)
Location. Location is my own structstructure that is like a Vector3Vector3, but intsuses integers instead of floating point values.
"light[,,]" light[,,] is the lightmap for the chunk.

Voxel lighting for a Minecraft clone

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

  My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

My current recursion code:
Notes: This is called from any place in the chunk that does not have a light level of zero, after clearing and re-adding sunlight and torchlight.
world.get___at is a function that can get blocks outside of this chunk (this is inside the "chunk" class)
Location is my own struct that is like a Vector3, but ints.
"light[,,]" is the lightmap for the chunk.

How can I implement voxel-based lighting with occlusion in a Minecraft-style game?

I am using C# and XNA. My current algorithm for lighting is a recursive method. However, it is expensive, to the point where one 8x128x8 chunk calculated every 5 seconds.

  • Are there other lighting methods that will make variable-darkness shadows?
  • Or is the recursive method good, and maybe I am just doing it wrong?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk). I was thinking about using a method similar to ray tracing, but I have no idea how this would work. Another thing I tried was storing light sources in a List, and for each block getting the distance to each light source, and using that to light it to the correct level, but then lighting would go through walls.

My current recursion code is below. This is called from any place in the chunk that does not have a light level of zero, after clearing and re-adding sunlight and torchlight.

world.get___at is a function that can get blocks outside of this chunk (this is inside the chunk class). Location is my own structure that is like a Vector3, but uses integers instead of floating point values. light[,,] is the lightmap for the chunk.

added 1306 characters in body
Source Link
user10835
user10835

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

My current recursion code:
Notes: This is called from any place in the chunk that does not have a light level of zero, after clearing and re-adding sunlight and torchlight.
world.get___at is a function that can get blocks outside of this chunk (this is inside the "chunk" class)
Location is my own struct that is like a Vector3, but ints.
"light[,,]" is the lightmap for the chunk.

    private void recursiveLight(int x, int y, int z, byte lightLevel)
    {
        Location loc = new Location(x + chunkx * 8, y, z + chunky * 8);
        if (world.getBlockAt(loc).BlockData.isSolid)
            return;
        lightLevel--;
        if (world.getLightAt(loc) >= lightLevel || lightLevel <= 0)
            return;
        if (y < 0 || y > 127 || x < -8 || x > 16 || z < -8 || z > 16)
            return;
        if (x >= 0 && x < 8 && z >= 0 && z < 8)
            light[x, y, z] = lightLevel;

        recursiveLight(x + 1, y, z, lightLevel);
        recursiveLight(x - 1, y, z, lightLevel);
        recursiveLight(x, y + 1, z, lightLevel);
        recursiveLight(x, y - 1, z, lightLevel);
        recursiveLight(x, y, z + 1, lightLevel);
        recursiveLight(x, y, z - 1, lightLevel);
    }

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

My current recursion code:
Notes: This is called from any place in the chunk that does not have a light level of zero, after clearing and re-adding sunlight and torchlight.
world.get___at is a function that can get blocks outside of this chunk (this is inside the "chunk" class)
Location is my own struct that is like a Vector3, but ints.
"light[,,]" is the lightmap for the chunk.

    private void recursiveLight(int x, int y, int z, byte lightLevel)
    {
        Location loc = new Location(x + chunkx * 8, y, z + chunky * 8);
        if (world.getBlockAt(loc).BlockData.isSolid)
            return;
        lightLevel--;
        if (world.getLightAt(loc) >= lightLevel || lightLevel <= 0)
            return;
        if (y < 0 || y > 127 || x < -8 || x > 16 || z < -8 || z > 16)
            return;
        if (x >= 0 && x < 8 && z >= 0 && z < 8)
            light[x, y, z] = lightLevel;

        recursiveLight(x + 1, y, z, lightLevel);
        recursiveLight(x - 1, y, z, lightLevel);
        recursiveLight(x, y + 1, z, lightLevel);
        recursiveLight(x, y - 1, z, lightLevel);
        recursiveLight(x, y, z + 1, lightLevel);
        recursiveLight(x, y, z - 1, lightLevel);
    }
deleted 2 characters in body
Source Link
user10835
user10835

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 2 mil25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 2 mil blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

Im going to say this first- I am making this for fun, no profit. I am using C# XNA.

My current algorithm for lighting is a recursive method. However, it is expensive, to the point of one 8x128x8 chunk calculated per 5 seconds. There are two options:

Are there other lighting methods that will make variable darkness shadows?
Or is the recursive method good, and I am just doing it bad?

It just seems like recursive stuff is fundamentally expensive (forced to go through around 25k blocks per chunk (a guess)). I was thinking about using a method similar to raytracing, but I have no idea how this would work. Another thing I tried was storing lightsources in a List, and for each block getting the distance to each lightsource, and using that to light it to the correct level, but then lighting would go through walls.

edited tags
Link
Nicol Bolas
  • 26.1k
  • 3
  • 77
  • 104
Loading
Source Link
user10835
user10835
Loading