Showing off my lighting system

Been playing around with cubes.
Been lots of fun. Mostly just combined the picking demo and the physics demo. Added a server so my kids can pick blocks in the same world together. They call it “Dad’s Minecraft”.

But the last day or so, I decided to add a lighting engine.

It still has a few weird edge cases. Like if a surface faces an empty chunk its black. And caves get dark when you dig them, but the initial chunk loading sometimes has tiny bit of leakage.

I also made some improvements to the physics and mesh generation. It no longer renders physics surfaces or mesh surfaces for the sides of chunks that are hidden by the next chunk over for example. Also allows you to transfer chunks in slices so they fit into network packets.

What do you guys think?

BigScorch

PS thanks @destroflyer

7 Likes

How is this implemented? Did you dynamically modify the textures or something more traditional like a filter? I ask since I am implementing a game with dynamic meshes (that JME’s built-in light and shadow system will probably be insufficient for) that needs good lighting.

I would guess, this is some shader doing work.I think you could pass the “distance” to lights (or light blocks) (=> the “brightness”) for each vertice and then modify the result in the fragment shader accordingly. At least that would be my first attempt.

Seems cool, but is there a problem with the regular Lighting.j3md shader or are you just making it for fun?

I’m using a color buffer.
I’m calculating all blocks exposed to the sky (strait up) and giving them a light value of 9.
Then every step away from those ‘source’ blocks I deduct 1 light value until you hit 0.
Then when I generate the mesh chunk, I give it a black to white scale color.

I was emulating the minecraft lighting pattern. I didn’t use normal lights/shadow casting because I didn’t want a natural look. I probably did it the hard way. I didn’t look very far into anything built into JME. Although I would be really surprised if it had something that already did this. (but happy, so please do tell!)

Right now it only supports sunlight as a source. I intend for it to support placed light sources such as lava/torches/glowing rocks etc. I also think I will try coloring the light to the source, so lava would give off red light, torches would give off orange, etc.

It does support breaking and placing blocks. So if you dig a cave, the cave gets light from the entrance, and gets darker the farther in you go. If you close the cave from the inside, it gets dark. Break a hole in the roof an it lights up again etc. Its configurable to how many levels of light you want. I have some performance improvements let to make. Right now placing and breaking blocks is fast because it just makes a delta calculation, but I’m not batching the chunk generation enough, so I still consider that part slow.

Right now my current challenge is a friend dared me to round the corners on the blocks so I’m not just making a minecraft clone. That is going to create some interesting lighting problems, but I’m still planning on how I can generate the more complex mesh correctly and quickly.

I’ve pushed it all to github. But I don’t consider it done yet.

BigScorch.

Oh, I forgot to mention, I also changed the grass algorithm to only put grass if the block is exposed to the sky, as opposed to just being exposed to air above. So when you dig into the ground, its dirt instead of more grass. It also effects how the shadows look since they aren’t on bright green ground.