Hi,
I have worked with ThreeJS in the past and now decided to try BabylonJS because I like the features much better, but I can’t get my lighting to work well.
Here I have an example of a lowpoly blender model that I imported into a scene with a directional and ambient light.
When I created it in three js it looked like the one on the left. I have now tried to recreate this in BabylonJS, and it turned out like the one on the right:
ThreeJS code:
let scene = new THREE.Scene();
scene.background = new THREE.Color( 0xffffff );
let camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 500 );
camera.position.set( -1, 0.5, 1 ).setLength( 15 );
camera.lookAt( 0, 0, 0 );
scene.add( camera );
let light = new THREE.DirectionalLight( 0xfff9bc, 0.75 );
light.position.set( 1, 2, 1 ).setLength( 10 );
scene.add( light );
let ambient = new THREE.AmbientLight( 0xaf7ede, 0.5 );
scene.add( ambient );
new THREE.GLTFLoader().load( "assets/blender/pillar.glb", ( model ) => {
let gltf = model.scene.children[0];
let material = new THREE.MeshPhongMaterial( { color: 0x2a2a2a, flatShading: true, shininess: 0, specular: 0x000000 } );
let mesh = new THREE.Mesh( gltf.geometry, material );
scene.add( mesh );
} );
BabylonJS code:
let scene = new BABYLON.Scene( render.engine );
scene.clearColor = new BABYLON.Color3( 1, 1, 1 );
scene.ambientColor = new BABYLON.Color3( 0.5, 0.5, 0.5 ); //ambient intensity?
let camera = new BABYLON.ArcRotateCamera( "Camera", Math.PI / 4, (Math.PI / 8) * 3, 15, new BABYLON.Vector3( 0, 0, 0 ), scene );
camera.fov = 50 * (Math.PI / 180);
let light = new BABYLON.DirectionalLight( "DirectionalLight", new BABYLON.Vector3( -1, 2, 1 ).normalize().scale( -10 ), scene );
light.diffuse = new BABYLON.Color3.FromHexString( "#fff9bc" );
light.specular = new BABYLON.Color3( 0, 0, 0 );
light.intensity = 0.75;
BABYLON.SceneLoader.LoadAssetContainer( "assets/blender/", "pillar.glb", scene, function( container ) {
let gltf = container.meshes[1];
gltf.material = new BABYLON.StandardMaterial( "Material" );
gltf.material.diffuseColor = new BABYLON.Color3.FromHexString("#2a2a2a");
gltf.material.specularColor = new BABYLON.Color3( 0, 0, 0 );
gltf.material.ambientColor = new BABYLON.Color3.FromHexString( "#af7ede" );
scene.addMesh( gltf );
});
(I also tried HemiLight for the ambient, but it also didn’t work. Also, BabylonJS doesn’t render the lowpoly mesh correctly (“flatShaded”), I tried convertToFlatShadedModel but that resulted in displaced vertecies.)
My question is, what did I do wrong? how can I make it look like the ThreeJS scene?
Thanks