Best way to create part of a mesh that acts as a light source

Hi all!

My question is pretty short. I would like to achieve this kind of lighting in my scene.
Reference image is from Star Trekish ship :slight_smile:

0cf3a7e2afe46d1a98f64720967ca858

As you can see, the light in that picture comes from bottom and top lights that are not exact points. The other requirement that I have is that the lights can be turned on and off easily and dynamically. For example, there could be light flickering to make the scene a bit spooky!

I have already familiarized myself with the glow layer (Making Meshes Glow | Babylon.js Documentation), but I wonder if that can actually be used to emit any light to it’s surrounding meshes. So, do you pros around here have any advice on my problem? :sunglasses:

1 Like

This is vast and very interesting topic!
Just to be short.
First of all, any 3D scene actually is just illusion; the artist/programmer task is to make it as realistic as possible - in this case with Babylon methods.
Second. There is limitation how much lights you can use simultaneously - not more than 4 lights.
Third. Every light puts a load to the engine, too much of them and FPS will drop. Less lights = better optimization.
Fourth. Emissive texture + Glow layer is very powerful instrument. In combination with other textures it gives infinite possibilities to create stunning dynamic visual effects.

For the scene depicted in your image I would use no lights at all (at least not more than one light). Anyway you need some environment for PBR materials - so this environment will be actually the only light source in this scene. All other lights could be simulated with emissive/glow combination (one can add particles as option). Use lightmaps for the shadows - it will have realistic look and it is much simpler load for the engine than shadow generator.

Check this 9-lines demo with only 1 light and no environment texture at all - it is so simple!.
https://playground.babylonjs.com/#U5SSCN#110

2 Likes

Thank you for your answer, was really thought inspiring! :sunglasses:

Glow layers surely seem to be the way to go for visual appeal. However, lightmaps are a bit harder to do for the game I’m currently prototyping. There are few problems that prevent the use of it (or at least I think there are):

  • Spaceship is made from dynamic wall/floor/door 3d pieces. Makes harder for baked maps.
  • Characters and 3d items (boxes or things that player grabs) should project some kind of shadow.
  • You should be able to turn of lights from certain parts of the ship, so they need to be dynamic (or do the shadows need to be dynamic? :smiley:)
  • There are windows in some rooms of the spaceship that illuminate the light from nearby sun, mixed with regular lighting inside the ship.

So the big question is, I guess, to how to create this illusion if I can’t use many lights :thinking:

1 Like

Hi. Simple small answer. You cant do what you need without magik. And if serious you need lightmaps in any way because your lighting is very complex and no way recreate this with any webgl engine… in Babylon max 4 lights source for shader.
But you can do this magik.
Pbr material + Lightmsps + ambient occlusion + emissive with glow layer like unreal bloom in post process + ambient light + 1 hemisphere light with shadow generator like sun + light probes + real time environment map for reflections + something like clearCoat make this magikal soup. You can create lightmaps sprite for light animation and many other magical stuff. everything depends on the specific task and without knowing the task it is impossible to solve it correctly. what prevents you from baking light into modules like doors?
I am afraid that without theory you cannot do anything. for a start, you just need to understand that behind the scenes your magic kitchen in which you brew a magic potion stupefies the player’s mind.

2 Likes

Note that 4 is the default max number of simultaneous lights, but you can raise this value with material.maxSimultaneousLights.

3 Likes

Here is one of my projects - Mu-so Qb 2nd Generation - 3D Demo
In order to achieve “realistic” or even “better than realistic” view there were used: Glow, Sheen, ClearCoat, imageProcessingConfiguration.
Glow is dynamic (look at logo).
No lights at all, except environment.
The source is open, one may use any part of it.
On the rear panel of the model there is blinking LED - possible solution for the light flickering in your scene.

1 Like

A Lot of Lights demo - Babylon.js Playground

1 Like

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?

1 Like

Thread resurrection commence :slight_smile:

I’ve been doing some other things related to lighting. I have however determined to use one of the following solutions:

  1. 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… :thinking: See: https://playground.babylonjs.com/#WJWSNL#1

  2. 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?

  3. 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… :grimacing:

Edit:
Digged into some code and found this:
image
Could someone explain what this means in laymans terms? If I have an instanced mesh, the lighting of it cannot be changed? :exploding_head:

modified code so that after 2 seconds only the sphere is lighted

2 Likes

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 :grinning_face_with_smiling_eyes:

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? :slight_smile:

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

Adding @Evgeni_Popov to double check as he is the instances king :slight_smile:

1 Like

This thread has been split to Creating lights dynamically that effect instanced meshes with includedOnlyMeshes

1 Like