I’m trying to understand what’s going on with a shader.
I have a plane in a scene,
to which I apply the following shaders:
Vertex Shader
void main(void) {
vCorners = aCorners / vec2(width, height);
gl_Position = matrix_viewProjection * matrix_model * vec4(aPosition, 1.0);
position = gl_Position;
// affine correction
gl_Position /= gl_Position.w;
}
Fragment Shader
void main() {
vec2 UVs = vec2(vCorners.x, 1. - vCorners.y);
gl_FragColor = texture2D(uColorBuffer, UVs);
}
Line 6: gl_Position /= gl_Position.w;
is intended to correct affine aberration.
However, when the camera approaches the plane, it results in the plane being misplaced/transformed like so:
Whereas, it should be placed like this (as can be seen by removing line 6):
- What is happening?
- Why?
- How can it be corrected?
- Why didn’t I become a carpenter instead???
- Does god hate me?!?