Lib3d strange clipping happens only on actual hardware

Environment: Playdate SDK 1.13.2, Windows (simulator), also Playdate actual hardware.

I'm fiddling with lib3d and simple wireframe stuff for a potential mini-game.

Experimenting with having cubes here and there and wandering around in a field of them by moving the camera about.

Things were going dandy until I created and placed a cube well behind the camera (at game start camera is at 0,1.5,-10 orientation 90 degrees, unfriendly cube at -10,0,-20). On the simulator, things remain peachy. On the hardware, though, all cubes get clipped as though they had a face vertex behind the camera, even though they're well in front of the camera. I simplified things by commenting code out so as to be down to only two cubes... the unfriendly one, and another well in front of the camera (at world origin: 0,0,0).

When the program loads and begins its update cycle on the simulator, the cube at origin renders fine:

But when the program loads and begins its update cycle on the hardware, the cube at origin has faces clipped as if one or more face vertices were behind the camera (they're not):

It's even more strange looking when there are multiple cubes in the scene on hardware... moving the camera about so that all cubes are in front of the camera (even though some are offscreen) and any that are onscreen all render fine, but shift the camera about so that even one cube vertex is behind the camera and all of the cubes get the strange clipping, all at once.

It's as if there's only one actual set of cube vertices/faces that's being shared, and if one gets clipped then they all do. So I made sure that each node has their own set of vertices and faces (nothing shared) but that didn't make a difference. Neither does having the nodes setClosed true or false.

Looking at the code there is one (and I think only one?) difference between the runtime for the simulator and the hardware - looks like some conditional inline assembler optimization for square root:

I don't see how that would make a difference, but...?

Anyhow, I created a test case (attached). Playing with these five lines will produce the results described above. Comment out the cube at -10,-20 and the problem doesn't happen (unless you move the camera around so there's a vertex behind it).

	
    :
    CreateCube(0,0)
	--CreateCube(-10,0)
	--CreateCube(10,0)
	CreateCube(-10,-20) -- <--- this one when uncommented causes strange clipping for other cubes, as if they're also behind the camera
	--CreateCube(10,10)
    :

Of course, it's completely possible that I'm just doing something dreadfully wrong - going sort of by the seat of my pants on how lib3d works by looking through the source code, and I may just be making some bad assumptions. If so, though, those assumptions seem to work ok (I think?) on simulator but not on hardware.

lib3dTestCase.zip (688.0 KB)

I'm seeing this in the simulator too, thank goodness (so much easier to debug!), and I noticed that if I change ENABLE_Z_BUFFER to 0 the problem goes away. I couldn't tell you why but if you're just doing wireframe drawing you won't need to worry about depth sorting so both ENABLE_Z_BUFFER and ENABLE_ORDERING_TABLE can be turned off.

But now there's a new problem:

lines

Hm. I know I've fixed this problem before, but your render.c is up to date. Weird. Welp, here's a fix for that: render.c.zip (3.3 KB)

I'm surprised I never noticed that line overrun before. Thanks for pointing that out! (even if unintentionally :slight_smile:)

1 Like

That's great!

Thanks much :slight_smile:

1 Like