Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta matching for shader material IDs #869

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {

// Iris Shaders
compileOnly('org.jetbrains:annotations:26.0.2')
api("com.github.GTNewHorizons:GTNHLib:0.6.8:dev")
api("com.github.GTNewHorizons:GTNHLib:9.9.9:dev")
shadowImplementation("org.anarres:jcpp:1.4.14") // Apache 2.0
shadowImplementation("org.taumc:glsl-transformation-lib:0.2.0-4.g6b42bca") {
exclude module: "antlr4" // we only want to shadow the runtime module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface ITexturesCache {

Set<IIcon> getRenderedTextures();
void enableTextureTracking();
void track(IPatchedTextureAtlasSprite sprite);
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public void onKeypress(TickEvent.ClientTickEvent event) {
wasGLSMKeyPressed = isPressed;
}

public static boolean hitPostInit = false;

@Override
public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);
Expand All @@ -173,6 +175,12 @@ public void postInit(FMLPostInitializationEvent event) {
LOGGER.error("Could not replace LOTR handle render code with thread safe version");
}
}

hitPostInit = true;

if (AngelicaConfig.enableIris) {
Iris.getCurrentPack().ifPresent(pack -> pack.getIdMap().loadMaterialIdLookup());
}
}

float lastIntegratedTickTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gtnewhorizons.angelica.utils;

import java.util.Stack;

import com.gtnewhorizons.angelica.mixins.interfaces.IPatchedTextureAtlasSprite;
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -28,4 +30,26 @@ public static void markBlockTextureForUpdate(IIcon icon, IBlockAccess blockAcces
}
}
}

private final static ThreadLocal<Stack<ITexturesCache>> TEXTURE_CACHE_STACK = ThreadLocal.withInitial(Stack::new);

public static void onSpriteUsed(IPatchedTextureAtlasSprite sprite) {
Stack<ITexturesCache> stack = TEXTURE_CACHE_STACK.get();

if (stack == null || stack.isEmpty()) {
// icon was used outside of chunk building, it's probably an item in an inventory or something
sprite.markNeedsAnimationUpdate();
return;
}

stack.peek().track(sprite);
}

public static void pushCache(ITexturesCache cache) {
TEXTURE_CACHE_STACK.get().push(cache);
}

public static void popCache() {
TEXTURE_CACHE_STACK.get().pop();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jellysquid.mods.sodium.client.gl.shader;

import com.gtnewhorizons.angelica.config.AngelicaConfig;
import com.gtnewhorizons.angelica.glsm.GLDebug;
import me.jellysquid.mods.sodium.client.gl.GlObject;
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;
Expand Down Expand Up @@ -93,12 +94,12 @@ public <P extends GlProgram> P build(ProgramFactory<P> factory) {

final String log = GL20.glGetProgramInfoLog(this.program, GL20.GL_INFO_LOG_LENGTH);

if (!log.isEmpty()) {
final int result = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS);

if ((AngelicaConfig.enableDebugLogging || result != GL11.GL_TRUE) && !log.isEmpty()) {
LOGGER.warn("Program link log for " + this.name + ": " + log);
}

final int result = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS);

if (result != GL11.GL_TRUE) {
throw new RuntimeException("Shader program linking failed, see log for details");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jellysquid.mods.sodium.client.gl.shader;

import com.gtnewhorizons.angelica.config.AngelicaConfig;
import me.jellysquid.mods.sodium.client.gl.GlObject;
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -34,12 +35,12 @@ public GlShader(RenderDevice owner, ShaderType type, ResourceLocation name, Stri

String log = GL20.glGetShaderInfoLog(handle, GL20.GL_INFO_LOG_LENGTH);

if (!log.isEmpty()) {
int result = GL20.glGetShaderi(handle, GL20.GL_COMPILE_STATUS);

if ((AngelicaConfig.enableDebugLogging || result != GL11.GL_TRUE) && !log.isEmpty()) {
LOGGER.warn("Shader compilation log for " + this.name + ": " + log);
}

int result = GL20.glGetShaderi(handle, GL20.GL_COMPILE_STATUS);

if (result != GL11.GL_TRUE) {
throw new RuntimeException("Shader compilation failed, see log for details");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.gtnewhorizon.gtnhlib.client.renderer.quad.properties.ModelQuadFacing;
import com.gtnewhorizons.angelica.config.AngelicaConfig;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.Getter;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.gl.buffer.VertexData;
Expand All @@ -17,6 +16,7 @@
import me.jellysquid.mods.sodium.client.render.chunk.format.ChunkModelOffset;
import me.jellysquid.mods.sodium.client.render.chunk.format.ModelVertexSink;
import me.jellysquid.mods.sodium.client.render.chunk.passes.BlockRenderPass;
import net.coderbot.iris.block_rendering.MaterialIdLookup;
import net.coderbot.iris.block_rendering.BlockRenderingSettings;
import net.coderbot.iris.sodium.block_context.BlockContextHolder;
import net.coderbot.iris.sodium.block_context.ChunkBuildBuffersExt;
Expand Down Expand Up @@ -61,10 +61,10 @@ public ChunkBuildBuffers(ChunkVertexType vertexType) {
}

if(AngelicaConfig.enableIris) {
final Object2IntMap<Block> blockMatches = BlockRenderingSettings.INSTANCE.getBlockMatches();
final MaterialIdLookup lookup = BlockRenderingSettings.INSTANCE.getLookup();

if (blockMatches != null) {
this.iris$contextHolder = new BlockContextHolder(blockMatches);
if (lookup != null) {
this.iris$contextHolder = new BlockContextHolder(lookup);
} else {
this.iris$contextHolder = new BlockContextHolder();
}
Expand Down Expand Up @@ -156,16 +156,20 @@ public void setRenderOffset(int x, int y, int z) {
}

// Iris Compat

@Override
public void iris$setLocalPos(int localPosX, int localPosY, int localPosZ) {
if(!AngelicaConfig.enableIris) return;
this.iris$contextHolder.setLocalPos(localPosX, localPosY, localPosZ);
}

public void iris$setMaterialId(Block block, short renderType) {
@Override
public void iris$setMaterialId(Block block, int meta, short renderType) {
if(!AngelicaConfig.enableIris) return;
this.iris$contextHolder.set(block, renderType);
this.iris$contextHolder.set(block, meta, renderType);
}

@Override
public void iris$resetBlockContext() {
if(!AngelicaConfig.enableIris) return;
this.iris$contextHolder.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ChunkModelVertexTransformer(ModelVertexSink delegate, ChunkModelOffset of
}

@Override
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
this.delegate.writeQuad(x + this.offset.x, y + this.offset.y, z + this.offset.z, color, u, v, light);
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
this.delegate.writeQuad(x + this.offset.x, y + this.offset.y, z + this.offset.z, color, u, v, light, shaderBlockId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface ModelVertexSink extends VertexSink {
* @param u The u-texture of the vertex
* @param v The y-texture of the vertex
* @param light The packed light-map coordinates of the vertex
* @param shaderBlockId The blockId to be passed to the shader
*/
void writeQuad(float x, float y, float z, int color, float u, float v, int light);
void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public HFPModelVertexBufferWriterNio(VertexBufferView backingBuffer) {
}

@Override
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
this.writeQuadInternal(
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(x),
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(y),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public HFPModelVertexBufferWriterUnsafe(VertexBufferView backingBuffer) {
}

@Override
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
this.writeQuadInternal(
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(x),
ModelVertexUtil.denormalizeVertexPositionFloatAsShort(y),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public SFPModelVertexBufferWriterNio(VertexBufferView backingBuffer) {
}

@Override
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
int i = this.writeOffset;

ByteBuffer buffer = this.byteBuffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public SFPModelVertexBufferWriterUnsafe(VertexBufferView backingBuffer) {
}

@Override
public void writeQuad(float x, float y, float z, int color, float u, float v, int light) {
public void writeQuad(float x, float y, float z, int color, float u, float v, int light, int shaderBlockId) {
long i = this.writePointer;

memPutFloat(i, x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.gtnewhorizons.angelica.mixins.interfaces.ITexturesCache;
import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry;
import com.gtnewhorizons.angelica.rendering.AngelicaRenderQueue;
import com.gtnewhorizons.angelica.utils.AnimationsRenderUtils;
import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkGraphicsState;
Expand Down Expand Up @@ -132,7 +133,10 @@ public ChunkBuildResult<T> performBuild(ChunkRenderCacheLocal cache, ChunkBuildB

final WorldSlice slice = cache.getWorldSlice();
final RenderBlocks renderBlocks = new RenderBlocks(slice);
if(renderBlocks instanceof ITexturesCache) ((ITexturesCache)renderBlocks).enableTextureTracking();
if(renderBlocks instanceof ITexturesCache textureCache) {
textureCache.enableTextureTracking();
AnimationsRenderUtils.pushCache(textureCache);
}

final int baseX = this.render.getOriginX();
final int baseY = this.render.getOriginY();
Expand Down Expand Up @@ -172,7 +176,10 @@ public ChunkBuildResult<T> performBuild(ChunkRenderCacheLocal cache, ChunkBuildB
if (canRenderInPass(block, pass) && !shouldUseSodiumFluidRendering(block)) {
ChunkRenderManager.setWorldRenderPass(pass);
final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z);
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.BLOCK_RENDER_TYPE);

if(AngelicaConfig.enableIris) {
buffers.iris$setMaterialId(block, meta, ExtendedDataHelper.BLOCK_RENDER_TYPE);
}

if (cache.getBlockRenderer().renderModel(cache.getWorldSlice(), renderBlocks, block, meta, pos, buffers.get(pass), true, seed)) {
bounds.addBlock(relX, relY, relZ);
Expand All @@ -189,7 +196,9 @@ public ChunkBuildResult<T> performBuild(ChunkRenderCacheLocal cache, ChunkBuildB
for (BlockRenderPass pass : BlockRenderPass.VALUES) {
if (canRenderInPass(block, pass)) {
ChunkRenderManager.setWorldRenderPass(pass);
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.FLUID_RENDER_TYPE);
if(AngelicaConfig.enableIris) {
buffers.iris$setMaterialId(block, meta, ExtendedDataHelper.FLUID_RENDER_TYPE);
}

if (cache.getFluidRenderer().render(slice, cache.getWorldSlice(), block, pos, buffers.get(pass))) {
bounds.addBlock(relX, relY, relZ);
Expand Down Expand Up @@ -217,6 +226,10 @@ public ChunkBuildResult<T> performBuild(ChunkRenderCacheLocal cache, ChunkBuildB
}
}

if(renderBlocks instanceof ITexturesCache) {
AnimationsRenderUtils.popCache();
}

handleRenderBlocksTextures(renderBlocks, renderData);

if(hasMainThreadBlocks) {
Expand Down Expand Up @@ -263,7 +276,10 @@ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buf
final int baseZ = this.render.getOriginZ();
final BlockPos renderOffset = this.offset;
final RenderBlocks rb = new RenderBlocks(slice.getWorld());
if(rb instanceof ITexturesCache) ((ITexturesCache)rb).enableTextureTracking();
if(rb instanceof ITexturesCache textureCache) {
textureCache.enableTextureTracking();
AnimationsRenderUtils.pushCache(textureCache);
}
while(!mainThreadBlocks.isEmpty()) {
final long longPos = mainThreadBlocks.dequeueLong();
if (cancellationSource.isCancelled()) {
Expand Down Expand Up @@ -292,7 +308,9 @@ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buf
if (canRenderInPass(block, pass) && !shouldUseSodiumFluidRendering(block)) {
ChunkRenderManager.setWorldRenderPass(pass);
final long seed = MathUtil.hashPos(pos.x, pos.y, pos.z);
if(AngelicaConfig.enableIris) buffers.iris$setMaterialId(block, ExtendedDataHelper.BLOCK_RENDER_TYPE);
if(AngelicaConfig.enableIris) {
buffers.iris$setMaterialId(block, meta, ExtendedDataHelper.BLOCK_RENDER_TYPE);
}

if (cache.getBlockRenderer().renderModel(slice.getWorld(), rb, block, meta, pos, buffers.get(pass), true, seed)) {
bounds.addBlock(relX, relY, relZ);
Expand All @@ -303,6 +321,10 @@ private void performMainBuild(ChunkRenderCacheLocal cache, ChunkBuildBuffers buf
if(AngelicaConfig.enableIris) buffers.iris$resetBlockContext();
}

if(rb instanceof ITexturesCache) {
AnimationsRenderUtils.popCache();
}

handleRenderBlocksTextures(rb, renderData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private void renderQuad(ModelVertexSink sink, QuadView quad, QuadLightData light

final ModelQuadOrientation order = (useSodiumLight || this.useSeparateAo) ? ModelQuadOrientation.orient(light.br) : ModelQuadOrientation.NORMAL;

int shaderBlockId = quad.getShaderBlockId();
for (int dstIndex = 0; dstIndex < 4; dstIndex++) {
final int srcIndex = order.getVertexIndex(dstIndex);

Expand All @@ -174,7 +175,7 @@ private void renderQuad(ModelVertexSink sink, QuadView quad, QuadLightData light
final int lm = (useSeparateAo) ? ModelQuadUtil.mergeBakedLight(quad.getLight(srcIndex), light.lm[srcIndex]) :
(useSodiumLight) ? light.lm[srcIndex] : quad.getLight(srcIndex);

sink.writeQuad(x, y, z, color, u, v, lm);
sink.writeQuad(x, y, z, color, u, v, lm, shaderBlockId);
}

final TextureAtlasSprite sprite = quad.rubidium$getSprite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private void flushQuad(ChunkModelBuffers buffers, ModelQuadView quad, ModelQuadF

int light = this.quadLightData.lm[vertexIdx];

sink.writeQuad(x, y, z, color, u, v, light);
sink.writeQuad(x, y, z, color, u, v, light, -1);

vertexIdx += lightOrder;
}
Expand Down
Loading
Loading