Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ hand, emitted once the item's pose is on the matrix stack, so first person, the
hidden shadow model, and other players share one hook. `HeldLightState` is the
one decision on whether a held item's lit element is burning: the local
player's Toggle Held Lights key puts out everything in their own hands, and by
default an open flame goes out for any holder whose eyes are under water.
default an open flame goes out for any holder whose eyes are under water. A
torch's own texture glows, so an item whose flame is out is drawn through the
atlas material with its emission off (`EntitySurfaceMode.DOUSED`).

Terrain block lights are per-frame draws, not retained instances: every frame
`ChunkManager.draw` submits each surviving `TerrainLight` (the `RemixLight`
Expand Down Expand Up @@ -416,8 +418,9 @@ diluting the sampler's candidate pool.
owns a dynamic articulated light, and a static rule would light it twice
(`LightManager`, `CopperBeaconBlockEntityRenderer`).
- Whether a held item's lit element burns is decided once, in `HeldLightState`;
the flame, the smoke, the hand light, and the held beam all consult it
(`HeldItemEffectsRenderer`, `LightManager`).
the flame, the smoke, the hand light, the held beam, and the glow of the
item's own texture all consult it (`HeldItemEffectsRenderer`, `LightManager`,
`ItemRendererMixin`).
- A terrain light's cull is the decision not to draw it this frame, never a
destroy; the radius `TerrainState` holds is finite and pushed only on
change, because a changed radius dirties the whole flood (`ChunkManager`,
Expand Down
2 changes: 1 addition & 1 deletion docs/IN_GAME_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ folder. Camera commands are unavailable while a benchmark is running.
|---|---|
| Toggle RTX Rendering (default `F8`) | Turn path tracing off, or back on, without opening chat. The new state shows above the hotbar |
| `Alt+X` | Open the RTX Remix runtime's own developer overlay, or close whichever Remix overlay is open, including the Graphics Settings menu that the button on the settings screen opens; each menu's own close button closes it too. What you change in either overrides the mod's settings. While one is open, Minecraft receives no keyboard or mouse input at all, Escape included; close the menu or press `Alt+X` to return |
| Toggle Held Lights (default `G`) | Put out everything lit in your hands, a torch's flame and light or a Copper Beacon's beam, and light it again |
| Toggle Held Lights (default `G`) | Put out everything lit in your hands, a torch's flame, glow and light or a Copper Beacon's beam, and light it again |
| `R` | Start and stop a camera recording, once `/rtx camera record` has armed it |
| `=` and `-` | While recording, move the time of day forward or back in normal steps. Hold `Ctrl` for larger steps |
| `F1` | Hide the interface, including your own hand |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface CapturedEntityGeometry {
Object getPartSprite(int part);
int getPartTint(int part);
int getPartBlockItemLayer(int part);
boolean isPartDoused(int part);
int cardFaceOfPartStartingAt(int start);

int getVertexCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public final class EntityRenderContext {
/** Entity whose hand-held item is being rendered, or null outside a held-item render. */
private Object heldItemHolder;
private int blockItemLayer = NO_BLOCK_ITEM;
private boolean heldItemDoused;

/** The viewer's eye in the capture's space, valid while {@link #eyeKnown}. */
private final Vector3f eye = new Vector3f();
Expand Down Expand Up @@ -85,6 +86,7 @@ public void begin(boolean remixPass) {
this.activeHand = null;
this.heldItemHolder = null;
this.blockItemLayer = NO_BLOCK_ITEM;
this.heldItemDoused = false;
this.eyeKnown = false;
this.boneCounter = 0;
// Bone transforms are not cleared: the pre-allocated Matrix4f objects are
Expand Down Expand Up @@ -119,6 +121,7 @@ private void closeCapture() {
this.activeHand = null;
this.heldItemHolder = null;
this.blockItemLayer = NO_BLOCK_ITEM;
this.heldItemDoused = false;
this.eyeKnown = false;
}

Expand All @@ -145,6 +148,22 @@ public void setBlockItemLayer(int blockItemLayer) {
this.blockItemLayer = blockItemLayer;
}

/**
* Whether the item currently being rendered is a hand-held one whose lit
* element is out, so its own texture must not glow either.
*
* <p>Set and sampled as {@link #getBlockItemLayer()} is: by
* {@code ItemRendererMixin} for one item render, and by
* {@link RemixCapturingConsumer} as each part opens.
*/
public boolean isHeldItemDoused() {
return heldItemDoused;
}

public void setHeldItemDoused(boolean heldItemDoused) {
this.heldItemDoused = heldItemDoused;
}

/**
* The viewer's eye in the capture's space, or null when the capture owner
* has not supplied it. The first-person pass knows it, because its capture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ public enum EntitySurfaceMode {
CUTOUT,
TRANSLUCENT,
EMISSIVE,
GLASS
GLASS,
/**
* A block-atlas cutout with its emission off: a hand-held item whose lit
* element is out. A torch's texture glows by itself, so the torch would
* otherwise look lit after its flame and its light have gone.
*/
DOUSED
}
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ private static final class PooledMesh {
*/
private final IdentityHashMap<Object, BeaconLensAssets>
beaconLensAssets = new IdentityHashMap<>();
/** See {@link #dousedAtlasMaterial(BlockTextureManager)}; null until a doused part is drawn. */
private RemixMaterial dousedAtlasMaterial;
private final Map<EntityTextureKey, EntityTextureSet> textureSets = new HashMap<>();
private final Map<EntityTextureKey, TextureSize> dynamicTextureSizes = new HashMap<>();
private final Map<EntityTextureKey, Long> dynamicTextureVersions = new HashMap<>();
Expand Down Expand Up @@ -908,6 +910,31 @@ private static void destroyBeaconLensAssets(
}
}

/**
* The atlas cutout material with its emission off, made on first use and
* shared by every doused part. It reads the atlas textures the terrain
* materials own, so it is dropped with them when materials reload.
*/
private RemixMaterial dousedAtlasMaterial(BlockTextureManager textures) {
if (dousedAtlasMaterial == null || dousedAtlasMaterial.isDeleted()) {
dousedAtlasMaterial = textures.createEmissionScaledAtlasMaterial(0.0f);
}
return dousedAtlasMaterial;
}

private void clearDousedAtlasMaterial() {
if (dousedAtlasMaterial == null) {
return;
}
BlockTextureManager textures = BlockTextureManager.get();
if (textures != null) {
textures.destroyEmissionScaledAtlasMaterial(dousedAtlasMaterial);
} else if (!dousedAtlasMaterial.isDeleted()) {
dousedAtlasMaterial.destroy();
}
dousedAtlasMaterial = null;
}

private void clearBeaconLensAssets() {
BlockTextureManager textures = BlockTextureManager.get();
for (BeaconLensAssets assets : beaconLensAssets.values()) {
Expand Down Expand Up @@ -1039,7 +1066,9 @@ private void submitLayer(CapturedEntity result,
}
if (canvasReader.isBacking(role, sides, bone)) continue;
submitRigidPart(result, consumer, part, texId,
atlasSurfaceMode(texId, surfaceMode, consumer.getPartBlockItemLayer(part)),
dousedSurfaceMode(texId,
atlasSurfaceMode(texId, surfaceMode, consumer.getPartBlockItemLayer(part)),
consumer.isPartDoused(part)),
layer.topology(), layer.transientGeometry(), layerIndex,
shellLayerFor(layerIndex, canvasReader.depth(), role), role,
worldTransform, baseCategoryFlags | textureCategoryFlags
Expand Down Expand Up @@ -1085,6 +1114,29 @@ static EntitySurfaceMode atlasSurfaceMode(EntityTextureKey texId,
return EntitySurfaceMode.CUTOUT;
}

/**
* Takes a held item whose lit element is out off the atlas material that
* glows.
*
* <p>A held block borrows the atlas material of its placed counterpart, and
* a torch's texture is emissive there, so a torch whose flame and light had
* gone out still showed a bright head. Only the cutout treatment is swapped:
* nothing that carries a lit element is glass or translucent.
*
* @param narrowed the part's mode after {@link #atlasSurfaceMode}
* @param doused whether the capture path saw the part come from a
* hand-held item whose lit element is out
*/
static EntitySurfaceMode dousedSurfaceMode(EntityTextureKey texId,
EntitySurfaceMode narrowed,
boolean doused) {
return doused
&& narrowed == EntitySurfaceMode.CUTOUT
&& BLOCK_ATLAS_TEXTURE.equals(texId)
? EntitySurfaceMode.DOUSED
: narrowed;
}

/**
* The terrain atlas material a narrowed block-atlas surface mode borrows, so a
* held block shades as its placed counterpart does: ice refracts like ice, clear
Expand Down Expand Up @@ -2255,7 +2307,9 @@ private void ensureMaterial(EntityMaterialKey materialKey) {
// items through its translucent item layer too, so a captured atlas
// TRANSLUCENT only reaches a material key after atlasSurfaceMode has
// narrowed it per part.
RemixMaterial material = btm.getAtlasMaterial(atlasLayerType(materialKey.surfaceMode()));
RemixMaterial material = materialKey.surfaceMode() == EntitySurfaceMode.DOUSED
? dousedAtlasMaterial(btm)
: btm.getAtlasMaterial(atlasLayerType(materialKey.surfaceMode()));
cacheMaterial(materialKey, material);
return;
}
Expand Down Expand Up @@ -2967,6 +3021,7 @@ public void reloadMaterials() {
retainedEntityParts.clear(RemixEntitySubmitter::destroyRetainedPart);
frameOpen = false;
clearBeaconLensAssets();
clearDousedAtlasMaterial();

for (PooledMesh pooled : rigidMeshPool.values()) {
if (!pooled.mesh.isDeletedFast()) pooled.mesh.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public final class HeldItemEffectsRenderer {

private HeldItemEffectsRenderer() {}

/**
* Whether {@code stack} is being rendered in a hand with its lit element
* out, see {@link HeldLightState}. The item's own texture must then not glow
* either: a torch's head is emissive, and stayed bright under water after
* the flame and the light had gone.
*
* <p>False for an item with no flame to put out, and outside a hand, where
* {@link #render} lets a prop burn.
*/
public static boolean isDoused(ItemStack stack) {
if (HeldItemFlame.particleFor(stack) == null) return false;
LivingEntity holder = (LivingEntity) EntityRenderContext.get().getHeldItemHolder();
return holder != null && !HeldLightState.isLit(holder, stack);
}

/**
* Emits the flame and smoke quads for {@code stack} if the Remix capture is
* active, {@code mode} is a hand, the item carries a lit element, and that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public class RemixCapturingConsumer implements VertexConsumer, CapturedEntityGeo
* a held pane of glass and a held torch, must not share the answer.
*/
private final int[] partBlockItemLayer = new int[MAX_PARTS];
/**
* Whether each part came from a hand-held item whose lit element is out;
* see {@link EntityRenderContext#isHeldItemDoused}. Per part for the reason
* the layer is, and written wherever the layer is.
*/
private final boolean[] partDoused = new boolean[MAX_PARTS];
/**
* The first vertex of a full item-card face in each part, or {@link #NO_VERTICES}.
* A full face survives only when its sprite is too busy to rebuild, see
Expand Down Expand Up @@ -1091,7 +1097,9 @@ private void closeQuadIfReady(int lastVertexIndex) {
partBone[parts] = bone;
partSides[parts] = null;
partSprite[parts] = null;
partBlockItemLayer[parts] = EntityRenderContext.get().getBlockItemLayer();
EntityRenderContext context = EntityRenderContext.get();
partBlockItemLayer[parts] = context.getBlockItemLayer();
partDoused[parts] = context.isHeldItemDoused();
partCardFace[parts] = NO_VERTICES;
lane0 = FNV_OFFSET; lane1 = FNV_OFFSET; lane2 = FNV_OFFSET; lane3 = FNV_OFFSET;
partOpen = true;
Expand Down Expand Up @@ -1127,6 +1135,7 @@ private void closeStripIfReady(int lastVertexIndex) {
// Streamed strip vertices never come from a baked item quad, so the
// constants are exact.
partBlockItemLayer[parts] = EntityRenderContext.NO_BLOCK_ITEM;
partDoused[parts] = false;
partCardFace[parts] = NO_VERTICES;
lane0 = FNV_OFFSET; lane1 = FNV_OFFSET; lane2 = FNV_OFFSET; lane3 = FNV_OFFSET;
partOpen = true;
Expand Down Expand Up @@ -1242,6 +1251,10 @@ private void closeOpenPart() {
/** The terrain layer of the block item this part came from, or {@link EntityRenderContext#NO_BLOCK_ITEM}. */
public int getPartBlockItemLayer(int part) { return partBlockItemLayer[part]; }

/** Whether this part came from a hand-held item whose lit element is out. */
@Override
public boolean isPartDoused(int part) { return partDoused[part]; }

/**
* The first vertex of a full item-card face in the part whose vertices start at
* {@code start}, or {@link #NO_VERTICES} when that part is not an item card.
Expand Down Expand Up @@ -1287,6 +1300,7 @@ public void acceptCuboid(ModelPart.Polygon[] sides, int color, Matrix4f pose, Te
// no context to sample, agrees with the live one. Translucent and glass
// blocks are baked-quad models, so the constants are exact.
partBlockItemLayer[parts] = EntityRenderContext.NO_BLOCK_ITEM;
partDoused[parts] = false;
partCardFace[parts] = NO_VERTICES;
parts++;
}
Expand All @@ -1311,6 +1325,7 @@ public void replayCuboidPart(ModelPart.Polygon[] sides, int color, int boneIndex
partTint[parts] = color;
partHash[parts] = 0L;
partBlockItemLayer[parts] = EntityRenderContext.NO_BLOCK_ITEM;
partDoused[parts] = false;
partCardFace[parts] = NO_VERTICES;
parts++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Records the terrain layer of the block item being rendered, and adds the lit
* element of a hand-held item.
* Records the terrain layer of the block item being rendered and whether a
* hand-held item's lit element is out, and adds that lit element when it is
* burning.
*
* <p>Minecraft routes ordinary opaque items through its translucent item layer,
* and clear glass through its cutout one, so the render layer alone cannot tell
Expand All @@ -43,6 +44,7 @@ public class ItemRendererMixin {
EntityRenderContext context = EntityRenderContext.get();
if (context.isRemixPass()) {
context.setBlockItemLayer(rtxremix$blockLayer(stack));
context.setHeldItemDoused(HeldItemEffectsRenderer.isDoused(stack));
}
}

Expand Down Expand Up @@ -75,6 +77,7 @@ public class ItemRendererMixin {
EntityRenderContext context = EntityRenderContext.get();
if (context.isRemixPass()) {
context.setBlockItemLayer(EntityRenderContext.NO_BLOCK_ITEM);
context.setHeldItemDoused(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,42 @@ void theBlockItemLayerIsSampledAsEachPartOpens() {
assertEquals(EntityRenderContext.NO_BLOCK_ITEM, consumer.getPartBlockItemLayer(2));
}

@Test
void whetherAHeldItemIsDousedIsSampledAsEachPartOpens() {
// A torch that is out in one hand and a block in the other can arrive
// through one layer, so this answer is per part too.
EntityRenderContext context = EntityRenderContext.get();
context.begin(true);
RemixCapturingConsumer consumer = new RemixCapturingConsumer(null, true);

context.setHeldItemDoused(true);
itemQuad(consumer, poseAt(0.0f));
context.setHeldItemDoused(false);
itemQuad(consumer, poseAt(1.0f));
consumer.finishOpenVertex();

assertEquals(2, consumer.getPartCount());
assertTrue(consumer.isPartDoused(0));
assertFalse(consumer.isPartDoused(1));
}

@Test
void cuboidPartsOverwriteAStaleDousedAnswer() {
EntityRenderContext context = EntityRenderContext.get();
context.begin(true);
RemixCapturingConsumer consumer = new RemixCapturingConsumer(null, true);
context.setHeldItemDoused(true);
itemQuad(consumer, poseAt(0.0f));
consumer.finishOpenVertex();
assertTrue(consumer.isPartDoused(0));
consumer.clear();

consumer.acceptCuboid(quads(1), 0xFFFFFFFF, new Matrix4f(), null);

assertEquals(1, consumer.getPartCount());
assertFalse(consumer.isPartDoused(0));
}

/**
* A pooled consumer as the next entity receives it: cleared, with the answers
* an earlier item entity wrote into its first two slots still there, and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,34 @@ void otherAtlasSurfaceModesAreLeftAlone() {
}
}

@Test
void aHeldItemWhoseLitElementIsOutLosesTheAtlasMaterialThatGlows() {
assertEquals(EntitySurfaceMode.DOUSED,
RemixEntitySubmitter.dousedSurfaceMode(BLOCK_ATLAS, EntitySurfaceMode.CUTOUT, true));
assertEquals(EntitySurfaceMode.CUTOUT,
RemixEntitySubmitter.dousedSurfaceMode(BLOCK_ATLAS, EntitySurfaceMode.CUTOUT, false));
}

@Test
void onlyAnAtlasCutoutIsEverDoused() {
// Nothing that carries a lit element is glass or translucent, and an
// entity texture has its own material.
for (EntitySurfaceMode mode : EntitySurfaceMode.values()) {
if (mode == EntitySurfaceMode.CUTOUT) {
continue;
}
assertEquals(mode, RemixEntitySubmitter.dousedSurfaceMode(BLOCK_ATLAS, mode, true), mode.name());
}
assertEquals(EntitySurfaceMode.CUTOUT,
RemixEntitySubmitter.dousedSurfaceMode(ENTITY_TEXTURE, EntitySurfaceMode.CUTOUT, true));
}

@Test
void aDousedPartBlendsAndBorrowsAsTheCutoutItReplaces() {
assertEquals(BlockTextureManager.L_CUTOUT,
RemixEntitySubmitter.atlasLayerType(EntitySurfaceMode.DOUSED));
}

@Test
void texturesOtherThanTheAtlasAreNeverNarrowed() {
// A genuinely translucent entity layer, a ghast or a slime, must keep it,
Expand Down