A Lot of Lights demo - Babylon.js Playground
You have to be very creative with very few ârealâ light sourcesâŠ
The scene in question I wonder if you could make the lights simple holes in the geometry and surround the whole thing with a lightbox maybe?
Thread resurrection commence
Iâve been doing some other things related to lighting. I have however determined to use one of the following solutions:
-
Use the âlots of lightsâ demo as a base and try to dynamically turn of lighting when player cannot see them, and also use the includedOnlyMeshes too to battle the lighting limit. However, Iâm currently using instancing to create my game map from pieces⊠And I have problems to get this working. Are there any limitations to this method using instances? If I change the lots of lights -demo to use instancing of spheres instead of cloning, only some spheres are litâŠ
See: https://playground.babylonjs.com/#WJWSNL#1
-
Use hemispheric light and add some stencil buffer âlightsâ to spice up the corridors. For example something like: Wind Waker Style Firefly Lights â polycount or Procedural Pixel Art Fire - YouTube ⊠Do you think these would be possible in Babylon?
-
Just give up lighting and paint shadows to textures. Such example is here (also using ambient occlusion): Break Room - 3D model by lampy (@lampysprites) [708c30f] - Sketchfab
Are there some limitations with the lights and their includedOnlyMeshes
property? I made a test to light the instance (sphere) with point light using includedOnlyMeshes
after two seconds and nothing happens. See: https://playground.babylonjs.com/#1FUKMR#4
If the original sphere is used, everything worksâŠ
Edit:
Digged into some code and found this:
Could someone explain what this means in laymans terms? If I have an instanced mesh, the lighting of it cannot be changed?
Hmmm, I see! But is it possible to not do this in the same tick? In my real project, I would like to create lights dynamically when I create the map from mesh pieces⊠So the scene has already been initialized, I just add stuff into it
Anyone having an idea why the instanced sphere doesnât update in https://playground.babylonjs.com/#1FUKMR#4 when created in setTimeout? Does this have to do with the picture I posted before, as in instanced meshes lights are coded in a way they do not update the lights afterwards?
Also, does anyone know if there are any plans for âarea lightsâ, such as in Unity. Here is a link to their docs, area lights are in the bottom of the page: Unity - Manual: Types of light
This thread has been split to Creating lights dynamically that effect instanced meshes with includedOnlyMeshes
Hi everyone!
Iâve been theorycrafting my use case a lot during these few months but I need some help to validate the âsolutionâ Iâm thinking of doing.
So, Iâm thinking of creating two versions of the texture, the âlights onâ and âlights offâ versions for each wall/floor mesh. Then, I would place an invisible sphere to each fake âlight sourceâ which would be the light radius. If the sphere exists, it would show the âlights onâ version of the mesh texture where it touches/intersects. If not, it would be the âlights offâ one. The other solution would be to not have a âlights offâ version of the texture, but just turn it a lot darker.
What would be the best action to make this kind of system. Iâve been thinking of playing with stencil buffer to somehow do this, or to dive into shaders a bit more⊠What do you guys think of this and what do you think would be the best course of action to do this?
If you are wondering about the use case and donât want to spend time reading everythingâŠ
I need some kind of ârealtimeâ lighting that would come from some sources, like walls. May not use real lights since they are too expensive. Canât bake lightmaps because the map is generated from mesh pieces dynamically.
I would like to build an electricity system in the game, where electricity source is connected to the âlampâ and if electricity turns off the light turns off. In the âsolutionâ earlier I wondered if I could do this by creating a sphere and showing different texture or darkened texture when the sphere is not enabled or it is shrinked. No idea if this would look good though, but is is an idea at least
I am wondering if you could generate two lightmaps one all lights on and one all lights off.
and then having a custom shader to fetch from the right texture depending on a custom attribute value ?
This is pretty cluncky but at least you could control each light independently per vertex without increasing your number of draw calls too much ?
Generating lightmaps would be nice but I plan to make the whole map from 2m x 2m mesh pieces, where the floor and walls are also in quite many pieces. So I would need to predict all the combinations and also there is the problem that I could not have large areas lit simultaneously⊠Or that is what I assume at least! Take the picture below as an example. Each square is a wall/floor piece. If the lamp is attached to the wall, it might lit things up to 4+ meters and cover many floor tiles⊠And of course there is the problem when we add other game objects like furniture in the mix⊠Oh boy what have I gotten myself into
But the lighting in this case would not need to be so realistic, since I am doing a pretty cartoonish game. So I am thinking of something like Zelda: Wind Waker style. Take the end result of this video for example: Unity: Luces volumétricas (Como en Zelda Wind Waker) - YouTube
There is the yellow light that in my case would be just the normal color of the âlights onâ texture, and then all the rest could basically be pitch black or just really darkâŠ
ohhhh that makes me think to something How many lights max do you have per mesh ?
I wonder if you could limit each mesh to include only the impactfull lights so that basically most meshes would fall under the max limit cause if they are lets say point light all the meshes would not be impacted by all the lights ?
Just thinking out loud here
Yeah, the problem with this is that the meshes are instanced and the big boss said that you cannot use includedOnlyMeshes
with instanced meshes, or that it only works with the main mesh? Creating lights dynamically that effect instanced meshes with includedOnlyMeshes - #2 by Deltakosh
Or so I at least understood So I canât just instantiate the wall piece and try to tinker with what lights it acceptsâŠ
Ohhhhh they are instanced as well so, yup I guess you d need a special trick
Yeap! Thatâs why I am currently interested in stencil buffer / shaders⊠But I would need someone wiser than me to tell me if it viable
@Panuchka, this is an interesting problem and I think I have an idea. Give me a little time to mock it up
Ok, @Panuchka, I think I have something that may work for you with some customization on your end. Basically what we have is this:
The scene is made of 4 instances of a plane with the original plane hidden. The textures on the plane are using the PBR lighting model and there is an environment light in the scene that is lighting the planes. They are all using the same shader that was applied to the source plane.
The âlightsâ are just meshes with an unlit material that are animating back and forth across the length of the planes. The environment light is also rotating every frame so that we can test all of the lights interacting correctly.
The red and green light on the planes is generated in the shader and uses the position of the meshes to determine where the light on any of the instances is rendered. Note that the shape of the light âcastâ from each mesh light is controlled by the procedure in the shader, the sphere casting a circular shape and the cylinder casting a line shape.
They are also respecting the normal map on the texture by casting more light on the surfaces that face the light and being culled from faces pointing away. The mask for this looks like this:
And the full shader for the effect looks like this:
I am using the world postion of the instance minus a vector3 that is pumped into the shader which is taken from each mesh light. This shader can handle two âlightâ inputs, but you can add as many as you want and performance will allow with their own path in the shader. I would suggest designing your assets to handle a couple of light sources and adding that number of inputs into your shader.
The way I would handle which lights and the light positions contribute to any instance would be to add some nulls or abstract meshes to your meshes that will cast your light. These are the positions you will feed to the shader. If you have a lot of lights to cast into your shader, you will want to set up an instance buffer to hold all the positions and distribute the positions of the closest lights to each instance.
The thing to note is that I am only using the X position of the mesh to drive the effect, but you could modify it to your needs. The important thing here is that we are using world positions to determine how far the light is from any pixel and the shape of the light cast is controllable in the shader.
The playground where you can see this in action is below. Feel free to ping me with any questions. And thanks to @sebavan for the interesting challenge!
Custom Lighting on Instances | Babylon.js Playground (babylonjs.com)