Jump to content

Imported blender object always has light source


styxxx
 Share

Recommended Posts

Hi,

 

I noticed that the .babylon-files of blender models always have some light in the rendered result but there is no light specified in the babylon file. When I disable all light light sources in the scene (either by code, using the browser console or the debug gui) everything wents dark as expected - except for the blender objects. There's even a specular effect. I disposed all lights so now scene.lights is "[]" according to the browser console. 

For example the "hexagon" below. I even modified it with an editor and removed the ""lights":[]," part. Did I miss something? I'm not talking about the emissive color of course, the object is supposed to "glow" a bit, but turnig of lights has no effect at all and as I mentioned I can see specular effects on the surface from some directed light source. I made the same mesh with pure javascript code before, the values are the same and it works there. 

I have to post the file content below since I get an error message when trying to attach/upload it, sorry.

 

hex_simple.babylon

You aren't permitted to upload this kind of file

{"autoClear":true,"ambientColor":[0,0,0],"materials":[{"name":"hex_simple_full.Material.002","id":"hex_simple_full.Material.002","ambient":[0,0,0],"diffuse":[0.7,0.7,1],"specular":[0.3,0.3,0.5],"emissive":[0.5,0.5,0.7],"specularPower":64,"alpha":0.7,"backFaceCulling":true,"checkReadyOnlyOnce":true, "diffuseTexture":{"name":"hexa2_rot.png","level":1,"hasAlpha":1,"coordinatesMode":0,"uOffset":0,"vOffset":0,"uScale":1,"vScale":1,"uAng":0,"vAng":0,"wAng":0,"wrapU":1,"wrapV":1,"coordinatesIndex":0} }],"multiMaterials":[],"skeletons":[],"meshes":[{"name":"6 - Hexagon","id":"6 - Hexagon","materialId":"hex_simple_full.Material.002","billboardMode":0,"position":[0,0,0],"rotation":[0,0,0],"scaling":[1,1,1],"isVisible":true,"freezeWorldMatrix":false,"isEnabled":true,"useFlatShading":false,"checkCollisions":false,"receiveShadows":false,"positions":[-0.25,0,0.433,-0.5,0,0,-0.25,0,-0.433,0.25,0,0.433,0.25,0,-0.433,0.5,0,0],"normals":[0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0],"uvs":[0.5,0.9999,0.0671,0.75,0.0671,0.25,0.9329,0.75,0.5,0.0001,0.9329,0.25],"indices":[0,1,2,3,0,2,3,2,4,3,4,5],"subMeshes":[{"materialIndex":0,"verticesStart":0,"verticesCount":6,"indexStart":0,"indexCount":12}],"instances":[]}],"cameras":[],"activeCamera":"Camera","shadowGenerators":[]}

You can see the difference in the attached screenshots (I changed the emissiveColor to (0.1,0.1,0.1) in both cases for better visibilty). There are also some other blender objects that all seem to have some light. Where does it come from? 
Also turning off textures in the debug gui doesn't seem to have effect on all of them which is weird too.

Edit: the darker image is using hexagons made via code (BABYLON.Mesh.CreateDisc) the other one is using an imported blender model of the same object (the code above). Lights are disabled in both cases.

post-17067-0-69284100-1448491948_thumb.p

post-17067-0-67457900-1448491950_thumb.p

Edited by styxxx
Link to comment
Share on other sites

Okay, there is more weird stuff going on with imported blender meshes. I now also disabled all textures but they're mostly still there (except for bump maps and emissive). You see the strange pattern on the plane? Happens when I disable "diffuse textures". That's actually the diffuse texture image of the space ship. Those (the floor and the ships) are totally different models they don't share a file, a name or something else (the floor tile meshes are named "disc-[number-x]-[number-y]", the ships are called "ship something"). The floor tiles are the hexagons I posted above.

Happens only to imported models. So I guess there's something happening when being imported.
Again you can also see some light reflecting.
Also happens with babylon 2.3.

 

edit: It's not just the floor: Every imported mesh is now rendered with this texture unless I reactivate diffuse texure channels. Neither was it the first nor the last texture (or mesh/texture file pair) that was loaded from file. 
The skybox doesn't seem to lose it's texture at all though (it was created with code, not imported).

screenshot103.png

Link to comment
Share on other sites

Hi again,

 

I made a demo file to show the effects I'm talking about  ^_^ 

http://styxxx.de/temp/babylon/blender/blenderlights.html     (zip file to download: http://styxxx.de/temp/babylon/blender/blenderlights.zip)

I created 6 boxes, the first two are made with BABYLON.Mesh.CreateBox, the other 4 are imported from ".babylon" files:

1. A box with a simple material, some diffuse, specular and a very dark emissive color (so it's still visible without light source). Created with BABYLON.Mesh.CreateBox. No textures.
2. Like the first box but with an additional diffuse and bump texture (the same file for both). 

The blender-generated babylon-files:
3. A box similar to box 1: just some colors (diffuse, specular, a little bit emissive). No texture.
4. A box with colors and additional diffuse texture
5. Colors + diffuse texture + bump texture
6. Colors + diffuse texture + bump texture + emissive texture

The scene also has one light source. The babylon files don't have any specified. 
By clicking on any box the light intensity is set to a random value. So you can play around with it. 

Now let's take a look at the debug options or the console an the effects some actions have:

  1. Disable lights:
    The first two boxes are now dark, except for the emissive color. But the 4 imported boxes still receive some light. You can also see specular effects. 
    The same effect can be created by using the console and manually setting scene.lightsEnabled to false. Or by disposing the light source with "scene.lights[0].dispose()."
     
  2. Change the intensity value or the color of the light source (with console):
    Works for all objects as expected as long as "scene.lightsEnabled" is true (or disabled in the debug menu).
    If not: nothing happens until you reactivate the light source. 
    For example:
    "scene.lightsEnabled=false; scene.lights[0].intensity=0.1;" -> blender objects are still illuminated with intensity=1; (or whatever it was before) then enter
    "scene.lightsEnabled=true;" -> illumination drops to 0.1;
     
  3. debug layer: texture channels -> disable "Diffuse":
    The diffuse texture of the imported objects now change to the crater texture of box #2.
    Diffuse textures are still shown. 
     
  4. debug layer: texture channels -> disable "bump":
    A smilar effect to the one before but this time the bump texture of the imported box #5 changes.
    But not for the last box: no changes here. 
     
  5. debug layer: texure channels - > disable "emissive":
    Objects with an emissive texure (only box #6 in this example) start to glow like a christmas tree because also this time the texure seems to be swapped ;)
     
  6. debug layer: options -> disable "textures":
    Only affects the non-imported meshes again.

So as you can see imported meshes aren't treated like the others. :)

While playing I also noticed differences on how the boxes are rendered in blender and in babylon. For example the bump maps are way more visible in babylon as if not only the normals are manipulated. But I'm not sure about that. Also the color values vary (are darker in babylon) and some options seem to be ignored like the blending mode for textures (mix, add, screen, multiply, etc). I guess that's simpley not exported by the babylon exporter. Also the value on how much the bump textures have influence doesn't seem to be included in the .babylon-file (or I'm just blind). [edit: The specular effects are also rendered differently on the imported boxes, aren't they?] So no big issues but while I'm at it I wanted to note too.


Would be nice if someone took a look at it to confirm.  ;) 
Thanks.

Link to comment
Share on other sites

Sorry, I could not really follow the space ship stuff.  I picked up with the cubes example.  This all about materials.

 

Cube 1's material has no ambient component / channel.  The cube 3 from Blender does, and there are other differences as well.  It was good you got a simple example, but if you got the exact same material settings in the .babylon to match your hand code, the color should be the same.  If not then there is a fileLoader error.  To insure you get the material you wish, set the controls according to this picture.

 

StdMaterials.png

 

The entire manual is @ https://github.com/BabylonJS/Extensions/tree/master/TowerOfBabel

Link to comment
Share on other sites

Hello,

 

you can ignore the post about the ship since the cube example is better ;)
The materials are different, I know. It wasn't primarily about the same color, but the effects you get when deactivating some options. While making this demo file I just also noticed that there might be differences (mostly with the specular effect). I'll take a closer look at it. Until then the isssue with the "eternal" light source and textures are more important. I guess something's happening while the meshes are imported that places them kind of "outside" the world. Can't describe it better. 

Try deactivating the light source in the example :)  Should only affect the meshes that weren't imported. At least it's the case on my machine.

Link to comment
Share on other sites

Ha! I found something:

http://styxxx.de/temp/babylon/blender/blenderlights2.html Here's another example. This time I used the exact same values that were defined in the blender file of cube #3 for cube #1 (babylon-code). Now the first cube also doesn't respond as expected to option changs. So what's different? It's this:

box_material.checkReadyOnlyOnce = true; 

Exported blender models always have this value defined in the blender file by the exporter. The default value for newly generated standardMaterials with js code is "false". I thought this value would be ignored anyway (I read it in some post) but I guess it changed. 

So this is responsible for most of the noticed strange behavior. I'm not sure if this is supposed to be this way. Using the wrong texture for a mesh looks like a bug no matter what's defined there. I'd expect no changes at all with this option set to true. But I'm not even sure what it really is about. And do I gain performance by setting it to false? 

There's stil something odd: The imported cube and the code-generated are still rendered differently. The specular effect and the lighting varies. #1 and #3 should look the same since the same values are set. So I guess the default values for some attributes are different for new standardMaterials and for materials of imported meshes? Or is this something about the normals? The "specular dot" is the most noticable.
 

 cubes1-3.png

 

edit: Solved this too :D The culprit is:

"useFlatShading":false

How do I define this with code-generated models (like "createBox" and "new BABYLON.StandardMaterial)?

Would still be awesome if a developer could take a look into the behavior when checkReadOnlyOnce is set to false to check if it is as supposed to be. After that I guess I can mark this problem as solved.  :rolleyes:


edit:
"Debug layer > Options > Textures" still has a weird effect with not disabling all textures as you would expect. Bump textures stay.

Link to comment
Share on other sites

So:)

 

  • checkReadyOnlyOnce is a dangerous tool: it helps with performance by freezing the shader but can leads to weird results if you change the material afterwards or if you share the material with different meshes. (This is why it is off by default). I suggest never using this unless you have deep knowledge of how it works under the hood:)

 

 

  • About the debugLayer>Textures this is a stupid bug of mine :)

 

 

Link to comment
Share on other sites

I have better plans for using checkReadyOnlyOnce, packaged along with allowing the material namspace to be something other than the filename, on a material by material basis.  This way you could selectively share materials across .blend's, e.g.. a shared 'GreenEyed' material in the 'pool' namespace, 'pool.GreenEyed'.  The current decision is to set it to true, when there is only 1 mesh user of it (baked materials are of course single user).  Need to add another custom exporter properties section on the Materials tab, and not done this yet.  I kind of doubt this is the cause of the difference though.  It is probably either the normals, or the light placement relative to the cubes.

 

Flat shading can also be ordered up from the Mesh properties of the exporter.  If checked, FileLoader / Mesh.Parse runs convertToFlatShadedMesh() for you.  Would like to change that to be implemented in the exporter instead, if I have time.  2 ways of doing normals is already in the script.  It would load faster doing it in the export, and Shape Keyed Meshes could be flat shaded.  Redoing everything in BJS without also doing the Shape Keys destroys them.

 

I want to have the new version out by xMas.  I am just getting all the big changes (variable bone influencers 1-8, vertex optimization while having a skeleton, shape key redo) a real good test using a BJS motion capture tool.  If styxxx needs something before I am ready, and he thinks it will fix his spot issue, he need only delete 2 lines starting here, https://github.com/BabylonJS/Babylon.js/blob/master/Exporters/Blender/io_export_babylon.py#L1760.  This is open source, everybody is a developer.

Link to comment
Share on other sites

Hi,

 

thank you :)

What about 

checkReadyOnEveryCall

Didn't notice any effect by changing this option. I guess it still checks the state but when if not on every call? 

I also don't know why all my exported models have set the checkReadyOnEveryCall option in their babylon files. I haven't set anything in blender as far as I know. Or is this the standard behavior by the exporter?


About the flat shading:
When the babylon files contain "useFlatShading":true it's rendered exactly as the code generated models that weren't converted with convertToFlatShadedMesh (at least the cubes are). So shouldn't the ones made with createBox (and without convertToFlatShaededMesh) rendered as smooth as the imported ones? 


 

Link to comment
Share on other sites

Regarding checkReadyOnEveryCall, it should be off by default but can be turned on if you need to update your material many times per frame

Did this change? Because it's false on babylonjs-playground but always true in my example files (although I didn't set it), using v2.2.0.

Like here (output on console): http://styxxx.de/temp/babylon/blender/blenderlights2.html

Thanks :) 

 

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