I'm trying to create a four corner perspective effect using vertex shader and fragment shader.
I set the vertex position infos to draw a perspective like shape, then map my texture on it. But somehow the texture is not correctly mapped.
Here are two pictures to show you the problem.
I find some infos from this post that texture2DProj
maybe the right answer, but I don't quite understand how it works. I tried to do something like this,
varying lowp vec4 TexCoordOut;
uniform sampler2D Texture;
void main(void) {
gl_FragColor = texture2DProj(Texture, TexCoordOut);
}
And for the TexCoordOut
I pass in
{1, 0, 0, 1}
{1, 1, 0, 1}
{0, 1, 0, 1}
{0, 0, 0, 1}
to vertex shader, and varying it into fragment shader. But the result is the same.
I only know how to use texture2D
with vec2
, how can I get the other two components of my texture coordinates to use them with texture2DProj
?