Jump to content

Shadow woes.


Pryme8
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:
image.thumb.png.2cec5388b88176fe48f0fa4fcd71410d.png

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? 

 

Link to comment
Share on other sites

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:

image.png

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.
 

Link to comment
Share on other sites

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.

image.thumb.png.b4445359c398f23191f381c7c1a2efc1.png

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