Pryme8 Posted June 22, 2018 Share Posted June 22, 2018 I am trying to understand the directional light shadow casting system a little more... and for some reason I can not make sense of the pg demo: http://www.babylonjs-playground.com/#R1EVD0#3 or the docs on it https://doc.babylonjs.com/babylon101/shadows. Could someone explain to me whats up with my scene here: https://www.babylonjs-playground.com/#WGTQ6E#19 I know it has to do with the lights shadow frustum, but Im not sure what to do. Light is created on line 329, and are added to the shadow system on line : 258 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 23, 2018 Share Posted June 23, 2018 In #3, I dunno HOW lightsphere is tracking light. No parenting, no renderLoop work. Just set once in line 12. It's as-if light has a secret .position onChangeObserver, and lightSphere is in its notifyListeners phone book. I think my eyes are bad, today. I can't see certain code. heh Other than that, a strange demo indeed. I know one interesting thing. In non-shadow situations, directionalLights don't need to have a .position. WITH shadows... they DO need a .position. (I hear.) The shadow NEEDS it. Why? Only The Shadow knows. I think we need a real-time shadow editor... with a bunch of sliders, just like that particle editor that's floating around. A shadows laboratory. Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 24, 2018 Share Posted June 24, 2018 @Pryme8 Is this any better? I can explain the docs if you like. But I'm not certain what you want to achieve specifically. Play with the values in lines 332-336, and I'm guessing you'll achieve what you want. If you want to light the left wall, then you need to add an exclusive light for that wall - unfortunately there's no other option from my experience. https://www.babylonjs-playground.com/#WGTQ6E#20 Your Bother (although you NEVER answer my calls!), DB Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 25, 2018 Author Share Posted June 25, 2018 On 6/23/2018 at 11:06 AM, Wingnut said: I know one interesting thing. In non-shadow situations, directionalLights don't need to have a .position. WITH shadows... they DO need a .position. (I hear.) Spot on. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 25, 2018 Share Posted June 25, 2018 We need a position to set the point of view to render the shadow map: http://doc.babylonjs.com/babylon101/shadows#directional-lights Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 25, 2018 Author Share Posted June 25, 2018 https://www.babylonjs-playground.com/#WGTQ6E#23 Still kinda drawing a blank of how this is supposed to work. Even when I place the light and set its direction to what should make sense it seems to still be really hard to predict the results. trying to make the directional light handle like a sun shadow caster. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 26, 2018 Author Share Posted June 26, 2018 https://www.babylonjs-playground.com/#WGTQ6E#30 So I simplified the scene and am still running into issues, it seems like the meshes are cast correctly to a ground plane; but the mesh its self shadowing is all sorts of screwy. Line 340+ is your point of interest. https://www.babylonjs-playground.com/#WGTQ6E#31 Also look at that z fighting on the ground next to the clipped sphere, some interesting fighting going in there. then when messing withe the sliders I noticed: Pretty sure a circle does not cast a shadow like that. The box we can excuse because of possible frustum clipping id assume, but the sphere does some loopy stuff. Maybe I should not use a directional light? Or are there errors in my setup? Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 26, 2018 Share Posted June 26, 2018 This is probably a setup issue but the scene code is pretty dense Here is a good list of stuff to check: http://doc.babylonjs.com/babylon101/shadows#troubleshooting Also I recommend using Spector.js here to see the content of the shadow map. This helps a lot positioning the light: But in your case as the sphere (which cast the shadows) intersect the plane (which receives it) it will be tricky to get a better shadow due to how directional lights work Wingnut and Pryme8 1 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 26, 2018 Author Share Posted June 26, 2018 https://www.babylonjs-playground.com/#WGTQ6E#34 the struggle is real... >_<, even with a point light. Ill check out the spector stuff when I get home, I have it there. ****Lunch Break update**** https://www.babylonjs-playground.com/#WGTQ6E#38 so even with spector, I am having trouble visualizing what is really happening. Its a lot getting closer, I just do not understand the mechanics behind the orthographic projection the directional light is doing... Also how the objects are receiving the shadows seems weird, which I am sure ties into all of this with the projection of the map. Some interesting behavior: https://www.babylonjs-playground.com/#WGTQ6E#39 When I nerf line 258 there is the zFighting again with the shadows and a mesh. You can see it if you move the camera out and pan around. What would cause that behavior? Quote Link to comment Share on other sites More sharing options...
Guest Posted June 26, 2018 Share Posted June 26, 2018 Tough to say with so much code ;( is the floor and the wall part of the same mesh? Because it could be a self shadow issue then. Did you play with bias? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Author Share Posted June 27, 2018 They are standard shapes like boxes created with meshbuilder parented to a empty container mesh. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2018 Share Posted June 27, 2018 We need to repro on a simpler scene because now it is a nightmare to debug internally with so much objects Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Author Share Posted June 27, 2018 https://www.babylonjs-playground.com/#WGTQ6E#42 I commented out all the fluff/complex elements. Stripped the CSG, out and left just 5 cloned blocks. the zfighting on the shadows is interesting. Line 143 is where the original meshes are created. Line 271 is where the floor block is cloned; Line 287 starts the wall clones; Line 259 is Shadow assignments. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 27, 2018 Share Posted June 27, 2018 So it is actually working I've got this rendering by hiding this guy (who is over the ground and does not receive shadows): Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Author Share Posted June 27, 2018 Yeah but whats up with that Z fighting of the shadow through the mesh that hid it? Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 It think it is more a general z fighting between ground and the mesh. You can try to set mesh.material.zOffset = 1? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 28, 2018 Author Share Posted June 28, 2018 https://www.babylonjs-playground.com/#WGTQ6E#44 Still some odd behavior, pretty much cant tell all the meshes to receive shadows because then nothing looks right. BUT the major thing is zFighting still, if you move the camera to a similar angle as shown below and pan around you should notice the bottom of those 4 blocks appear and disappear pretty oddly. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 This is because the ground is large and with only 4vertices so the depth interpolation is really large. It is not a big deal generally speaking but with shadows it is as we fight against the low precision of our textures https://www.babylonjs-playground.com/#WGTQ6E#45 See line #365 Pryme8 and dbawel 2 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.