Orient camera for ODS in game instead of in vertex shader
This makes it work more like regular 360 mode and is generally more compatible because it doesn't require the frustum culling workarounds which the GPU solution needs. In particular, this fixes frustum culling with newer sodium versions (which no longer use the vanilla intersection checking method) and fixes the clouds on modern Iris (which seems to be using a different shader program for clouds).
This commit is contained in:
@@ -9,10 +9,49 @@ uniform int direction;
|
||||
|
||||
const float eyeDistance = 0.14;
|
||||
|
||||
void orient(vec4 position, int orientation) {
|
||||
float z;
|
||||
if (orientation == 0) { // LEFT
|
||||
z = position.z;
|
||||
position.z = position.x;
|
||||
position.x = -z;
|
||||
} else if (orientation == 1) { // RIGHT
|
||||
z = position.z;
|
||||
position.z = -position.x;
|
||||
position.x = z;
|
||||
} else if (orientation == 2) { // FRONT
|
||||
// No changes required
|
||||
} else if (orientation == 3) { // BACK
|
||||
position.x = -position.x;
|
||||
position.z = -position.z;
|
||||
} else if (orientation == 4) { // TOP
|
||||
z = position.z;
|
||||
position.z = -position.y;
|
||||
position.y = z;
|
||||
} else if (orientation == 5) { // BOTTOM
|
||||
z = position.z;
|
||||
position.z = position.y;
|
||||
position.y = -z;
|
||||
}
|
||||
}
|
||||
|
||||
void orientInverse(vec4 position, int orientation) {
|
||||
if (orientation < 2) {
|
||||
orient(position, 1 - orientation); // LEFT and RIGHT flip
|
||||
} else if (orientation < 4) {
|
||||
orient(position, orientation); // FRONT and BACK are their own inverses
|
||||
} else {
|
||||
orient(position, (1 - (orientation - 4)) + 4); // TOP and BOTTOM flip
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Transform to view space
|
||||
vec4 position = gl_ModelViewMatrix * gl_Vertex;
|
||||
|
||||
// Undo the camera rotation, so we always apply our stereo effect looking in the same direction
|
||||
orientInverse(position, direction);
|
||||
|
||||
// Distort for ODS
|
||||
// O := The origin
|
||||
// P := The current vertex/point
|
||||
@@ -34,30 +73,8 @@ void main() {
|
||||
// Calculate the vector between O and T and finally move the vertex by that vector
|
||||
position -= vec4(distTO * sin(angOT), 0, distTO * cos(angOT), 0);
|
||||
|
||||
// Rotate for different cubic views
|
||||
float z;
|
||||
if (direction == 0) { // LEFT
|
||||
z = position.z;
|
||||
position.z = position.x;
|
||||
position.x = -z;
|
||||
} else if (direction == 1) { // RIGHT
|
||||
z = position.z;
|
||||
position.z = -position.x;
|
||||
position.x = z;
|
||||
} else if (direction == 2) { // FRONT
|
||||
// No changes required
|
||||
} else if (direction == 3) { // BACK
|
||||
position.x = -position.x;
|
||||
position.z = -position.z;
|
||||
} else if (direction == 4) { // TOP
|
||||
z = position.z;
|
||||
position.z = -position.y;
|
||||
position.y = z;
|
||||
} else if (direction == 5) { // BOTTOM
|
||||
z = position.z;
|
||||
position.z = position.y;
|
||||
position.y = -z;
|
||||
}
|
||||
// Rotate back into the correct cubic view
|
||||
orient(position, direction);
|
||||
|
||||
// Transform to screen space
|
||||
gl_Position = gl_ProjectionMatrix * position;
|
||||
|
||||
@@ -14,10 +14,49 @@ uniform int direction;
|
||||
|
||||
const float eyeDistance = 0.14;
|
||||
|
||||
void orient(vec4 position, int orientation) {
|
||||
float z;
|
||||
if (orientation == 0) { // LEFT
|
||||
z = position.z;
|
||||
position.z = position.x;
|
||||
position.x = -z;
|
||||
} else if (orientation == 1) { // RIGHT
|
||||
z = position.z;
|
||||
position.z = -position.x;
|
||||
position.x = z;
|
||||
} else if (orientation == 2) { // FRONT
|
||||
// No changes required
|
||||
} else if (orientation == 3) { // BACK
|
||||
position.x = -position.x;
|
||||
position.z = -position.z;
|
||||
} else if (orientation == 4) { // TOP
|
||||
z = position.z;
|
||||
position.z = -position.y;
|
||||
position.y = z;
|
||||
} else if (orientation == 5) { // BOTTOM
|
||||
z = position.z;
|
||||
position.z = position.y;
|
||||
position.y = -z;
|
||||
}
|
||||
}
|
||||
|
||||
void orientInverse(vec4 position, int orientation) {
|
||||
if (orientation < 2) {
|
||||
orient(position, 1 - orientation); // LEFT and RIGHT flip
|
||||
} else if (orientation < 4) {
|
||||
orient(position, orientation); // FRONT and BACK are their own inverses
|
||||
} else {
|
||||
orient(position, (1 - (orientation - 4)) + 4); // TOP and BOTTOM flip
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Transform to view space
|
||||
vec4 position = gl_ModelViewMatrix * gl_Vertex;
|
||||
|
||||
// Undo the camera rotation, so we always apply our stereo effect looking in the same direction
|
||||
orientInverse(position, direction);
|
||||
|
||||
// Distort for ODS
|
||||
// O := The origin
|
||||
// P := The current vertex/point
|
||||
@@ -39,30 +78,8 @@ void main() {
|
||||
// Calculate the vector between O and T and finally move the vertex by that vector
|
||||
position -= vec4(distTO * sin(angOT), 0, distTO * cos(angOT), 0);
|
||||
|
||||
// Rotate for different cubic views
|
||||
float z;
|
||||
if (direction == 0) { // LEFT
|
||||
z = position.z;
|
||||
position.z = position.x;
|
||||
position.x = -z;
|
||||
} else if (direction == 1) { // RIGHT
|
||||
z = position.z;
|
||||
position.z = -position.x;
|
||||
position.x = z;
|
||||
} else if (direction == 2) { // FRONT
|
||||
// No changes required
|
||||
} else if (direction == 3) { // BACK
|
||||
position.x = -position.x;
|
||||
position.z = -position.z;
|
||||
} else if (direction == 4) { // TOP
|
||||
z = position.z;
|
||||
position.z = -position.y;
|
||||
position.y = z;
|
||||
} else if (direction == 5) { // BOTTOM
|
||||
z = position.z;
|
||||
position.z = position.y;
|
||||
position.y = -z;
|
||||
}
|
||||
// Rotate back into the correct cubic view
|
||||
orient(position, direction);
|
||||
|
||||
// Transform to screen space
|
||||
gl_Position = gl_ProjectionMatrix * position;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
"Mixin_HideNameTags",
|
||||
"Mixin_HideNameTags_LivingEntity",
|
||||
"Mixin_Omnidirectional_Camera",
|
||||
"Mixin_Omnidirectional_DisableFrustumCulling",
|
||||
"Mixin_Omnidirectional_Rotation",
|
||||
"Mixin_PreserveDepthDuringGuiRendering",
|
||||
"Mixin_SkipBlockOutlinesDuringRender",
|
||||
|
||||
Reference in New Issue
Block a user