diff --git a/src/main/java/com/replaymod/render/capturer/IrisODSFrameCapturer.java b/src/main/java/com/replaymod/render/capturer/IrisODSFrameCapturer.java index 0f581d99..6671d80a 100644 --- a/src/main/java/com/replaymod/render/capturer/IrisODSFrameCapturer.java +++ b/src/main/java/com/replaymod/render/capturer/IrisODSFrameCapturer.java @@ -129,7 +129,7 @@ public class IrisODSFrameCapturer implements FrameCapturer { @Override protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) { direction = captureData.ordinal(); - return super.renderFrame(frameId, partialTicks, null); + return super.renderFrame(frameId, partialTicks, captureData); } } } diff --git a/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java b/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java index c0ec8c3d..925257fe 100644 --- a/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java +++ b/src/main/java/com/replaymod/render/capturer/ODSFrameCapturer.java @@ -160,7 +160,7 @@ public class ODSFrameCapturer implements FrameCapturer { @Override protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) { directionVariable.set(captureData.ordinal()); - return super.renderFrame(frameId, partialTicks, null); + return super.renderFrame(frameId, partialTicks, captureData); } } } diff --git a/src/main/java/com/replaymod/render/mixin/Mixin_Omnidirectional_DisableFrustumCulling.java b/src/main/java/com/replaymod/render/mixin/Mixin_Omnidirectional_DisableFrustumCulling.java deleted file mode 100644 index f174e0a3..00000000 --- a/src/main/java/com/replaymod/render/mixin/Mixin_Omnidirectional_DisableFrustumCulling.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.replaymod.render.mixin; - -import com.replaymod.core.versions.MCVer; -import com.replaymod.render.hooks.EntityRendererHandler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -//#if MC>=10800 -import net.minecraft.client.render.Frustum; -//#else -//$$ import net.minecraft.client.renderer.culling.Frustrum; -//#endif - -//#if MC>=10800 -@Mixin(Frustum.class) -//#else -//$$ @Mixin(Frustrum.class) -//#endif -public abstract class Mixin_Omnidirectional_DisableFrustumCulling { - //#if MC>=11500 - @Inject(method = "isAnyCornerVisible", at = @At("HEAD"), cancellable = true) - //#else - //$$ @Inject(method = "intersects", at = @At("HEAD"), cancellable = true) - //#endif - public void intersects(CallbackInfoReturnable ci) { - EntityRendererHandler handler = ((EntityRendererHandler.IEntityRenderer) MCVer.getMinecraft().gameRenderer).replayModRender_getHandler(); - if (handler != null && handler.omnidirectional) { - // Note the following used to be true but for simplicity non-ODS omnidirectional is the same now too. - // Normally the camera is always facing the direction of the omnidirectional image face that is currently - // getting rendered. With ODS however, the camera is always facing forwards and the turning happens in the - // vertex shader (non-trivial due to stereo). As such, all chunks need to be rendered all the time for ODS. - ci.setReturnValue(true); - } - } -} diff --git a/src/main/resources/assets/replaymod/iris/ods/shaders/gbuffers_textured_lit.vsh b/src/main/resources/assets/replaymod/iris/ods/shaders/gbuffers_textured_lit.vsh index 3b53c589..68e7e0fb 100644 --- a/src/main/resources/assets/replaymod/iris/ods/shaders/gbuffers_textured_lit.vsh +++ b/src/main/resources/assets/replaymod/iris/ods/shaders/gbuffers_textured_lit.vsh @@ -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; diff --git a/src/main/resources/assets/replaymod/shader/ods.vert b/src/main/resources/assets/replaymod/shader/ods.vert index 43160450..6a654a6b 100644 --- a/src/main/resources/assets/replaymod/shader/ods.vert +++ b/src/main/resources/assets/replaymod/shader/ods.vert @@ -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; diff --git a/src/main/resources/mixins.render.replaymod.json b/src/main/resources/mixins.render.replaymod.json index ba783acd..092aa958 100644 --- a/src/main/resources/mixins.render.replaymod.json +++ b/src/main/resources/mixins.render.replaymod.json @@ -14,7 +14,6 @@ "Mixin_HideNameTags", "Mixin_HideNameTags_LivingEntity", "Mixin_Omnidirectional_Camera", - "Mixin_Omnidirectional_DisableFrustumCulling", "Mixin_Omnidirectional_Rotation", "Mixin_PreserveDepthDuringGuiRendering", "Mixin_SkipBlockOutlinesDuringRender",