Search in sources :

Example 1 with Mirror

use of com.qouteall.immersive_portals.portal.Mirror in project ImmersivePortalsMod by qouteall.

the class MyRenderHelper method setupTransformationForMirror.

public static void setupTransformationForMirror(Camera camera) {
    if (CGlobal.renderer.isRendering()) {
        Portal renderingPortal = CGlobal.renderer.getRenderingPortal();
        if (renderingPortal instanceof Mirror) {
            Mirror mirror = (Mirror) renderingPortal;
            Vec3d relativePos = mirror.getPos().subtract(camera.getPos());
            GlStateManager.translated(relativePos.x, relativePos.y, relativePos.z);
            float[] arr = getMirrorTransformation(mirror.getNormal());
            multMatrix(arr);
            GlStateManager.translated(-relativePos.x, -relativePos.y, -relativePos.z);
        // GlStateManager.cullFace(GlStateManager.FaceSides.FRONT);
        } else {
        // GlStateManager.cullFace(GlStateManager.FaceSides.BACK);
        }
    } else {
    // GlStateManager.cullFace(GlStateManager.FaceSides.BACK);
    }
}
Also used : Portal(com.qouteall.immersive_portals.portal.Portal) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with Mirror

use of com.qouteall.immersive_portals.portal.Mirror in project ImmersivePortalsMod by qouteall.

the class ViewAreaRenderer method buildPortalViewAreaTrianglesBuffer.

private static void buildPortalViewAreaTrianglesBuffer(Vec3d fogColor, Portal portal, BufferBuilder bufferbuilder, Vec3d cameraPos, float partialTicks, float layerWidth) {
    // if layerWidth is small, the teleportation will not be seamless
    // counter-clockwise triangles are front-faced in default
    bufferbuilder.begin(GL_TRIANGLES, VertexFormats.POSITION_COLOR);
    Vec3d posInPlayerCoordinate = portal.getPos().subtract(cameraPos);
    if (portal instanceof Mirror) {
        posInPlayerCoordinate = posInPlayerCoordinate.add(portal.getNormal().multiply(-0.001));
    }
    Consumer<Vec3d> vertexOutput = p -> putIntoVertex(bufferbuilder, p, fogColor);
    if (portal.specialShape == null) {
        generateTriangleRectangular(vertexOutput, portal, layerWidth, posInPlayerCoordinate);
    } else {
        generateTriangleSpecial(vertexOutput, portal, layerWidth, posInPlayerCoordinate);
    }
    if (shouldRenderAdditionalBox(portal, cameraPos)) {
        renderAdditionalBox(portal, cameraPos, vertexOutput);
    }
}
Also used : GlStateManager(com.mojang.blaze3d.platform.GlStateManager) GuiLighting(net.minecraft.client.render.GuiLighting) Tessellator(net.minecraft.client.render.Tessellator) Arrays(java.util.Arrays) OFInterface(com.qouteall.immersive_portals.OFInterface) GL_CLIP_PLANE0(org.lwjgl.opengl.GL11.GL_CLIP_PLANE0) CGlobal(com.qouteall.immersive_portals.CGlobal) SpecialPortalShape(com.qouteall.immersive_portals.portal.SpecialPortalShape) Consumer(java.util.function.Consumer) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d) Portal(com.qouteall.immersive_portals.portal.Portal) BufferBuilder(net.minecraft.client.render.BufferBuilder) MinecraftClient(net.minecraft.client.MinecraftClient) GL11(org.lwjgl.opengl.GL11) VertexFormats(net.minecraft.client.render.VertexFormats) GL_TRIANGLES(org.lwjgl.opengl.GL11.GL_TRIANGLES) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d)

Example 3 with Mirror

use of com.qouteall.immersive_portals.portal.Mirror in project ImmersivePortalsMod by qouteall.

the class ViewAreaRenderer method drawPortalViewTriangle.

public static void drawPortalViewTriangle(Portal portal) {
    MinecraftClient.getInstance().getProfiler().push("render_view_triangle");
    DimensionRenderHelper helper = CGlobal.clientWorldLoader.getDimensionRenderHelper(portal.dimensionTo);
    Vec3d fogColor = helper.getFogColor();
    // important
    GlStateManager.enableCull();
    // In OpenGL, if you forget to set one rendering state and the result will be abnormal
    // this design is bug-prone (DirectX is better in this aspect)
    GuiLighting.disable();
    GlStateManager.color4f(1, 1, 1, 1);
    GlStateManager.disableFog();
    GlStateManager.disableAlphaTest();
    GlStateManager.disableTexture();
    GlStateManager.shadeModel(GL11.GL_SMOOTH);
    GlStateManager.disableBlend();
    GlStateManager.disableLighting();
    GL11.glDisable(GL_CLIP_PLANE0);
    if (OFInterface.isShaders.getAsBoolean()) {
        fogColor = Vec3d.ZERO;
    }
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferbuilder = tessellator.getBufferBuilder();
    buildPortalViewAreaTrianglesBuffer(fogColor, portal, bufferbuilder, PortalRenderer.mc.gameRenderer.getCamera().getPos(), MyRenderHelper.partialTicks, portal instanceof Mirror ? 0 : 0.45F);
    tessellator.draw();
    GlStateManager.enableCull();
    GlStateManager.enableAlphaTest();
    GlStateManager.enableTexture();
    GlStateManager.enableLighting();
    MinecraftClient.getInstance().getProfiler().pop();
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with Mirror

use of com.qouteall.immersive_portals.portal.Mirror in project ImmersivePortalsMod by qouteall.

the class MyGameRenderer method calcClipPlaneEquation.

// invoke this before rendering portal
// its result depends on camra pos
private double[] calcClipPlaneEquation() {
    Portal portal = CGlobal.renderer.getRenderingPortal();
    Vec3d planeNormal = portal.getNormal().multiply(-1);
    // Vec3d cullingPos = portal.getPos()
    // .subtract(portal.getNormal().multiply(-0.01))//avoid z fighting
    // .subtract(mc.gameRenderer.getCamera().getPos());
    Vec3d cameraPos = mc.gameRenderer.getCamera().getPos();
    Vec3d cullingPos = portal.getPointInPortalProjection(cameraPos).subtract(cameraPos).subtract(// avoid z fighting
    portal.getNormal().multiply(-0.01));
    if (OFInterface.isShaders.getAsBoolean() && portal instanceof Mirror) {
        planeNormal = planeNormal.multiply(-1);
    }
    // equation: planeNormal * p + c > 0
    // -planeNormal * portalCenter = c
    double c = planeNormal.multiply(-1).dotProduct(cullingPos);
    return new double[] { planeNormal.x, planeNormal.y, planeNormal.z, c };
}
Also used : Portal(com.qouteall.immersive_portals.portal.Portal) Mirror(com.qouteall.immersive_portals.portal.Mirror) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Mirror (com.qouteall.immersive_portals.portal.Mirror)4 Vec3d (net.minecraft.util.math.Vec3d)4 Portal (com.qouteall.immersive_portals.portal.Portal)3 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 Tessellator (net.minecraft.client.render.Tessellator)2 GlStateManager (com.mojang.blaze3d.platform.GlStateManager)1 CGlobal (com.qouteall.immersive_portals.CGlobal)1 OFInterface (com.qouteall.immersive_portals.OFInterface)1 SpecialPortalShape (com.qouteall.immersive_portals.portal.SpecialPortalShape)1 Arrays (java.util.Arrays)1 Consumer (java.util.function.Consumer)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 GuiLighting (net.minecraft.client.render.GuiLighting)1 VertexFormats (net.minecraft.client.render.VertexFormats)1 GL11 (org.lwjgl.opengl.GL11)1 GL_CLIP_PLANE0 (org.lwjgl.opengl.GL11.GL_CLIP_PLANE0)1 GL_TRIANGLES (org.lwjgl.opengl.GL11.GL_TRIANGLES)1