Class RenderUtils

java.lang.Object
me.hackware.api.util.RenderUtils

public final class RenderUtils extends Object
Direct-draw API for 3D overlays: box outlines/fills, lines, quads and camera-facing strips (tracers), plus world-to-screen projection. Draw calls are valid between Render3DEvent begin/end; the client drives the lifecycle. Shader-mod routing and AA selection go through RenderBridge.
  • Field Details

    • STRIP_NEAR_PLANE

      public static final float STRIP_NEAR_PLANE
      Near-plane distance for manual strip clipping (matches vanilla).
      See Also:
    • lastFov

      public static float lastFov
      Last FOV captured from GameRenderer.renderLevel (degrees).
    • viewProjMatrix

      public static final org.joml.Matrix4f viewProjMatrix
      View-projection matrix for the current frame (proj * bob * view). Set by GameRendererMixin.
    • bobMatrix

      public static final org.joml.Matrix4f bobMatrix
      The combined bobHurt + bobView transform for the current frame. Applied to the projection matrix by vanilla so that the world "bobs" when walking. Custom renderers that bypass the GPU projection (e.g. worldToScreen(double, double, double, net.minecraft.client.Camera)) must account for this matrix to stay aligned with the bobbed world.

      Identity when view bobbing is disabled or suppressed.

  • Method Details

    • beginFrame

      public static void beginFrame()
      Called once per frame from GameRendererMixin before Render3DEvent is posted. Resets the draw budget and detects post-loading conditions, and registers Iris pipelines on first use.
    • isGizmosSuppressed

      public static boolean isGizmosSuppressed()
      Returns true when draw calls should be skipped this frame.
    • beginRender

      public static void beginRender(net.minecraft.client.renderer.MultiBufferSource.BufferSource bufferSource, com.mojang.blaze3d.vertex.PoseStack poseStack, net.minecraft.client.Camera camera, net.minecraft.client.renderer.culling.Frustum frameFrustum)
      Begins the per-frame direct-draw context. Must be called before posting Render3DEvent and paired with endRender().
    • isInFrustum

      public static boolean isInFrustum(net.minecraft.world.phys.AABB box)
      Returns true if the given world-space AABB is inside (or intersects) the current view frustum. Always returns true when no frustum is set.
    • endRender

      public static void endRender()
      Flushes any pending draw batches and clears the render context.
    • flushPendingBatches

      public static void flushPendingBatches()
      Immediately flushes the pending no-depth lines + filled batches without tearing down the render context. Used by post-process pipelines that need draws to materialise against a specific FBO that's only bound for a short window.
    • drawBoxOutline

      public static void drawBoxOutline(net.minecraft.world.phys.AABB box, int color, float lineWidth)
    • drawBoxOutlineDepth

      public static void drawBoxOutlineDepth(net.minecraft.world.phys.AABB box, int color, float lineWidth)
    • drawBoxFill

      public static void drawBoxFill(net.minecraft.world.phys.AABB box, int color)
    • drawLine

      public static void drawLine(net.minecraft.world.phys.Vec3 from, net.minecraft.world.phys.Vec3 to, int color, float lineWidth)
    • getCamX

      public static double getCamX()
    • getCamY

      public static double getCamY()
    • getCamZ

      public static double getCamZ()
    • getBufferSource

      public static net.minecraft.client.renderer.MultiBufferSource.BufferSource getBufferSource()
      Returns the active buffer source for the current frame, or null outside a render pass.
    • emitFillQuad

      public static void emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int color)
      Emits a single filled quad into the no-depth-test filled batch.
    • emitFillQuad

      public static void emitFillQuad(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, int c0, int c1, int c2, int c3)
      Emits a filled quad with a per-vertex color (for gradients) into the no-depth-test filled batch.
    • emitFillQuadRelative

      public static void emitFillQuadRelative(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, int color)
      Emits a filled quad using camera-relative float coordinates. Use this when positions were already computed as (world - cam) in doubles and then cast to float, avoiding double precision loss.
    • emitLine

      public static void emitLine(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth)
      Emits a single line segment into the no-depth-test line batch.
    • emitLineDepth

      public static void emitLineDepth(double sx, double sy, double sz, double ex, double ey, double ez, int color, float lineWidth)
      Emits a single line segment into the depth-tested line batch.
    • emitLineRelative

      public static void emitLineRelative(float sx, float sy, float sz, float ex, float ey, float ez, int color, float lineWidth)
      Emits a line segment using camera-relative float coordinates. Use this when positions were already computed as (world - cam) in doubles and then cast to float, avoiding double precision loss.
    • emitClippedStrip

      public static void emitClippedStrip(float sx, float sy, float sz, float ex, float ey, float ez, org.joml.Vector3f fwd, int color, float pxWidth, float pxToWorld)
      Emits a camera-facing anti-aliased quad strip with constant screen-pixel width, after clipping the segment against the near plane.

      Unlike the MC line shader (which computes width from the normal's screen projection and degenerates when the line is view-aligned), this builds explicit billboard geometry whose width is derived from depth, guaranteeing constant rasterised width at any angle. The quad is widened by STRIP_AA_PAD pixels per side and the strip_aa shader fades edge coverage over the outer pixel.

      Parameters:
      fwd - unit camera-forward direction (camera-relative)
      pxWidth - desired width in screen pixels
      pxToWorld - pre-computed 2·tan(fov/2) / screenHeight
    • argb

      public static int argb(int r, int g, int b, int a)
    • withAlpha

      public static int withAlpha(int argb, int alpha)
    • worldToScreen

      public static org.joml.Vector3f worldToScreen(double x, double y, double z, net.minecraft.client.Camera camera)
      Project a world position to GUI-scaled screen coordinates.
      Returns:
      a Vector3f with (screenX, screenY, cameraSpaceZ) or null if the point is behind the camera.
    • clearDrawCaches

      public static void clearDrawCaches()
      Clears the direct-draw pipeline/type caches (called from RenderState.clearAllCaches).