vec4 partTranslate = texture(partValues, vec2(partIndex_translate, partSlot)); vec4 partRotate = texture(partValues, vec2(partIndex_rotate, partSlot)); // Grab the fourth translate component as scale. float s = partTranslate.w; partTranslate.w = 1.0; mat4 partMatrix = mat4( vec4(s,0,0,0), vec4(0,s,0,0), vec4(0,0,s,0), partTranslate ); 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); // How did my old one work? It did, with I think a nonstandard scaling of W that worked out in the end. // Switching to more conventional like http://www.songho.ca/opengl/gl_projectionmatrix.html // dvb1601 also take a look at http://csc.lsu.edu/~kooima/pdfs/gen-perspective.pdf for offset-perspective. //n /= 20.0; //xMore /= 20.0; //yMore /= 20.0; xMore /= eyePos / zNear; yMore /= eyePos / zNear; projectionMatrix = mat4(zNear / yMore, 0, 0, 0, 0, zNear / xMore, 0, 0, 0, 0, -(zFar+zNear)/(zFar-zNear), -1, 0, 0, -2*zFar*zNear/(zFar-zNear), 0); //partMatrix = partMatrix * rotter; mat4 viewMatrix = cameraMatrix * partMatrix; mat4 transformMatrix = projectionMatrix * viewMatrix; modelPosV = pos; vec3 t1 = rotateByQuaternion(pos, partRotate); worldPosV = (partMatrix * vec4(t1, 1.0)).xyz; viewPosV = (cameraMatrix * vec4(worldPosV, 1.0)).xyz; vec4 transformedPos = projectionMatrix * vec4(viewPosV, 1.0); gl_Position = transformedPos;