Skip to content

Rendering-aware mods

To show the other side of a portal, Immersive Portals Reforged renders the world a second time, from a virtual camera on the other side, and puts the picture inside the portal. Code that runs during world rendering therefore also runs for these portal views. Most of the time that is what you want, but anything that assumes “one world render per frame” can go wrong:

  • temporal effects (TAA, motion blur) that keep the previous frame’s data;
  • caches keyed on the camera position, such as culling results or level-of-detail choices;
  • counters and timers advanced once per world render;
  • screen-space overlays meant for the player’s own view.

RenderViews tells you which view is being drawn.

Method Returns
isRenderingPortalView() true while a portal view is being drawn, false in the main view.
current() A ViewInfo for the innermost view being drawn, or null in the main view.
depth() 0 in the main view, 1 in a view through a portal, 2 through a portal seen inside another, and so on.

Call these on the render thread only. RenderViews.enter and RenderViews.exit are @Internal: the mod uses them to mark views, and other mods must not call them.

A record describing the view being drawn:

Component Type Meaning
depth() int 1 for a portal seen directly, 2 for a portal seen through another one, and so on.
portal() PortalSnapshot The portal surface this view is seen through.
dimension() String Id of the dimension being drawn, such as "minecraft:the_nether".
eye() Vec3D Position of the virtual camera, in that dimension’s coordinates.
reduced() boolean Whether the view is drawn at reduced quality (shorter distance or lower resolution).

In 0.1.0-alpha, views through portals seen inside other portals are not drawn, so depth() is always 1 in a view and reduced() is false. Write your code for the general case anyway.

A renderer that keeps a history buffer for a temporal effect should only update it in the main view, and can lower its own quality inside portals:

TemporalEffect.java
package com.example.portals;
import net.night.ipreforged.api.client.RenderViews;
import net.night.ipreforged.api.client.ViewInfo;
public final class TemporalEffect {
private long historyFrames;
/** Called by your renderer once per world render. */
public void onWorldRendered() {
if (RenderViews.isRenderingPortalView()) {
ViewInfo view = RenderViews.current();
if (view.reduced() || view.depth() > 1) {
return; // not worth the cost in a small or nested view
}
renderWithoutHistory(view.dimension());
return;
}
// The player's own view: the only one that should feed the history.
historyFrames++;
renderWithHistory();
}
private void renderWithHistory() {
// ...
}
private void renderWithoutHistory(String dimension) {
// ...
}
}

If your mod has to run without Immersive Portals Reforged too, put the RenderViews calls behind the check described in Optional dependencies.