fenomas / noa

Experimental voxel game engine.
MIT License
611 stars 87 forks source link

Light Issues #148

Closed sourcerose closed 1 year ago

sourcerose commented 3 years ago

For some reason, light is traveling through the blocks. Is there anyway to fix this without implemeneting a really complex lighting system? This also Happens with SpotLight, PointLights, Directional, Hemispheric etc.

ghost commented 3 years ago

Sorry source I couldn't help earlier I have 2 kids and it's Christmas vacation , they kicked me out of the PC lol. I f you lower the ambient light and ground light and you add one huge light it will create a shadow darker and darker ,I saw it with my own eyes , but didn't have time to experiment , but today I had an idea if the light Wich is technically the sun , follows the player , the the shadow effect will follow the player also , please test it if you can thanks

sourcerose commented 3 years ago

Ok, I'll test it

sourcerose commented 3 years ago

I know this sounds dumb, but Im trying to use SpotLight.range = x to change the size of the light but it's not working. Any ideas??

sourcerose commented 3 years ago

Made a Question on the BBJS Fourm. https://forum.babylonjs.com/t/spotlight-range-is-not-working/16784 I think it might be a bug.

fenomas commented 3 years ago

Hi, so I could be misunderstanding the question, but in general I think light will always go through blocks unless you set up Babylon's options for handling shadows. Doing "real" shadows (where each light does tests against actual mesh geometries) is AFAIK not feasible for something like a big dynamic voxel world, so things like minecraft have a separate lighting system where the game engine tracks light levels for each voxel, and basically applies a tint to terrain graphics based on that, separate from the rendering engine.

OTOH if you're finding that lights aren't affecting meshes, I think there's also a limit on how many lights in a BJS scene can affect a given mesh. I think it's 4 by default, so the 5th light added to a scene won't affect anything unless various settings are changed. But I'm not sure of the details.

sourcerose commented 3 years ago

Any Ideas on how I could handle shadows? I've tried using shadowBuilder and that doesnt seem to work. The light does diffuse with a spotlight however only on the x,z axis. Not on the Y axis.

fenomas commented 3 years ago

Hi, sorry I thought I replied to this. Basically handling shadows at the "meshes and lights" level is a Babylon question, and I don't know very much about it. My suspicion is that it couldn't perform well, due to how many terrain meshes would need (or potentially need) to cast shadows on each other. But I haven't tried anything similar.

(All that is separate from the question of handling lighting at the "voxel engine meshing" level, which isn't currently planned for noa.)

Codezilluh commented 3 years ago

It definitely is a problem with Babylon. I don't know how well shadows would work with this performance-wise, but in other environments one can have shadows and 3D lighting while keeping a smooth performance.

Codezilluh commented 1 year ago

It's been over a year. Recently I was making my own voxel stuff for fun when I remembered Noa engine. Apparently, shadows don't have much of a performance hit. I've since tested them on some pretty wild and large terrain. I scrappily implemented BabylonJS shadows into Noa. Here is a picture:

image

I'm using a frustum size constraint, not for performance, but just to keep the pixelation of the shadows down (currently using 2048px shadows, although performance didn't change much with 4096px). The main problem with shadows right now is that BabylonJS self-shadowing isn't the best.

Here's a GIF demonstrating it:

test

fenomas commented 1 year ago

Wow, this looks really impressive. Was the code straightforward? I'd like to check out how it scales to larger draw distances!

Codezilluh commented 1 year ago

Wow, this looks really impressive. Was the code straightforward? I'd like to check out how it scales to larger draw distances!

Sorry for the delayed response (this got lost in my email over Thanksgiving). Yes, it was straightforward. I believe I just created a sun light, added a ShadowGenerator to it, updated your code to add meshes to the generator, and changed something to move the sun light above the player.

fenomas commented 1 year ago

Sorry for the delay here. Noa v0.33 now adds a bunch of internal changes meant to enable clients to use Babylon built shadow generators, which seem to work pretty well and performantly. The examples repo now have shadow generators in the test and stress worlds, which should give a general idea of how to go about it. Thanks for all the feedback here, especially @Codezilluh !

I'll close this now; if you find bugs or missing stuff please track them in a fresh issue.