surfaces got broken when object is far away in iphone

别来无恙 提交于 2020-01-07 04:23:07

问题


I am using the opengl es to display objects.

when the object is near to the camera, everything is perfect. but if the objects are moved faraway from the camera, the surface of objects would break.

The broken objects will be like:

the code snippet of draw objects is:

glVertexPointer(3, GL_FLOAT, 32, self.vertices);
glNormalPointer(GL_FLOAT, 32, &(self.vertices[3]));
glTexCoordPointer(2, GL_FLOAT, 32, &(self.vertices[6]));    

glDrawElements(GL_TRIANGLES, self.indexNumber, GL_UNSIGNED_SHORT, &(self.faces[0]));

I guess the reason could be the precision of float number.

Anyone have a solution for this? thanks


回答1:


The problem is depth-buffer precision.

Depth values are scaled such that closer objects have a greater range of possible depth values than those further away. Distant objects are therefore more likely to exhibit z-fighting and other such problems. See question 12.070 in this FAQ.

The near and far frustum planes should always be set to be as close together as possible: i.e.: the near plane should be as far from the camera as possible while still being closer than the rendered object, and the far plane should be as close as possible while still being further away than the rendered object.

It looks like you're just rendering the one object - find the nearest and closest points on that object, add a bit of padding for safety, and use those values for the near and far planes.

If you have to render a scene with objects both in the distance and the foreground and you run into similar problems you can split the rendering into two phases. First render the distant objects with appropriate near and far values, then clear the depth buffer and render the foreground objects with their own appropriate near and far values.



来源:https://stackoverflow.com/questions/5449943/surfaces-got-broken-when-object-is-far-away-in-iphone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!