Hi. I’m trying to make a distorted shader for GUI
The shader works fine if the there is only one image in a texture, but when there is a second image the shader doesn’t function well, due var_texcoord0.x < 0.5
is no longer the center of the image
My question, is there anyway to tell if vertex is in the on the right / left part of the box?
uniform highp mat4 view_proj;
// positions are in world space
attribute mediump vec3 position;
attribute mediump vec2 texcoord0;
attribute lowp vec4 color;
varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;
void main() {
var_texcoord0 = texcoord0;
var_color = vec4(color.rgb * color.a, color.a);
vec3 pos = position;
float xSkew = 0.0;
float ySkew = position.z;
pos.z = 0.0;
if (var_texcoord0.x < 0.5) {
ySkew = -ySkew;
}
mat4 transform = mat4(
1,xSkew,0,0,
ySkew,1,0,0,
0,0,1,0,
0,0,0,1);
gl_Position = view_proj * transform * vec4(pos.xyz, 1.0);
}