ShadowGenerator issue with physical objects

Hello there,
Something weird is going on with the shadows. It looks like its quality goes to 0 over time.
It looks like it has something to do with the moving objects, as if you comment out the lines #271

rigidVehicle = addRigidVehicle({
  position: {
    x: 8,
    y: 6,
    z: 0,
  },
});

it looks ok

But with this rigidVehicle doing it’s thing (flying to the edge of the universe :flying_saucer: - I don’t know what is going on, I think it’s because of the differences between cannon and cannon-es, it works locally with my cannon-es) after few seconds it’s easy to see that’s it getting worse and worse

Here is the PG:

It’s also visible at the demo
https://neu5.github.io/cannon-es-debugger-babylonjs/
You just need to start driving by pressing WSAD and wait few seconds

That’s because the light frustum used for shadow computation is based on meshes that can cast shadows. You have a mesh that is going away as time is passing, so this frustum is always expanding, lowering the shadow quality.

You should either remove this mesh from the shadow caster list or use a cascaded shadow generator. Using the latest:

2 Likes

Thanks! That’s it! :slight_smile:
I hoped that I had made easy to fix mistake :melting_face:

Btw. @RaananW you can take a look at this demo too, as it’s basic rigidVehicle with cannon-es and it flieeees :rocket: into space :wink:

1 Like

Love it! thanks for sharing :slight_smile:

@RaananW I have w hunch that you didn’t get it :smile:
The flying rigidVehicle is not intentional! It shouldn’t fly! :slight_smile:
The same code works well with cannon-es as you can witness here
https://neu5.github.io/cannon-es-debugger-babylonjs/
And cannon makes rigidVehicle fly into the space :comet:

ha. I just loved the visuals :slight_smile:

Was away for a week, just came back. I’ll see if I can see why things fly into space
Just wanted to note, that a simple solution would be to change the car into a space rocket, and then you get exactly what you wanted to achieve!!! :upside_down_face:

1 Like

It might be related to the fact that the original cannon’s up vector is z, which was changed in cannon-es. The Rigid Vehicle might have some references to the up vector internally

1 Like