Open ghost opened 1 year ago
@VinhTruongAmbient Hm that's so strange with the weird grey box in the background in the second screenshot. Seems like it's failing almost every time on main now
I was able to reproduce this on my local Docker container which runs LLVMPipe. Investigating.
As a test I removed all entities, except for the camera and the decal. The result looks like this:
The gray box looks to be oriented by the decal, which makes sense. Removing orientation yields:
There seem to be two separate issues:
CubeMesh
to draw the context in which the decal is rendered. This CubeMesh
is actually twice as large in every dimension. The shader expects a cube with min=[-0.5,-0.5,-0.5], max=[0.5,0.5,0.5]
but our CubeMesh
is actually min=[-1.0,-1.0,-1.0], max=[1.0,1.0,1.0]
.extent=1
and extent=2
cubes are in play here. The green cube is the cube()
component, which is extent=1
or the "unit cube". However, the decals code uses the regular "cube", which defaults to the extent=2
cube, but thinks it's using the extent=1
cube. This confusion of cubes caused the mismatch between the two.get_decal()
in decal shader calls discard;
if the projected point does not land inside the unit cube. This is incorrect because in this case the fragment never gets written. So the gray background just happens to be some uninitialized render target data.Working on a fix.
The uninitialized render target explains the random behavior we have seen in the CI.
Looks like the discard theory doesn't tell the whole story. This bug actually happens on my Mac too, you just had to change the clear color from black to something else:
We should change our default clear color to something else than pitch black. Helps reveal bugs like this.
Fixed in https://github.com/AmbientRun/Ambient/pull/473.
A summary of the problem:
extent=1
, but instead got a cube of extent=2
. This was caused by confusion about the two ways to define a "unit cube" inside the engine. This issue actually helped to reveal the more fundamental problem about the shader which is:screen_normal_quat
render target. The correct behavior is to discard;
these pixels.
Expected image:
This test usually passes, but every once in a while this image gets rendered instead:
This started happening after #440, but only on Github Actions. On M2 Max the decals example works as expected.