#version 410 uniform float yRatio; // height/width uniform float eyePos; uniform mat4 cameraMatrix; in vec3 pos; in vec3 col; in vec3 nor; in vec2 uv; // part attrs uniform sampler2D partValues; uniform float partIndex_color; // part transform, in four columns uniform float partIndex_xform1; uniform float partIndex_xform2; uniform float partIndex_xform3; uniform float partIndex_xform4; in float partSlot; out vec3 colV; out vec3 norV; out vec3 viewPosV; out vec3 worldPosV; out vec3 modelPosV; // position after transforming & stuff, before perspective. out vec2 uvV; void main(void) { // part matrix mat4 partMatrix = mat4( texture(partValues, vec2(partIndex_xform1, partSlot)), texture(partValues, vec2(partIndex_xform2, partSlot)), texture(partValues, vec2(partIndex_xform3, partSlot)), texture(partValues, vec2(partIndex_xform4, partSlot))); 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); mat4 viewMatrix = cameraMatrix * partMatrix; mat4 transformMatrix = projectionMatrix * viewMatrix; modelPosV = pos; worldPosV = (partMatrix * vec4(pos, 1.0)).xyz; viewPosV = (cameraMatrix * vec4(worldPosV, 1.0)).xyz; vec4 transformedPos = projectionMatrix * vec4(viewPosV, 1.0); gl_Position = transformedPos; colV = col; colV *= texture(partValues, vec2(partIndex_color, partSlot)).rgb; uvV = uv; norV = mat3(viewMatrix) * nor; }