#version 410 uniform float yRatio; // height/width uniform float eyePos; uniform mat4 cameraMatrix; in vec3 pos; in vec3 col; out vec3 colV; // ramped color from vertex color out vec3 viewPosV; // gl_Position gets final projected coordinate // flatShader2 is a highly-reduced shader, in particular: NO PART ATTRIBUTES, so it can handle // vast geometries ok. void main(void) { colV = col; float yRatioScaler = yRatio < 1.0 ? 1.0 : yRatio; float xMore = yRatio / yRatioScaler; float yMore = 1.0 / yRatioScaler; float zFixer = -150.0; // we flip & compress Z for the final depth write. Our world is all in RHS, negative Z from screen. Device is +Z. // matrix is actually transpose of how it "looks" here... mat4 projectionMatrix = mat4(xMore, 0, 0, 0, 0, yMore, 0, 0, 0, 0, 1.0 / zFixer, -1.0 / eyePos, 0, 0, eyePos/ zFixer, 0); viewPosV = (cameraMatrix * vec4(pos, 1.0)).xyz; vec4 transformedPos = projectionMatrix * cameraMatrix * vec4(pos, 1.0); gl_Position = transformedPos; }