开发者

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

开发者 https://www.devze.com 2023-02-05 13:15 出处:网络
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.

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 tri开发者_开发百科angles.

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

    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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号