mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-19 20:09:39 +00:00
Keep armor and held-item glint materials separate (#2289)
This commit is contained in:
1 parent
e84c8c8d7a
commit
fc8d3e8b89
13 files changed
+170
-46
No files matched your search
@@ -17,7 +17,11 @@ public final class TesrMaterial {
|
||||
|
||||
public enum Transparency { OPAQUE, TRANSLUCENT, ADDITIVE, ADDITIVE_ALPHA, GLINT }
|
||||
|
||||
public enum SpecialRender { NONE, BEACON_BEAM, GLINT }
|
||||
public enum SpecialRender {
|
||||
NONE, BEACON_BEAM, GLINT, ITEM_GLINT;
|
||||
|
||||
public boolean isGlint() { return this == GLINT || this == ITEM_GLINT; }
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<TesrMaterial, TesrMaterial> INTERNED = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ public final class RenderLayer implements BlendingStateHolder {
|
||||
|
||||
private static Hook hookFor(TesrMaterial material, PassOverride pass, int glintSlot, boolean lightmap) {
|
||||
switch (material.special()) {
|
||||
case GLINT -> {
|
||||
case GLINT, ITEM_GLINT -> {
|
||||
return glintHook(glintSlot);
|
||||
}
|
||||
case BEACON_BEAM -> {
|
||||
|
||||
@@ -20,7 +20,15 @@ public final class SkippedGlintBlock {
|
||||
}
|
||||
|
||||
public static void applyHeldItemExitState() {
|
||||
applyExitState(0.5F * 0.76F, 0.25F * 0.76F, 0.8F * 0.76F, 1.0F, GL11.GL_SRC_COLOR, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ZERO, false, false);
|
||||
applyItemExitState(GL11.GL_ONE, GL11.GL_ZERO);
|
||||
}
|
||||
|
||||
public static void applyDroppedItemExitState() {
|
||||
applyItemExitState(GL11.GL_SRC_COLOR, GL11.GL_ONE);
|
||||
}
|
||||
|
||||
private static void applyItemExitState(int srcAlpha, int dstAlpha) {
|
||||
applyExitState(0.5F * 0.76F, 0.25F * 0.76F, 0.8F * 0.76F, 1.0F, GL11.GL_SRC_COLOR, GL11.GL_ONE, srcAlpha, dstAlpha, false, false);
|
||||
}
|
||||
|
||||
private static void applyExitState(float red, float green, float blue, float alpha, int srcRgb, int dstRgb, int srcAlpha, int dstAlpha, boolean resetTextureMatrix, boolean restoreDepthMask) {
|
||||
|
||||
+24
-13
@@ -40,8 +40,7 @@ public final class DroppedItemInstancer {
|
||||
private static boolean glintSeen;
|
||||
private static final ItemPropCache.ItemProp glintProperties = new ItemPropCache.ItemProp();
|
||||
private static final ItemPropCache.ItemProp currentGlintProperties = new ItemPropCache.ItemProp();
|
||||
private static TemplateBuffer glintTemplate;
|
||||
private static int glintTemplateWidth, glintTemplateHeight;
|
||||
private static final GlintMesh glintMesh = new GlintMesh();
|
||||
|
||||
private static long instanced;
|
||||
private static long glintInstanced;
|
||||
@@ -183,16 +182,14 @@ public final class DroppedItemInstancer {
|
||||
return drawsBefore;
|
||||
}
|
||||
|
||||
public static boolean queueSkippedGlint(int iconWidth, int iconHeight) {
|
||||
if (!basePart || !BatchEligibility.batchingAllowed()) return false;
|
||||
if (glintTemplate == null || glintTemplateWidth != iconWidth || glintTemplateHeight != iconHeight) {
|
||||
final IconMesh hit = icons.get(0.0F, 0.0F, 1.0F, 1.0F, iconWidth, iconHeight, 0.0625F);
|
||||
if (hit == null || hit.template == null) return false;
|
||||
glintTemplate = hit.template;
|
||||
glintTemplateWidth = iconWidth;
|
||||
glintTemplateHeight = iconHeight;
|
||||
}
|
||||
if (!ModelPartBatcher.INSTANCE.queueSkippedHeldGlint(glintTemplate)) return false;
|
||||
public static boolean canQueueSkippedGlint() {
|
||||
return basePart && BatchEligibility.batchingAllowed();
|
||||
}
|
||||
|
||||
public static boolean queueSkippedGlint(int stripsWide, int stripsHigh, TesrMaterial material) {
|
||||
if (!canQueueSkippedGlint()) return false;
|
||||
final TemplateBuffer template = glintMesh.get(stripsWide, stripsHigh);
|
||||
if (template == null || !ModelPartBatcher.INSTANCE.queueSkippedItemGlint(template, material)) return false;
|
||||
glintInstanced += 2;
|
||||
BatchEligibility.onPartQueued();
|
||||
BatchEligibility.onPartQueued();
|
||||
@@ -276,13 +273,27 @@ public final class DroppedItemInstancer {
|
||||
basePart = false;
|
||||
glintCapture.reset();
|
||||
glintSeen = false;
|
||||
glintTemplate = null;
|
||||
glintMesh.template = null;
|
||||
if (blockBackend != null) {
|
||||
blockBackend.delete();
|
||||
blockBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GlintMesh {
|
||||
TemplateBuffer template;
|
||||
int stripsWide, stripsHigh;
|
||||
|
||||
TemplateBuffer get(int stripsWide, int stripsHigh) {
|
||||
if (template == null || this.stripsWide != stripsWide || this.stripsHigh != stripsHigh) {
|
||||
template = iconTemplate(0.0F, 0.0F, 1.0F, 1.0F, stripsWide, stripsHigh, 0.0625F);
|
||||
this.stripsWide = stripsWide;
|
||||
this.stripsHigh = stripsHigh;
|
||||
}
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
private static TemplateBuffer iconTemplate(float maxU, float minV, float minU, float maxV, int width, int height, float thickness) {
|
||||
final IconMesh hit = icons.get(maxU, minV, minU, maxV, width, height, thickness);
|
||||
if (hit != null) return hit.template;
|
||||
|
||||
+3
-3
@@ -16,15 +16,15 @@ import org.lwjgl.opengl.GL11;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.IOException;
|
||||
|
||||
/** One draw for the two vanilla held-item layers; modified glint sequences retain their original draws. */
|
||||
public final class HeldItemGlint {
|
||||
/** One draw for the two vanilla held and dropped item layers; modified glint sequences retain their original draws. */
|
||||
public final class ItemGlint {
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
private static final Matrix4f first = new Matrix4f();
|
||||
private static final Matrix4f second = new Matrix4f();
|
||||
private static long matrixTime = Long.MIN_VALUE;
|
||||
private static boolean listening, checked, opaque;
|
||||
|
||||
private HeldItemGlint() {}
|
||||
private ItemGlint() {}
|
||||
|
||||
private static boolean batchedGlintGuarded() {
|
||||
return ModelPartBatcher.INSTANCE.entityPassActive() && ModelPartBatcher.INSTANCE.canQueueGlint() && canResetStencil();
|
||||
@@ -30,8 +30,8 @@ public final class EntityMaterials {
|
||||
static final TesrMaterial DEPTH_ONLY = TesrMaterial.builder().depthOnly().stream().build();
|
||||
static final TesrMaterial DEPTH_ONLY_CUTOUT = TesrMaterial.builder().depthOnly().cutout(0.1f).stream().build();
|
||||
static final TesrMaterial OVERLAY = TesrMaterial.builder().translucent().depthEqual().stream().build();
|
||||
public static final TesrMaterial GLINT = TesrMaterial.builder().glint().depthEqual().noDepthWrite().unlit().stream().special(TesrMaterial.SpecialRender.GLINT).build();
|
||||
public static final TesrMaterial ITEM_GLINT = TesrMaterial.builder().glint().depthEqual().noDepthWrite().unlit().stream().special(TesrMaterial.SpecialRender.GLINT).build();
|
||||
public static final TesrMaterial GLINT = glintMaterial(TesrMaterial.SpecialRender.GLINT);
|
||||
public static final TesrMaterial ITEM_GLINT = glintMaterial(TesrMaterial.SpecialRender.ITEM_GLINT);
|
||||
|
||||
private static final BlendState effectiveBlend = new BlendState();
|
||||
private static final AlphaState effectiveAlpha = new AlphaState();
|
||||
@@ -39,6 +39,10 @@ public final class EntityMaterials {
|
||||
|
||||
private EntityMaterials() {}
|
||||
|
||||
private static TesrMaterial glintMaterial(TesrMaterial.SpecialRender special) {
|
||||
return TesrMaterial.builder().glint().depthEqual().noDepthWrite().unlit().stream().special(special).build();
|
||||
}
|
||||
|
||||
static TesrMaterial fromCurrentState(boolean texIdentity) {
|
||||
final boolean textured = GLStateManager.getTextures().getTextureUnitStates(0).isEnabled();
|
||||
final AlphaState alpha = GLStateManager.getEffectiveAlphaState(effectiveAlpha);
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.gtnewhorizons.angelica.glsm.states.PolygonState;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ModelBoxData;
|
||||
import com.gtnewhorizons.angelica.profiling.BailClassCounts;
|
||||
import com.gtnewhorizons.angelica.rendering.GlintClock;
|
||||
import com.gtnewhorizons.angelica.rendering.items.HeldItemGlint;
|
||||
import com.gtnewhorizons.angelica.rendering.items.ItemGlint;
|
||||
import com.gtnewhorizons.angelica.shadercompat.ShaderGlint;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
@@ -454,14 +454,14 @@ public final class ModelPartBatcher {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean queueSkippedHeldGlint(TemplateBuffer template) {
|
||||
if (!canQueueGlint() || GLStateManager.getActiveTextureUnit() != 0 || !activeGroups.canCopyInstances(EntityMaterials.ITEM_GLINT) || !MatrixHelper.isIdentity(GLStateManager.getTextures().getTextureUnitMatrix(0))) return false;
|
||||
public boolean queueSkippedItemGlint(TemplateBuffer template, TesrMaterial material) {
|
||||
if (!canQueueGlint() || GLStateManager.getActiveTextureUnit() != 0 || !activeGroups.canCopyInstances(material) || !MatrixHelper.isIdentity(GLStateManager.getTextures().getTextureUnitMatrix(0))) return false;
|
||||
final boolean offset = GLStateManager.glIsEnabled(GL11.GL_POLYGON_OFFSET_FILL);
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final int cullCode = DrawState.liveCull(EntityMaterials.ITEM_GLINT);
|
||||
final RenderLayer layer = layerFor(HeldItemGlint.texture(), EntityMaterials.ITEM_GLINT, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, ShaderGlint.NO_TINT, cullCode, false, DrawState.liveLightmap());
|
||||
activeGroups.queueGlintLayers(template, layer, EntityMaterials.ITEM_GLINT, currentModelView(), GLSMConfig.packedLastBrightness(), VANILLA_GLINT_COLOR, currentOverlay(), currentEntityInfo(0),
|
||||
HeldItemGlint.firstMatrix(), HeldItemGlint.secondMatrix());
|
||||
final int cullCode = DrawState.liveCull(material);
|
||||
final RenderLayer layer = layerFor(ItemGlint.texture(), material, PassOverride.NONE, offset ? polygon.getOffsetFactor() : 0, offset ? polygon.getOffsetUnits() : 0, ShaderGlint.NO_TINT, cullCode, false, DrawState.liveLightmap());
|
||||
activeGroups.queueGlintLayers(template, layer, material, currentModelView(), GLSMConfig.packedLastBrightness(), VANILLA_GLINT_COLOR, currentOverlay(), currentEntityInfo(0),
|
||||
ItemGlint.firstMatrix(), ItemGlint.secondMatrix());
|
||||
parts++;
|
||||
glintPassReuses++;
|
||||
return true;
|
||||
@@ -625,7 +625,7 @@ public final class ModelPartBatcher {
|
||||
final PolygonState polygon = GLStateManager.getPolygonState();
|
||||
final float offsetFactor = offset ? polygon.getOffsetFactor() : 0.0f;
|
||||
final float offsetUnits = offset ? polygon.getOffsetUnits() : 0.0f;
|
||||
final int glintSlot = material.special() == TesrMaterial.SpecialRender.GLINT ? lastBoundGlintSlot : ShaderGlint.NO_TINT;
|
||||
final int glintSlot = material.special().isGlint() ? lastBoundGlintSlot : ShaderGlint.NO_TINT;
|
||||
final int cullCode = DrawState.liveCull(material);
|
||||
final boolean lit = DrawState.liveLit(material);
|
||||
final EntityTextureAtlas.Slot atlasSlot = texMatrix == null && cubesInsideTexture ? atlasSlotFor(material) : null;
|
||||
|
||||
@@ -1136,10 +1136,10 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
if (!live(group) || !queuedInstanced(group)) continue;
|
||||
if (group.templateColumns.hasInstances()) {
|
||||
final boolean fixedFunction = deferred == null && GLStateManager.getActiveProgram() == 0;
|
||||
drawTemplateRuns(group.templateColumns, group.material.special() == TesrMaterial.SpecialRender.GLINT && fixedFunction, group.material == EntityMaterials.ITEM_GLINT);
|
||||
drawTemplateRuns(group.templateColumns, group.material.special().isGlint() && fixedFunction, group.material == EntityMaterials.ITEM_GLINT);
|
||||
}
|
||||
if (!cubeAvailable && group.cubeColumns.hasInstances() && !group.cubeColumns.anyAtlasSlot) {
|
||||
drawTemplateRuns(group.cubeColumns, group.material == EntityMaterials.GLINT && deferred == null, false);
|
||||
drawTemplateRuns(group.cubeColumns, group.material.special().isGlint() && deferred == null, false);
|
||||
}
|
||||
}
|
||||
restoreTexMatrix();
|
||||
@@ -1281,7 +1281,7 @@ final class RetainedTesrGroups implements AngelicaBufferSource.LayerDrawHook {
|
||||
for (int r = 0, n = cols.runs.size(); r < n; r++) {
|
||||
final TexRun run = cols.runs.get(r);
|
||||
applyTexMatrix(run);
|
||||
final boolean combined = group.material == EntityMaterials.GLINT && deferred == null && r + 1 < n && combineRuns(cols, run, cols.runs.get(r + 1));
|
||||
final boolean combined = group.material.special().isGlint() && deferred == null && r + 1 < n && combineRuns(cols, run, cols.runs.get(r + 1));
|
||||
try {
|
||||
if (canRedraw(run)) {
|
||||
instanced.redrawCubes(run.sourceRun.uploadOffset, run.instances, run.color);
|
||||
|
||||
Reference in new issue
Block a user