正确的glsl仿射纹理映射 [英] correct glsl affine texture mapping

查看:146
本文介绍了正确的glsl仿射纹理映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在GLSL中编写正确的2D仿射纹理映射代码.

i'm trying to code correct 2D affine texture mapping in GLSL.

说明:

...此图像均不符合我的要求.右(标记为正确")具有我不希望的透视校正.因此:了解Q纹理坐标解决方案(无需进一步改进)不是什么我在找.

...NONE of this images is correct for my purposes. Right (labeled Correct) has perspective correction which i do not want. So this: Getting to know the Q texture coordinate solution (without further improvements) is not what I'm looking for.

我想简单地在四边形内拉伸"纹理,如下所示:

I'd like to simply "stretch" texture inside quadrilateral, something like this:

但由两个三角形组成.有什么建议(GLSL)吗?

but composed from two triangles. Any advice (GLSL) please?

推荐答案

感谢您的回答,但经过试验后,我找到了解决方案.

thanks for answers, but after experimenting i found a solution.

根据,左侧的两个三角形具有uv(strq)和两个三角形右边是此透视校正的修改版本.

two triangles on the left has uv (strq) according this and two triangles on the right are modifed version of this perspective correction.

数字和着色器:

tri1 = [Vec2(-0.5, -1), Vec2(0.5, -1), Vec2(1, 1)]
tri2 = [Vec2(-0.5, -1), Vec2(1, 1), Vec2(-1, 1)]

d1 = length of top edge = 2
d2 = length of bottom edge = 1

tri1_uv = [Vec4(0, 0, 0, d2 / d1), Vec4(d2 / d1, 0, 0, d2 / d1), Vec4(1, 1, 0, 1)]
tri2_uv = [Vec4(0, 0, 0, d2 / d1), Vec4(1, 1, 0, 1), Vec4(0, 1, 0, 1)]

使用此glsl着色器仅渲染直角三角形(左侧是固定管线):

only right triangles are rendered using this glsl shader (on left is fixed pipeline):

void main()
{
    gl_FragColor = texture2D(colormap, vec2(gl_TexCoord[0].x / glTexCoord[0].w, gl_TexCoord[0].y);
}

所以..只有U是透视图,V是线性的.

so.. only U is perspective and V is linear.

这篇关于正确的glsl仿射纹理映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆