Added no mipping

This commit is contained in:
mcrcortex
2024-02-06 15:42:23 +10:00
parent e197e07c94
commit 006a900d41
6 changed files with 32 additions and 9 deletions

View File

@@ -152,7 +152,7 @@ public class VoxelCore {
this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ); this.renderer.renderFarAwayOpaque(projection, matrices, cameraX, cameraY, cameraZ);
//Compute the SSAO of the rendered terrain //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 //We can render the translucent directly after as it is the furthest translucent objects
this.renderer.renderFarAwayTranslucent(); this.renderer.renderFarAwayTranslucent();

View File

@@ -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.GlBuffer;
import me.cortex.voxy.client.core.gl.GlTexture; import me.cortex.voxy.client.core.gl.GlTexture;
import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.client.core.rendering.util.UploadStream;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FluidBlock; import net.minecraft.block.FluidBlock;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@@ -28,9 +30,7 @@ import net.minecraft.world.chunk.light.LightingProvider;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@@ -122,6 +122,8 @@ public class ModelManager {
private static final Set<Block> 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 //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; boolean isFluid = blockState.getBlock() instanceof FluidBlock;
int modelId = -1; int modelId = -1;
var textureData = this.bakery.renderFaces(blockState, 123456, isFluid); var textureData = this.bakery.renderFaces(blockState, 123456, isFluid);
if (NO_RENDER.contains(blockState.getBlock())) {
this.idMappings[blockId] = 0;
return 0;
}
{//Deduplicate same entries {//Deduplicate same entries
int possibleDuplicate = this.modelTexture2id.getInt(List.of(textureData)); int possibleDuplicate = this.modelTexture2id.getInt(List.of(textureData));
if (possibleDuplicate != -1) {//Duplicate found if (possibleDuplicate != -1) {//Duplicate found
@@ -234,6 +241,9 @@ public class ModelManager {
metadata |= canBeOccluded?4:0; 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 //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 faceModelData |= ((!faceCoversFullBlock)&&blockRenderLayer != RenderLayer.getTranslucent())?1<<23:0;//Alpha discard override, translucency doesnt have alpha discard
MemoryUtil.memPutInt(faceUploadPtr, faceModelData); MemoryUtil.memPutInt(faceUploadPtr, faceModelData);
} }
this.metadataCache[modelId] = metadata; this.metadataCache[modelId] = metadata;
@@ -267,6 +279,7 @@ public class ModelManager {
modelFlags |= colourProvider != null?1:0; 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 |= 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.getTranslucent()?4:0;
modelFlags |= blockRenderLayer == RenderLayer.getCutout()?0:8;
//modelFlags |= blockRenderLayer == RenderLayer.getSolid()?0:1;// should discard alpha //modelFlags |= blockRenderLayer == RenderLayer.getSolid()?0:1;// should discard alpha
MemoryUtil.memPutInt(uploadPtr, modelFlags); MemoryUtil.memPutInt(uploadPtr, modelFlags);
@@ -443,6 +456,10 @@ public class ModelManager {
return faceExists(metadata, face) && ((metadata>>(8*face))&0b1)==0b1; 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) { public static boolean isColoured(long metadata) {
//TODO: THIS //TODO: THIS
return false; return false;

View File

@@ -231,7 +231,7 @@ public class RenderDataFactory {
long otherFlags = 0; long otherFlags = 0;
otherFlags |= ModelManager.isTranslucent(metadata)?1L<<33:0; otherFlags |= ModelManager.isTranslucent(metadata)?1L<<33:0;
otherFlags |= ModelManager.isDoubleSided(metadata)?1L<<34: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; return true;
} }

View File

@@ -23,4 +23,8 @@ bool modelHasBiomeLUT(BlockModel model) {
bool modelIsTranslucent(BlockModel model) { bool modelIsTranslucent(BlockModel model) {
return ((model.flagsA)&4) != 0; return ((model.flagsA)&4) != 0;
}
bool modelHasMipmaps(BlockModel model) {
return ((model.flagsA)&8) != 0;
} }

View File

@@ -13,7 +13,7 @@ layout(location = 4) in flat uint flags;
layout(location = 0) out vec4 outColour; layout(location = 0) out vec4 outColour;
void main() { void main() {
vec2 uv = mod(uv, vec2(1f))*(1f/(vec2(3f,2f)*256f)); 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) { if ((flags&1) == 1 && colour.a <= 0.25f) {
discard; discard;
} }

View File

@@ -10,7 +10,7 @@ layout(location = 0) out vec2 uv;
layout(location = 1) out flat vec2 baseUV; layout(location = 1) out flat vec2 baseUV;
layout(location = 2) out flat vec4 tinting; layout(location = 2) out flat vec4 tinting;
layout(location = 3) out flat vec4 addin; layout(location = 3) out flat vec4 addin;
layout(location = 4) out flat uint discardAlpha; layout(location = 4) out flat uint flags;
uint extractLodLevel() { uint extractLodLevel() {
return uint(gl_BaseInstance)>>29; return uint(gl_BaseInstance)>>29;
@@ -88,10 +88,12 @@ void main() {
baseUV = modelUV + (vec2(face%3, face/3) * (1f/(vec2(3f, 2f)*256f))); baseUV = modelUV + (vec2(face%3, face/3) * (1f/(vec2(3f, 2f)*256f)));
uv = respectiveQuadSize + faceOffset;//Add in the face offset for 0,0 uv 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 //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 //Compute lighting
tinting = getLighting(extractLightId(quad)); tinting = getLighting(extractLightId(quad));