I have a slight problem with shadows and shadermaterial.
The shadow at the top is the only that’s visible unfortunately, but other meshes’ shadows are ok.
Somehow the shadows for the shadermaterial meshes move with the camera, I’m guessing it’s because I have a line that is dependent on the camera’s position. So how do I know when the shadow is rendering so I can set the camera position uniform to the shadow camera?
Your light may not be positioned correctly to be able to generate shadows for all objects.
You should use the inspector to see where your light is located and to display the light frustum (if using a directional light: “Display frustum” in the “DEBUG” section of the light). Your shadow casters/receivers should be in the frustum.
1 Like
when I opened the inspector they became as distorted as the shadows:
And I don’t see “Display frustum” anywhere in the Debug or general sections.
The “display frustum” button is on the light object (when the light is a directional light), so you need to locate your light under “Nodes” and navigate to it.
Anyway, I think we will need a repro at some point, as it seems you are facing some strange things (your meshes should not be distorted when opening the inspector…).
I fixed the distorting problem, sorry about that. But I still don’t see the button
You should scroll at the bottom in the right pane:
ok wait I think I need to update my version real quick
Ah yes, it is in the preview release. If you use the latest stable release you won’t have it.
Ok thanks I got it now. I enabled the frustum and saw this:
The objects in the scene (apart from the sphere in the middle) are raymarched. The meshes that contain them have ok shadows when I turn backface culling off and transparency off:
But when I turn on them back on I see that the shadows, which are meant to have transparent areas, have them but move with the camera like in the first screen shot, and this:
It’s hard to diagnose as if your are doing raymarching it means you are doing custom shadow map generation… Do you have a repro somewhere so that we can have a better look?
I will get it on github soon.
The main file that runs everything and creates the objects → src/Game.js
The file where the objects’ class is → src/planet/Planet.js
The file where the ray marcher is → src/planet/shdr/PlanetMarcher.glsl
Sorry, there are little to no comments as of now, I’ll take time to comment it.
Still hard to see what’s going on as the project can’t be run…
However, I think the problem is because your starting object is a sphere and you modify it in the fragment shader to look like cubes with holes. But to generate the shadow map the depth values are generated from the vertex shader, so from a sphere geometry: the changes in geometry done in the fragment shader are not accounted for.
Maybe one way to overcome this problem would be to use a standalone shadow wrapper (see Shadows | Babylon.js Documentation for more information on standalone wrappers) and have your fragment shader for this standalone wrapper writes the depth itself (in the r component of gl_FragColor
- should be a linear depth value between 0 and 1). You would also need to add a return;
statement after writing to gl_FragColor
so that the code injected by the wrapper is not run (else it will overwrite your value).
1 Like
Thanks for referring me to the shadows documentation, I really should have read it fully before coming here. Anyway this is the current state of it:
The shadows are working but theres still a small problem, the shadows are showing like they’re the abs of an axis:
I’ve not yet tried the standalone shadowdepthwrapper but this is where I am