Hey there!
Following discussions at How to keep buffers on the GPU when using compute shaders for instancing or vertex data generation - #10 by Evgeni_Popov I found what could be a bug with shadows when generating the vertex data on the GPU.
In this PG, I am creating a procedural mesh with compute shaders. If the keepDataOnGPU
is set to true, the vertex data stay on the GPU and I set the mesh vertex data using the GPU buffers directly. If it is set to false then the vertex data is sent to the CPU to be bound with the mesh there.
What’s weird is that when keepDataOnGPU
is true and there is a shadow generator, the mesh appears black, whereas it is correctly shaded when keepDataOnGPU
is false.
Any idea what could be happening?
Interesting! What browser and OS are you using? I’m not able to repro on Chrome / MacOS, but I can on Chrome / Windows.
MacOS, keepDataOnGPU = true:
Windows, keepDataOnGPU = true:
1 Like
I am running Chrome on Ubuntu, so it looks like it works only on Macos 
The problem is that the terrain mesh does not have any bounding info when you define the vertex buffer directly. In the “non-GPU” case, you pass the actual coordinates of the vertices to applyToMesh
, which allows the method to calculate the bounding info.
You must manually define the bounding info in the “GPU” case for this to work:
The bounding info is needed because directional light calculates the X and Y extensions of the light frustum by traversing all meshes and retrieving the bounding box coordinates to do so. At least, that’s what happens when autoUpdateExtends == true
, which is the default value. You can set it to “false”, in which case the bounding info is no longer needed, but you will need to set the orthoLeft
/ orthoRight
/ orthoBottom
/ orthoTop
properties of the light with some appropriate values:
3 Likes
Note that the output on MacOS is also incorrect; the shadows are not generated correctly. The output should be:
The output is “less wrong”, as it seems that NaN values are not handled the same way in the shader code.
4 Likes
Oh that makes sense! Thanks for looking at my problem 