[SOLVED] Need help with my vertex shader code
Posted: Mon Feb 10, 2020 7:07 pm
I'm trying to do a 2d perspective transformation using a vertex shader. Similar to the image below:
I'm currently using this shader code to try and achieve this effect:
where texSize is {game_width, game_height}. When I draw a playing card in the middle of the screen it appears like this:
I'm very new to vertex shaders so I'm not sure what I'm doing wrong here. I'm trying to make the card look like a trapezoid shape as if it was a card sitting on a table. If someone can help me with this shader code or direct me to some kind of examples/tutorial for vertex shaders I would greatly appreciate it.
I'm currently using this shader code to try and achieve this effect:
Code: Select all
extern vec2 texSize;
number lerp(number a, number b, number t) { return a * (1.0 - t) + b * t; }
#ifdef VERTEX
vec4 position(mat4 transform_projection, vec4 vertex_position) {
vertex_position.x += lerp(-50, 50, vertex_position.y / texSize.y);
return transform_projection * vertex_position;
}
#endif