Problems with texture deformation in OpenGL ES 1.1 on quad made out of triangle strips

前提是你 提交于 2020-01-04 05:48:08

问题


I'm using triangle strips to create a quad. The problem is when I try to paint it using a rectangular texture that I want to have evenly interpolated over the shape.

As long as the shape is a rectangle or an affine transform of a rectangle, I'll have two identical triangles that build the shape and everything goes well. But with arbitrary shapes, the triangles have different shapes and a distortion naturally occurs along the common edge of the triangles.

   _____       ______       _____
  |     |     /     /       \   /
  |_____|    /_____/         \_/

    Ok         Ok           Not Ok

I imagine it would be fairly straightforward to work around this with custom shaders in ES 2.0, but how do I achieve it in ES 1.1?


回答1:


Put bluntly, the hardware can only do linear interpolation of texture coordinates if you don't provide it with perspective/depth information.

Linear interpolation does not allow to properly handle the case that causes you problems.

To have a proper interpolation on you edge, you have to introduce perspective information in your quad.

You should find more information in this NVidia whitepaper : Projective Texture Mapping.




回答2:


One way to map a square/rectangular texture to an arbitrary quad is projective interpolation. I've written an article showing how to do this. This focuses on the math for setting up the interpolation, while the "Projective Texture Mapping" paper linked in rotoglup's answer focuses configuring the API to do the interpolation.

The short version: you interpolate UVs across the quad in a way analogous to how GPUs do it for perspective-correct rendering (which, as you may have noticed, does not produce a visible seam between the two triangles). To do this, you need to calculate a false "depth" value for each vertex of the quad, and do the interpolation using homogeneous coordinates based on this "depth". Full details are in the article linked above.

I'm not sure what is and isn't possible in OpenGL ES 1.1, but if it supports projective texturing via supplying 3- or 4-dimensional UV values, then this should be applicable.



来源:https://stackoverflow.com/questions/4748900/problems-with-texture-deformation-in-opengl-es-1-1-on-quad-made-out-of-triangle

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