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);
}
}
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);
}
}
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();
}
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 };
}
Aggregations