Diego
Diego

Reputation: 615

WebGL: missing triangles when moving camera

I am rendering a complex scene in WebGL (180 meshes) corresponding to a car model (Nissan GTX) car. However when I move the camera around , it seems as if triangles were missing far,

These 'missing triangles' seem to jump randomly over the surface. Can this be a depth buffer problem or a normal calculation problem? I have no idea.

Nevertheless, if I zoom-in near the surface of the model, all triangles are there zoom.

Does anyone have had this problem? any tips?!

Upvotes: 1

Views: 919

Answers (2)

ryanm
ryanm

Reputation: 3009

You might be right when you suspect a depth-buffer problem - the fact that the distance to the camera affects things suggests it could be a buffer precision problem. Check out the answer to this question for a possible solution.

Upvotes: 1

Christian Rau
Christian Rau

Reputation: 45948

I guess, you have a wireframe mesh directly on top of (or very near) a solid mesh and this is just a depth buffer problem. It works when zooming in, because the depth buffer precision is higher in the near area of the viewing frustum.

Try adjusting the screen space depth by working with the polygon offset (or a similar fragment shader modifying gl_FragDepth) when rendering a wireframe overlay directly on top of the solid mesh. Or just move them farther away in object space.

Upvotes: 4

Related Questions