mousebird-consulting-inc / WhirlyGlobe

WhirlyGlobe Development
Other
831 stars 255 forks source link

MaplyShapeLinear clipping just above the horizon #1236

Closed 696GrocuttT closed 4 years ago

696GrocuttT commented 4 years ago

I've got an issue with MaplyShapeLinear not displaying properly when its above the horizon. However other shapes behave correctly. EG the code below should display a red ball at the end of a vertical line:

let s = MaplyShapeSphere()
s.radius = 100 / 6371000
s.height = 3000 / 6371000
s.color  = .red
s.center = MaplyCoordinateMakeWithDegrees(Float(jump.dzCoordinate!.longitude),
                                          Float(jump.dzCoordinate!.latitude))

var lineCoords = [ MaplyCoordinate3d(x: s.center.x, y: s.center.y, z: 0),
                   MaplyCoordinate3d(x: s.center.x, y: s.center.y, z: s.height) ]
let line = MaplyShapeLinear(coords: &lineCoords, numCoords: Int32(lineCoords.count))
line?.color = .yellow
line?.lineWidth = 10
addShapes([s, line], desc: nil)

If the view is tilted so everything is below the horizon, everything is displayed correctly and we get the screen shot below: IMG_0359

However if I change the tilt/zoom the top part of the MaplyShapeLinear disappears, as show below: IMG_0360 As I change the tilt / zoom / pan the point at which the line disappears stays just above the horizon.

This is a really cool framework, but my app will displays the flight paths of skydivers, so the line disappearing is a bit of a show stopper for me. Any idea what could be causing this?

Thanks

Tom

696GrocuttT commented 4 years ago

I've been doing a bit more digging and found something (possibly) interesting. The point at which the line disappears in just above the horizon for v2.6.1 and later. However if I step back to v2.6.0 the point at which it disappears is slightly below the horizon. Not sure if this helps narrow it down, but thought I'd mention it.

Tom

mousebird commented 4 years ago

Can you make a video of that?

696GrocuttT commented 4 years ago

You can download the video here: https://www.icloud.com/photos/#0WeudgBtncCTe6rG5-6GV1T0Q

mousebird commented 4 years ago

Looks like z buffer weirdness. Try setting the kMaplyZBufferRead to false for the addShapes call.

696GrocuttT commented 4 years ago

Just tried that, but unfortunately it doesn't fix the problem.

696GrocuttT commented 4 years ago

Disabling the Z buffer reads did change the rendering slightly, as the yellow line in now being rendered on top of the red ball (when its below the horizon).

IMG_0366

But its still clipping the line when above the horizon. IMG_0367

I've also tried playing around with the drawing priority, but that didn't fix it either.

mousebird commented 4 years ago

Are you drawing anything in the background?

mousebird commented 4 years ago

So this is probably the shader. By default the globe will use a shader that fixes backface problems on the globe with lines and other random stuff.

You probably want a shader that doesn't do that. If you put kMaplyShader: kMaplyNoBackfaceLineShader in the description dictionary. That might do it.

696GrocuttT commented 4 years ago

Adding kMaplyNoBackfaceLineShader fixed it :-)

Thanks for your help!!