Sign in to follow this  
fenomas

Lights and light.range and max lights per mesh

Recommended Posts

Hi, quick questions. 

I have a big scene (500+ meshes), over a reasonably large area, which uses octrees. My use case is, I'd like to add many short-range point lights to the scene - think fireflies - that have a small "range" property and thus only affect a small number of meshes. In other words, the scene would have more than 4 lights, but each mesh will be lit by fewer than 4 lights.

My questions:

  1. Is it correct to assume that a light's range property does not interact with the "4 lights per mesh" limitation? In other words, if I add a point light with range=1 to my scene, every mesh in the scene is "lit" by that light even if they are far away, right?
     
  2. It looks like the correct/only way to do what I'm asking for is to add meshes to each light's includedOnlyMeshes array. Is this right?
     
  3. Is it correct to assume that includedOnlyMeshes doesn't know about octrees or parent/child relationships? In other words, if I want a point light to only affect the meshes in a particular octree, I need to add all those meshes to the light's includedOnlyMeshes array, and their children, right?

Thanks!

Share this post


Link to post
Share on other sites

I see nothing involving the .range of a light where they get bound.  There is a _lightSources property of AbstractMesh.  It can updated in.  I would look into that first, cause I am not sure when / if this gets called.

IncludeOnlyMeshes for each light seems like another way to go.  If it helps, the max can also be changed at the material level. 

One thing I do is attach a point light to a camera, which moves / rotates to match the light to the camera in a scene.beforeCameraRender.  This can really reduce the number of lights needed in the first place.  Does a part of the scene really need to have a light when it is not on the frame.

Share this post


Link to post
Share on other sites

1. Unfortunately no. The range is used to compute the quantity of energy received but not to remove a mesh from a light's activeMeshes list (mainly because the cost to evaluate to distance to the mesh is prohibitive)

2. Correct

3. Correct

More about how lights are tied to meshes here: 

https://github.com/BabylonJS/Babylon.js/blob/master/src/Lights/babylon.light.ts#L406

 

Share this post


Link to post
Share on other sites

 canAffectMesh in link from @Deltakosh (where the includedOnlyMeshes is evaluated) is in done in a loop of this.getScene().lights, so you need to make sure that lights with the includedOnlyMeshes are early in the array or all the slots could get filled up with lights that are too far away.

Share this post


Link to post
Share on other sites

Thanks folks, I think I have the general idea..

Lots o' lights: https://playground.babylonjs.com/#WJWSNL  :D 

 

Follow up question for @Deltakosh:

If a light has an includedOnlyMeshes array, and all of the included meshes are not rendered (e.g. due to frustum culling), that light won't have any performance impact on the scene since it's not bound to any meshes, right?

Or in other words, if I maintain an accurate list of included meshes for a light, I assume there's no need to disable the light when its outside the view frustum?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.