From 006a900d41144af460cfa24a68770bd084aa57ea Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:42:23 +1000 Subject: [PATCH] Added no mipping --- .../me/cortex/voxy/client/core/VoxelCore.java | 2 +- .../voxy/client/core/model/ModelManager.java | 23 ++++++++++++++++--- .../rendering/building/RenderDataFactory.java | 2 +- .../voxy/shaders/lod/gl46/block_model.glsl | 4 ++++ .../assets/voxy/shaders/lod/gl46/quads.frag | 2 +- .../assets/voxy/shaders/lod/gl46/quads.vert | 8 ++++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java index 20d37741..491f9683 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxelCore.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxelCore.java @@ -152,7 +152,7 @@ public class VoxelCore { this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ); //Compute the SSAO of the rendered terrain - //this.postProcessing.computeSSAO(projection, matrices); + this.postProcessing.computeSSAO(projection, matrices); //We can render the translucent directly after as it is the furthest translucent objects this.renderer.renderFarAwayTranslucent(); diff --git a/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java b/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java index 61c7ac96..e2c9e3f0 100644 --- a/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java +++ b/src/main/java/me/cortex/voxy/client/core/model/ModelManager.java @@ -6,7 +6,9 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import me.cortex.voxy.client.core.gl.GlBuffer; import me.cortex.voxy.client.core.gl.GlTexture; import me.cortex.voxy.client.core.rendering.util.UploadStream; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.block.FluidBlock; import net.minecraft.block.entity.BlockEntity; import net.minecraft.client.MinecraftClient; @@ -28,9 +30,7 @@ import net.minecraft.world.chunk.light.LightingProvider; import org.jetbrains.annotations.Nullable; import org.lwjgl.system.MemoryUtil; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Stream; import static org.lwjgl.opengl.GL11.*; @@ -122,6 +122,8 @@ public class ModelManager { + private static final Set NO_RENDER = new HashSet<>(List.of(Blocks.SHORT_GRASS, Blocks.TALL_GRASS)); + //TODO: what i need to do is seperate out fluid states from blockStates @@ -135,6 +137,11 @@ public class ModelManager { boolean isFluid = blockState.getBlock() instanceof FluidBlock; int modelId = -1; var textureData = this.bakery.renderFaces(blockState, 123456, isFluid); + if (NO_RENDER.contains(blockState.getBlock())) { + this.idMappings[blockId] = 0; + return 0; + } + {//Deduplicate same entries int possibleDuplicate = this.modelTexture2id.getInt(List.of(textureData)); if (possibleDuplicate != -1) {//Duplicate found @@ -234,6 +241,9 @@ public class ModelManager { metadata |= canBeOccluded?4:0; + //Face uses its own lighting if its not flat against the adjacent block & isnt traslucent + metadata |= (offset != 0 || blockRenderLayer == RenderLayer.getTranslucent())?0b1000:0; + //Scale face size from 0->this.modelTextureSize-1 to 0->15 @@ -256,6 +266,8 @@ public class ModelManager { faceModelData |= ((!faceCoversFullBlock)&&blockRenderLayer != RenderLayer.getTranslucent())?1<<23:0;//Alpha discard override, translucency doesnt have alpha discard + + MemoryUtil.memPutInt(faceUploadPtr, faceModelData); } this.metadataCache[modelId] = metadata; @@ -267,6 +279,7 @@ public class ModelManager { modelFlags |= colourProvider != null?1:0; modelFlags |= hasBiomeColourResolver?2:0;//Basicly whether to use the next int as a colour or as a base index/id into a colour buffer for biome dependent colours modelFlags |= blockRenderLayer == RenderLayer.getTranslucent()?4:0; + modelFlags |= blockRenderLayer == RenderLayer.getCutout()?0:8; //modelFlags |= blockRenderLayer == RenderLayer.getSolid()?0:1;// should discard alpha MemoryUtil.memPutInt(uploadPtr, modelFlags); @@ -443,6 +456,10 @@ public class ModelManager { return faceExists(metadata, face) && ((metadata>>(8*face))&0b1)==0b1; } + public static boolean faceUsesSelfLighting(long metadata, int face) { + return ((metadata>>(8*face))&0b1000) != 0; + } + public static boolean isColoured(long metadata) { //TODO: THIS return false; diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java index cbc49cd4..f881889b 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/building/RenderDataFactory.java @@ -231,7 +231,7 @@ public class RenderDataFactory { long otherFlags = 0; otherFlags |= ModelManager.isTranslucent(metadata)?1L<<33:0; otherFlags |= ModelManager.isDoubleSided(metadata)?1L<<34:0; - mesher.put(a, b, ((long)clientModelId) | (((long) Mapper.getLightId(facingState))<<16) | ((((long) Mapper.getBiomeId(self))<<24) * (ModelManager.isBiomeColoured(metadata)?1:0)) | otherFlags); + mesher.put(a, b, ((long)clientModelId) | (((long) Mapper.getLightId(ModelManager.faceUsesSelfLighting(metadata, face)?self:facingState))<<16) | ((((long) Mapper.getBiomeId(self))<<24) * (ModelManager.isBiomeColoured(metadata)?1:0)) | otherFlags); return true; } diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl b/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl index 78f9aebc..884e125a 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/block_model.glsl @@ -23,4 +23,8 @@ bool modelHasBiomeLUT(BlockModel model) { bool modelIsTranslucent(BlockModel model) { return ((model.flagsA)&4) != 0; +} + +bool modelHasMipmaps(BlockModel model) { + return ((model.flagsA)&8) != 0; } \ No newline at end of file diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag index 3b4b5f4f..869168f6 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.frag @@ -13,7 +13,7 @@ layout(location = 4) in flat uint flags; layout(location = 0) out vec4 outColour; void main() { vec2 uv = mod(uv, vec2(1f))*(1f/(vec2(3f,2f)*256f)); - vec4 colour = texture(blockModelAtlas, uv + baseUV); + vec4 colour = texture(blockModelAtlas, uv + baseUV, ((flags>>1)&1)*-4f); if ((flags&1) == 1 && colour.a <= 0.25f) { discard; } diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert index bb2c9756..5c954312 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quads.vert @@ -10,7 +10,7 @@ layout(location = 0) out vec2 uv; layout(location = 1) out flat vec2 baseUV; layout(location = 2) out flat vec4 tinting; layout(location = 3) out flat vec4 addin; -layout(location = 4) out flat uint discardAlpha; +layout(location = 4) out flat uint flags; uint extractLodLevel() { return uint(gl_BaseInstance)>>29; @@ -88,10 +88,12 @@ void main() { baseUV = modelUV + (vec2(face%3, face/3) * (1f/(vec2(3f, 2f)*256f))); uv = respectiveQuadSize + faceOffset;//Add in the face offset for 0,0 uv - discardAlpha = faceHasAlphaCuttout(faceData); + flags = faceHasAlphaCuttout(faceData); //We need to have a conditional override based on if the model size is < a full face + quadSize > 1 - discardAlpha |= uint(any(greaterThan(quadSize, ivec2(1)))) & faceHasAlphaCuttoutOverride(faceData); + flags |= uint(any(greaterThan(quadSize, ivec2(1)))) & faceHasAlphaCuttoutOverride(faceData); + + flags |= uint(!modelHasMipmaps(model))<<1; //Compute lighting tinting = getLighting(extractLightId(quad));