Jump to content

Lights, includedOnlyMeshes and maxSimultaneousLights :


gryff
 Share

Recommended Posts

Well, I've been experimenting with lights and meshes and exporting lights from Blender with includedOnlyMeshes. And I have even created a playground for experimenting with :o

5lights Playground

Basically the scene has 5 lights : a Hemi illuminating everything, and 4 coloured lights each illuminating a single mesh directly below it. I did this using the Blender Babylon Exporter(BBE)'s ability to export includedOnlyMeshes.

The scene loads fine into the PG. But I want to change the includedOnlyMeshes for the green light to include the floor mesh and get the scene to look like the image below.

My attempts at coding are in the PG above. No errors are thrown and I print out to the console the includedOnlyMeshes.length for the green light before and after i update the array - and the array is updated but there is no change in the appearance of the scene. (I even disable the green light before making changes and then re-enable the light.)

The code for maxSimultaneousLights is included as this is just a simple example for testing. The real scene will have 10-12 lights that I will need to do this for.

So either the code I have written is useless or it is something that can't be done.

Any help appreciated :)

cheers, gryff :)

endresult1.png

Link to comment
Share on other sites

1 hour ago, aWeirdo said:

but i'm clueless as to why it lights the entire plane green :P

Perhaps it is the type of light that is used, for example a directional light would light the whole floor.

Adding a spotlight restricts the range of the light on the floor.

http://www.babylonjs-playground.com/#1VXBNJ#8

Link to comment
Share on other sites

@aWeirdo & @JohnK Thank you for the response gentlemen. I'd been working on the more complex version 10 lights and the plane is named "floor" in that scene. That is what happens when I spend too much time testing my limited coding skills:wacko:

However, both the playgrounds you guys posted though still seem to be weird  - will think about it some more

cheers, gryff

Link to comment
Share on other sites

Well I took @JohnK's example and played with the Spotlight he added.

Lights PG

Now I have changed the parameters of the spot light:

1. Position - x,y,z values are all set to 10000 - so a long way away from the meshes in the scene

2. Direction set to <0,1,0> - pointing up and away from the meshes

3. Reduced the light  intensity to 0.001 and the diffuse colour to black.

And it still seems to work as I hoped.

If I disable the light (line27) we are back to @aWeirdo's result with green light flooding the whole Plane.

So what is the impact of this extra light on the scene?

Goes off for a 2nd cup of coffee ...

cheers, gryff :)

 

Link to comment
Share on other sites

Hey team!

regarding this PG: http://www.babylonjs-playground.com/#1VXBNJ#7

By default the green light has a mesh in its includedOnlyMeshes list: this means that ONLY ONE mesh is affected by this light.

The line #33 enable the ground to also be included in this list.

 

Here is the predicate used to know if a light can reach a mesh: https://github.com/BabylonJS/Babylon.js/blob/master/src/Lights/babylon.light.ts#L128

Link to comment
Share on other sites

7 minutes ago, Deltakosh said:

By default the green light has a mesh in its includedOnlyMeshes list: this means that ONLY ONE mesh is affected by this light.

@Deltakosh : and that mesh is the Cylinder. The code (lines 31 & 32) then adds the "ground" to that list. 

But the result is complete flooding of the "ground" with a green colour. The ground is 20x20 units

That green light is a Point Light with a range of 5 placed at [-5,4,-5] (.babylon co-ords). It is just above the Cylinder  - so why is the whole plane flooded?

cheers, gryff :)

Link to comment
Share on other sites

@JCPalmer : TY for the idea Jeff - but all materials are like this:

"name":"lights5_5.cone","id":"lights5_5.cone","ambient":[0.8,0.8,0.8],"diffuse":[0.64,0.64,0.64],"specular":[0.5,0.5,0.5],"emissive":[0,0,0],"specularPower":50,"alpha":1,"backFaceCulling":true,"checkReadyOnlyOnce":false,"maxSimultaneousLights":4

It is basically a simple Blender scene with just the sphere, cone etc each having their own layer and a light  with "this layer only" checkedfor each light.

@JohnK : I may need more than coffee by the end of this day :unsure:

cheers, gryff :)

Link to comment
Share on other sites

3 hours ago, JCPalmer said:

but the scene is so simple I would try to do it without a blend.

@JCPalmer a good thought Jeff. So I tried it - an even simpler scene just a sphere and the ground with a hemi and a point light. The size of the meshes and the properties of the lights are basically the same. Only difference is that the sphere mesh and the point light are not positioned in the lower left corner. The small cube can be clicked to add the ground to the green pointlight's includedOnlyMeshes

Constructed Playground

It works fine - so what does that mean? :huh:

And I tried it locally with "BABYLON.SceneLoader.Load" instead of "BABYLON.SceneLoader.Append". Get the same issue.

cheers,gryff :)

Link to comment
Share on other sites

It means that the problem is in something that is done with Fileloader, or a property of the point light set from the .babylon affects it. 

The exporter sets many things on lights.  Next thing to isolate would be to ensure anything in the .babylon not in your working PG gets removed.  Not all at once.  With WordPad.  If is does not start working before you run out of stuff to delete, it is how FileLoader processes.

FYI, Load is just a 2 step wrapper for Append.  Create a new scene, and call Append with it.

Link to comment
Share on other sites

@JCPalmer Jeff, I was ahead of you about removing stuff, and the fact that the whole ground plane was being flooded with light suggested I start with the imported Hemi light.

New Hemi

I disabled the imported hemi lines 18 & 19. Then created a new hemi locally lines 24-26.

And it seems to work fine :)

And what does that tell us?

cheers, gryff :)

Edit : Here is the code for the Hemi light that gets imported from the .babylon file :

{"name":"Hemi","id":"Hemi","type":3,"direction":[0,1,0],"groundColor":[0,0,0],"intensity":0.2,"diffuse":[1,1,1],"specular":[0,0,0]}

 

Link to comment
Share on other sites

@JohnK : yes it will work - but now all the meshes (cube, cone, sphere, cylinder) also have no light from the Hemi.

5 Lights at the same time

Here is what I was trying to achieve the yellow Hemi (a new Hemi) and the 4 coloured point lights.

The 4 point lights , one for each mesh, all light the floor so total of five lights illuminating the floor. And each mesh feels the effect of the Hemi (yellow).

Don't no what it is that BJS dislikes about that Blender Hemi light :unsure:

cheers, gryff :)

 

Link to comment
Share on other sites

  • 2 weeks later...
On 2016-11-02 at 11:13 AM, JCPalmer said:

So it looks id, groundColor, and specular are set in the JSON file, but not when you manually create one.  When they are deleted, does the exported hemi still behave the same way?

@JCPalmer: Yes Jeff .

I've spent quite a few hours trying stuff - but the only thing I can come up with is that somehow the light illuminating the floor ends up taking some of its properties from another light in the .babylon file - in fact the first light in the lights[] array. Here are some playgrounds and the corresponding lights array code from each .babylon file:

 

1. The Purple Light:

And from the .babylon file :

"lights":[{"name":"point_purple","id":"point_purple","type":0,"position":[5,4,5],"range":5,"intensity":4,"diffuse":[1,0.0018,0.825],"specular":[0,0,0],"includedOnlyMeshesIds":["Cube"]},{"name":"point_blue","id":"point_blue","type":0,"position":[5,4,-5],"range":5,"intensity":4,"diffuse":[0.0032,0.0063,1],"specular":[0,0,0],"includedOnlyMeshesIds":["Cone"]},{"name":"point_green","id":"point_green","type":0,"position":[-5,4,-5],"range":5,"intensity":4,"diffuse":[0,1,0.0051],"specular":[0,0,0],"includedOnlyMeshesIds":["Cylinder"]},{"name":"point_red","id":"point_red","type":0,"position":[-5,4,5],"range":5,"intensity":4,"diffuse":[1,0.0021,0.0021],"specular":[0,0,0],"includedOnlyMeshesIds":["Sphere"]},{"name":"Hemi","id":"Hemi","type":3,"direction":[0,1,0],"groundColor":[0,0,0],"intensity":0.4,"diffuse":[1,1,1],"specular":[0,0,0]}],

 

2. The Green Light

And from the .babylon file:

"lights":[{"name":"point_green","id":"point_green","type":0,"position":[-5,4,-5],"range":5,"intensity":4,"diffuse":[0,1,0.0021],"specular":[0,0,0],"includedOnlyMeshesIds":["Cylinder"]},{"name":"point_purple","id":"point_purple","type":0,"position":[5,4,5],"range":5,"intensity":4,"diffuse":[1,0.0018,0.825],"specular":[0,0,0],"includedOnlyMeshesIds":["Cube"]},{"name":"point_blue","id":"point_blue","type":0,"position":[5,4,-5],"range":5,"intensity":4,"diffuse":[0.0032,0.0063,1],"specular":[0,0,0],"includedOnlyMeshesIds":["Cone"]},{"name":"point_red","id":"point_red","type":0,"position":[-5,4,5],"range":5,"intensity":4,"diffuse":[1,0.0021,0.0021],"specular":[0,0,0],"includedOnlyMeshesIds":["Sphere"]},{"name":"Hemi","id":"Hemi","type":3,"direction":[0,1,0],"groundColor":[0,0,0],"intensity":0.4,"diffuse":[1,1,1],"specular":[0,0,0]}],

 

So I thought I would force the first light in that array to be the "Hemi" from the babylon file.

3. The Hemi

"lights":[{"name":"Hemi","id":"Hemi","type":3,"direction":[0,1,0],"groundColor":[0,0,0],"intensity":0.4,"diffuse":[1,1,1],"specular":[0,0,0]},{"name":"point_purple","id":"point_purple","type":0,"position":[5,4,5],"range":5,"intensity":4,"diffuse":[1,0.0018,0.825],"specular":[0,0,0],"includedOnlyMeshesIds":["Cube"]},{"name":"point_blue","id":"point_blue","type":0,"position":[5,4,-5],"range":5,"intensity":4,"diffuse":[0.0032,0.0063,1],"specular":[0,0,0],"includedOnlyMeshesIds":["Cone"]},{"name":"point_green","id":"point_green","type":0,"position":[-5,4,-5],"range":5,"intensity":4,"diffuse":[0,1,0.0051],"specular":[0,0,0],"includedOnlyMeshesIds":["Cylinder"]},{"name":"point_red","id":"point_red","type":0,"position":[-5,4,5],"range":5,"intensity":4,"diffuse":[1,0.0021,0.0021],"specular":[0,0,0],"includedOnlyMeshesIds":["Sphere"]}],

 

So it seems like the first light in the lights[] array is being used for the diffuse colour and the intensity of the lighting for the floor plane.

If you look in the console window the Plane is being assigned to each point light but is ignored. And if you activate line 18 and rem out line 26 - so that the Hemi from the .babylon file is replaced by the Hemi added in the script - they all work fine.

I don't know what is going on - my code, BJS, or the exporter - but it is very, very frustrating.:o

cheers, gryff :)

Link to comment
Share on other sites

The point of that exercise was to only set those things in the .babylon that you were hand coding.  Since the .babylon still does not behave the same way as hand coding, it looks like the loading process is the cause.  Do not think it has anything to do with either the exporter or the .babylon output.  .babylon file looks "legal".

You may not recognize the loading process is an actual "thing", but when one object requires another object in a .babylon file yet they can appear in any order in the file, the loading process has some juggling to do.  Have not looked, but suspect there is a bug there.

Link to comment
Share on other sites

@JCPalmer: Jeff, I understand that the loading process is important and goes beyond just having the correct syntax in the .babylon file. The process will involve timing and the order of loading objects.

I thought originally it could be a PG thing - but I get the same results locally.

1 hour ago, JCPalmer said:

but suspect there is a bug there.

"Bug" is not a favourite word of mine - as it has always seemed to me that it is a word that can annoy coders . :unsure: I prefer the word "issue", so,  is this an issue that you and @Deltakosh can sort out relatively easily? Or should I look for a workaround ?

cheers, gryff :)

Link to comment
Share on other sites

On 2016-11-14 at 1:49 PM, Deltakosh said:

Could you just reduce the pg to the barely minimum info that can highlight the issue?

@Deltakosh : Well that suggestion opened a can of worms - will try to explain later when I get the issue straight in my mind. In the meantime :

New Five Lights

All the PG code does now is load the .babylon file, set the # lights that can illuminate the floor to 16, then add the floor to the included meshes for each light.

No need for adding a Hemi in the code.

cheers, gryff :

 

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

Could you describe the bug?

@Deltakosh : I don't know whether it is a bug or not :o

So I will start by describing what I am trying to do. The scene has 5 lights - a Hemi that illuminates everything including the floor, and 4 other meshes which each are illuminated by the Hemi and their own coloured light (so two lights for each of the meshes). There is one additional mesh - a tiny cube at the centre of the scene that acts as the "target" for the ArcRotate camera called "Cube.target". It gets illumination from the Hemi.

The aim of the code is to make the 4 coloured lights also illuminate the floor - so it is illuminated by all five lights.

So, as I said,  your request to "reduce the pg to the barely minimum " opened up a can of worms.:lol:

 I started  by building a new .blend file with a basic ArcRotate Camera setup. Then, I added the floor plane illuminated by a Hemi and one mesh (sphere) with its own coloured light then exported it. When I added code to now added that coloured light to illuminate the floor - it worked fine!! :) So I added a second mesh/coloured light, exported and again it worked. So I added a third and then a fourth mesh/coloured light. Everything worked!!  I was back to to the five lights arrangement. (See my last post above for New Five Lights link).

So I now had two .blend files with five lights - one did not work, the other did. I repeated this with meshes and lights in the same positions as the file that was not working - and again it worked.

New Five Lights

So I looked at the .babylon files exported from the working and problem file. Lights, camera and materials were the same - the difference was in the meshes array:

1. File that works: meshes[(Cone),(Cylinder),(Cube),(Sphere),(Plane),(Cube.target)]

2. Problem file: meshes[(Cube.target),(Cone),(Cylinder),(Cube),(Sphere),(Plane)]

Note the difference is the position of the "Cube.target" mesh in the meshes array.

So back to Blender and the problem file - I deleted all the meshes except the "Cube.target" mesh and saved the file. I then reopened it and added back all the meshes (in the same order) and their materials and re-exported. Now the problem file worked too!!!

Old Five Lights Fixed

It seemed more and more that "Cube.target" mesh was an issue in some way  - so I loaded the original problem file and converted the camera to a free camera and deleted the "Cube.target" mesh and exported and again it worked just fine.

FreeCamera 5 lights

So I have two questions in my mind:

1. Why does the position of "Cube.target" in the meshes array make a difference?  Is there something about the name itself which is causing the issue or is it as @JCPalmer says, " the loading process has some juggling to do "

2. And then why does adding a new Hemi as suggested by @JohnK make it all work?

Right now, I know that I have to be careful setting up a .blend file with an ArcRotate camera and lights when I want play around with includingmeshes.

cheers, gryff :)

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...