diff --git a/AGENTS.md b/AGENTS.md index 89ea57ebe..e1a411c58 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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` @@ -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`, diff --git a/docs/IN_GAME_GUIDE.md b/docs/IN_GAME_GUIDE.md index 71d3545d9..f20d32566 100644 --- a/docs/IN_GAME_GUIDE.md +++ b/docs/IN_GAME_GUIDE.md @@ -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 | diff --git a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/CapturedEntityGeometry.java b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/CapturedEntityGeometry.java index cf62ce443..73c785cda 100644 --- a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/CapturedEntityGeometry.java +++ b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/CapturedEntityGeometry.java @@ -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(); diff --git a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntityRenderContext.java b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntityRenderContext.java index b5f6c8ebd..70e30d89c 100644 --- a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntityRenderContext.java +++ b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntityRenderContext.java @@ -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(); @@ -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 @@ -119,6 +121,7 @@ private void closeCapture() { this.activeHand = null; this.heldItemHolder = null; this.blockItemLayer = NO_BLOCK_ITEM; + this.heldItemDoused = false; this.eyeKnown = false; } @@ -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. + * + *

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 diff --git a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntitySurfaceMode.java b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntitySurfaceMode.java index 2a88f6a5b..ed3052105 100644 --- a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntitySurfaceMode.java +++ b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/EntitySurfaceMode.java @@ -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 } diff --git a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitter.java b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitter.java index 3d0eb1a73..64dbfc946 100644 --- a/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitter.java +++ b/renderer-core/src/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitter.java @@ -699,6 +699,8 @@ private static final class PooledMesh { */ private final IdentityHashMap beaconLensAssets = new IdentityHashMap<>(); + /** See {@link #dousedAtlasMaterial(BlockTextureManager)}; null until a doused part is drawn. */ + private RemixMaterial dousedAtlasMaterial; private final Map textureSets = new HashMap<>(); private final Map dynamicTextureSizes = new HashMap<>(); private final Map dynamicTextureVersions = new HashMap<>(); @@ -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()) { @@ -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 @@ -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. + * + *

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 @@ -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; } @@ -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(); diff --git a/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/HeldItemEffectsRenderer.java b/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/HeldItemEffectsRenderer.java index f3ed192b2..64bd904fb 100644 --- a/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/HeldItemEffectsRenderer.java +++ b/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/HeldItemEffectsRenderer.java @@ -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. + * + *

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 diff --git a/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumer.java b/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumer.java index 32f65b85e..3e376c84c 100644 --- a/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumer.java +++ b/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumer.java @@ -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 @@ -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; @@ -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; @@ -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. @@ -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++; } @@ -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++; } diff --git a/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/mixin/ItemRendererMixin.java b/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/mixin/ItemRendererMixin.java index 0a47a5b60..3c29dc8fb 100644 --- a/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/mixin/ItemRendererMixin.java +++ b/versions/1.21.1/minecraft/main/java/com/nvidia/rtxremix/minecraft/mixin/ItemRendererMixin.java @@ -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. * *

Minecraft routes ordinary opaque items through its translucent item layer, * and clear glass through its cutout one, so the render layer alone cannot tell @@ -43,6 +44,7 @@ public class ItemRendererMixin { EntityRenderContext context = EntityRenderContext.get(); if (context.isRemixPass()) { context.setBlockItemLayer(rtxremix$blockLayer(stack)); + context.setHeldItemDoused(HeldItemEffectsRenderer.isDoused(stack)); } } @@ -75,6 +77,7 @@ public class ItemRendererMixin { EntityRenderContext context = EntityRenderContext.get(); if (context.isRemixPass()) { context.setBlockItemLayer(EntityRenderContext.NO_BLOCK_ITEM); + context.setHeldItemDoused(false); } } diff --git a/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumerTest.java b/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumerTest.java index b4d1a4f1c..ef61678c7 100644 --- a/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumerTest.java +++ b/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixCapturingConsumerTest.java @@ -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 diff --git a/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitterAtlasSurfaceModeTest.java b/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitterAtlasSurfaceModeTest.java index 966f8b7e3..05b840fa2 100644 --- a/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitterAtlasSurfaceModeTest.java +++ b/versions/1.21.1/minecraft/test/java/com/nvidia/rtxremix/minecraft/entity/RemixEntitySubmitterAtlasSurfaceModeTest.java @@ -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,