Computergrafik
Projektionsmatrix
← Augenkoordinaten | ● | MVP Matrix →
Simulation der perspektivischen Projektion als 4×4 Matrix:
- Projektion ist
- zuerst ∗n
- gefolgt von ∗1−pz
- Multiplikation mit n entspricht uniformer Skalierungsmatrix S.
S=(n0000n0000n00000)
- Zusätzlich wird eine perspektivische Division durch −z benötigt. Dies wird durch die homogene Koordinate w=−z erreicht. Bei der Dehomogenisierung wird durch w geteilt, also durch −z. Daraus ergibt sich das −1 Element in folgender Projektionsmatrix P:
P=(n0000n0000n000−10)
Normalisierte Projektionsmatrix:
- Normalisierung der x- und y-Koordinaten (∗2w bzw. ∗2h)
- mit w=r−l=2⋅tan(fovy/2)⋅aspect
und h=t−b=2⋅tan(fovy/2) - Tiefe z soll erhalten bleiben
- Z-Werte im Bereich [-near,-far] werden auf [−1,1] normalisiert
- Z-Puffer Algorithmus kann Überdeckung entscheiden
MP=(2nw00002nh0000−n+ff−n−2fnf−n00−10)
Die normalisierte Projektionsmatrix bildet das pyramidenförmige View-Frustum auf die sog. Clip-Koordinaten ab. Diese umfassen einen sichtbaren Würfel im Bereich der Koordinaten von −1 bis 1. Alles außerhalb dieses Würfels ist unsichtbar und wird geclippt.
Hinweis: Für die uniforme Projektionsmatrix ist w=h=2.
Berechnung via GLM bzw. LGL:
Perspektivische Projektion:
float fovy = 60;
float aspect = (float)width() / height();
float near = 1;
float far = 100;
mat4 P = mat4::perspective(fovy, aspect, near, far);
float aspect = (float)width() / height();
float near = 1;
float far = 100;
mat4 P = mat4::perspective(fovy, aspect, near, far);
Sonderfall orthographische Projektion / Parallelprojektion:
float aspect = (float)width() / height();
mat4 P = mat4::ortho(-aspect, aspect, -1.0, 1.0, -1.0, 1.0);
mat4 P = mat4::ortho(-aspect, aspect, -1.0, 1.0, -1.0, 1.0);
← Augenkoordinaten | ● | MVP Matrix →