correct glsl affine texture mapping

后端 未结 6 1345
一整个雨季
一整个雨季 2020-12-19 10:43

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

Explanation:

\"\"

...NONE of thi

6条回答
  •  无人及你
    2020-12-19 11:26

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

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

    Numbers and shader:

    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)]
    

    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);
    }
    

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

提交回复
热议问题