Dinkelborg Posted August 26, 2015 Share Posted August 26, 2015 Hi, has been a while however I started a new project using BabylonJS,where I'm importing a model from Blender into a scene,now for some reason I cannot get it to cast a shadow. I added a cube next to it and it does cast a shadow, I'm also adding both the cube and the model to the renderList of the shadow generator..Any ideas or suggestions what I could try or why it wouldn't work? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted August 26, 2015 Share Posted August 26, 2015 Hi, Maybe your light is not high enough. Quote Link to comment Share on other sites More sharing options...
Dinkelborg Posted August 26, 2015 Author Share Posted August 26, 2015 var spot = new BABYLON.SpotLight("Lamp",BABYLON.Vector3.zero,BABYLON.Vector3.zero,2.5,8,scene); spot.intensity = 1.75; spot.diffuse = new BABYLON.Color3(0.9, 0.8, 0.8); spot.angle = 5; spot.exponent = 8; spot.position = new BABYLON.Vector3(-17.6, 18.8, -49.9); spot.setDirectionToTarget(new BABYLON.Vector3(0, 0, 0));The Building is about 3 unity high as the cube floating next to it is at position.y = 3 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 26, 2015 Share Posted August 26, 2015 can you try with a directional one? Quote Link to comment Share on other sites More sharing options...
Dinkelborg Posted September 10, 2015 Author Share Posted September 10, 2015 I tried with a directional light and with a directional light I cannot cast any shadow at all, however when all mesh parts are kept separate, I can cast shadows with a spot light, but not with everything combined to one mesh Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 10, 2015 Share Posted September 10, 2015 Did you try to change the shadowGenerator.bias ? You can also try to display the debugLayer with scene.debugLayer.show() and use the [Dump rendertargets] button to see the content of the shadow maps Quote Link to comment Share on other sites More sharing options...
jellix Posted May 5, 2016 Share Posted May 5, 2016 I habe the same question now. It seems that my imported mesh (OJB) also doesn't cast any shadows while a simple box does. Quote Link to comment Share on other sites More sharing options...
lesterhaus Posted May 5, 2016 Share Posted May 5, 2016 Hey, Could you post the part of your code where you push the mesh (or meshes) into the shadowMaps renderList? Mostly dealing with .babylon imports - but I usually do this inside the callback of e.g. my SceneLoader like this: BABYLON.SceneLoader.Load(modelPath, modelName, engine, (scene) => { // Wait for textures and shaders to be ready scene.executeWhenReady( () => { for (var i = 0; i < scene.meshes.length; i++) { let mesh = scene.meshes[i]; shadowGenerator.getShadowMap().renderList.push(mesh); mesh.receiveShadows = true; } }); }); ariespranata and Steffen 2 Quote Link to comment Share on other sites More sharing options...
ariespranata Posted June 17, 2018 Share Posted June 17, 2018 Hi there, I think I have the same problem and still don't have the solution. Here's the Playground link The skull doesn't cast any shadow, while the sphere is fine. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 17, 2018 Share Posted June 17, 2018 Hiya ariespranata, welcome to the forum. Imported meshes make great BabylonJS shadows... but sometimes it takes a little adjusting. http://www.babylonjs-playground.com/#JUKXQD#19 For a moment, let's look at the #17 playground... lines 25-32: BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) { // Set the target of the camera to the first imported mesh camera.target = newMeshes[0]; shadowGenerator.getShadowMap().renderList.push(newMeshes[0]); //shadowGenerator.addShadowCaster(mesh); newMeshes[0].receiveShadows = true; // add stuff here // add stuff here // add stuff here }); This red area... is called the loader "onSuccess" callback function. Now look at the #19 playground. BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) { // Set the target of the camera to the first imported mesh camera.target = newMeshes[0]; var shadowGenerator = new BABYLON.ShadowGenerator(1024, light); shadowGenerator.useBlurExponentialShadowMap = true; shadowGenerator.useKernelBlur = true; shadowGenerator.blurKernel = 64; shadowGenerator.forceBackFacesOnly = true; shadowGenerator.getShadowMap().refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONCE; shadowGenerator.getShadowMap().renderList.push(newMeshes[0]); var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 20, scene); sphere.position.x = 50; sphere.position.z = 50; shadowGenerator.getShadowMap().renderList.push(sphere); newMeshes[0].receiveShadows = true; }); Notice how I placed MANY things that happened AFTER the onSuccess callback... INTO the callback function "block". When importing mesh using the sceneLoader, MOST of the JS code needs to happen INSIDE the callback function, and not after it. Later, you may wish to use the more-modern BabylonJS AssetsManager... to do your mesh loading. It is sometimes easier to understand and more efficient than sceneLoader. I hope I have been helpful. For fun, I tried to spin the spotlight around the skull, while keeping it aimed at the skull. http://www.babylonjs-playground.com/#JUKXQD#22 Fun! ariespranata 1 Quote Link to comment Share on other sites More sharing options...
ariespranata Posted June 17, 2018 Share Posted June 17, 2018 Thanks, Wingnut! you're a lifesaver. ? This is my first time using BabylonJS, I'll surely explore the AssetsManager. Btw, just in case anyone else having the same problem, my actual imported mesh is consists of many mesh(es). It was exported from 3ds Max as a group. Thus, instead of shadowGenerator.getShadowMap().renderList.push(newMeshes[0]); we should use: newMeshes.forEach(function (mesh) { shadowGenerator.getShadowMap().renderList.push(mesh); }); at first I thought BabylonJS would recognize my 'group' as 1 mesh, but apparently that's not how it's working. dreinzy and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 18, 2018 Share Posted June 18, 2018 Just for the sake of it, it is also now possible to call: shadowGenerator.addShadowCaster(mesh); Because, well, less code is better Wingnut, ariespranata and dbawel 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.