More work on texturing and planning
This commit is contained in:
@@ -12,6 +12,7 @@ import me.cortex.zenith.common.world.storage.FragmentedStorageBackendAdaptor;
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.CropBlock;
|
import net.minecraft.block.CropBlock;
|
||||||
|
import net.minecraft.block.SnowBlock;
|
||||||
import net.minecraft.client.render.Camera;
|
import net.minecraft.client.render.Camera;
|
||||||
import net.minecraft.client.render.Frustum;
|
import net.minecraft.client.render.Frustum;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
@@ -107,7 +108,8 @@ public class VoxelCore {
|
|||||||
DebugUtil.setPositionMatrix(matrices);
|
DebugUtil.setPositionMatrix(matrices);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
|
|
||||||
renderer.getModelManager().updateEntry(0, Blocks.FERN.getDefaultState());
|
//this.renderer.getModelManager().updateEntry(0, Blocks.COMPARATOR.getDefaultState());
|
||||||
|
this.renderer.getModelManager().updateEntry(0, Blocks.OAK_LEAVES.getDefaultState());
|
||||||
|
|
||||||
//int boundFB = GlStateManager.getBoundFramebuffer();
|
//int boundFB = GlStateManager.getBoundFramebuffer();
|
||||||
//this.postProcessing.setSize(MinecraftClient.getInstance().getFramebuffer().textureWidth, MinecraftClient.getInstance().getFramebuffer().textureHeight);
|
//this.postProcessing.setSize(MinecraftClient.getInstance().getFramebuffer().textureWidth, MinecraftClient.getInstance().getFramebuffer().textureHeight);
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package me.cortex.zenith.client.core.model;
|
|||||||
|
|
||||||
import me.cortex.zenith.client.core.gl.GlBuffer;
|
import me.cortex.zenith.client.core.gl.GlBuffer;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.color.block.BlockColors;
|
||||||
|
import net.minecraft.registry.Registries;
|
||||||
|
|
||||||
//Manages the storage and updating of model states, textures and colours
|
//Manages the storage and updating of model states, textures and colours
|
||||||
|
|
||||||
@@ -10,6 +13,29 @@ public class ModelManager {
|
|||||||
public static final int MODEL_SIZE = 64;
|
public static final int MODEL_SIZE = 64;
|
||||||
private final ModelTextureBakery bakery = new ModelTextureBakery(16, 16);
|
private final ModelTextureBakery bakery = new ModelTextureBakery(16, 16);
|
||||||
private final GlBuffer modelBuffer;
|
private final GlBuffer modelBuffer;
|
||||||
|
|
||||||
|
|
||||||
|
//The Meta-cache contains critical information needed for meshing, colour provider bit, per-face = is empty, has alpha, is solid, full width, full height
|
||||||
|
// alpha means that some pixels have alpha values and belong in the translucent rendering layer,
|
||||||
|
// is empty means that the face is air/shouldent be rendered as there is nothing there
|
||||||
|
// is solid means that every pixel is fully opaque
|
||||||
|
// full width, height, is if the blockmodel dimentions occupy a full block, e.g. comparator, some faces do some dont and some only in a specific axis
|
||||||
|
|
||||||
|
//FIXME: the issue is e.g. leaves are translucent but the alpha value is used to colour the leaves, so a block can have alpha but still be only made up of transparent or opaque pixels
|
||||||
|
// will need to find a way to send this info to the shader via the material, if it is in the opaque phase render as transparent with blending shiz
|
||||||
|
|
||||||
|
//TODO: ADD an occlusion mask that can be queried (16x16 pixels takes up 4 longs) this mask shows what pixels are exactly occluded at the edge of the block
|
||||||
|
// so that full block occlusion can work nicely
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: what might work maybe, is that all the transparent pixels should be set to the average of the other pixels
|
||||||
|
// that way the block is always "fully occluding" (if the block model doesnt cover the entire thing), maybe
|
||||||
|
// this has some issues with quad merging
|
||||||
|
//TODO: ACTUALLY, full out all the transparent pixels that are _within_ the bounding box of the model
|
||||||
|
// this will mean that when quad merging and rendering, the transparent pixels of the block where there shouldent be
|
||||||
|
// might still work???
|
||||||
|
|
||||||
|
// this has an issue with scaffolding i believe tho, so maybe make it a probability to render??? idk
|
||||||
private final long[] metadataCache;
|
private final long[] metadataCache;
|
||||||
|
|
||||||
public ModelManager() {
|
public ModelManager() {
|
||||||
@@ -18,8 +44,24 @@ public class ModelManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateEntry(int id, BlockState blockState) {
|
public void updateEntry(int id, BlockState blockState) {
|
||||||
|
var colourProvider = MinecraftClient.getInstance().getBlockColors().providers.get(Registries.BLOCK.getRawId(blockState.getBlock()));
|
||||||
|
|
||||||
//This also checks if there is a block colour resolver for the given blockstate and marks that the block has a resolver
|
//This also checks if there is a block colour resolver for the given blockstate and marks that the block has a resolver
|
||||||
var textureData = this.bakery.renderFaces(blockState, 123456);
|
var textureData = this.bakery.renderFaces(blockState, 123456);
|
||||||
|
int depth = TextureUtils.computeDepth(textureData[0], TextureUtils.DEPTH_MODE_AVG);
|
||||||
|
|
||||||
|
int aaaa = 1;
|
||||||
|
|
||||||
|
|
||||||
|
//Model data contains, the quad size and offset of each face and whether the face needs to be resolved with a colour modifier
|
||||||
|
// sourced from the quad data and reverse indexed into the section data (meaning there will be a maxiumum number of colours)
|
||||||
|
// can possibly also put texture coords if needed
|
||||||
|
//Supplying the quad size and offset means that much more accurate rendering quads are rendered and stuff like snow layers will look correct
|
||||||
|
// the size/offset of the corners of the quads will only be applied to the corner quads of the merged quads with adjustment to the UV to ensure textures are not alignned weirdly
|
||||||
|
// the other axis offset is always applied and means that the models will look more correct even when merged into a large quad (which will have alot of overdraw)
|
||||||
|
//TODO: need to make an option for like leaves to be fully opaque as by default they are not!!!!
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getModelMetadata(int id) {
|
public long getModelMetadata(int id) {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class ModelTextureBakery {
|
|||||||
|
|
||||||
private static void addView(float pitch, float yaw) {
|
private static void addView(float pitch, float yaw) {
|
||||||
var stack = new MatrixStack();
|
var stack = new MatrixStack();
|
||||||
stack.translate(0.5f,0.5f,0);
|
stack.translate(0.5f,0.5f,0.5f);
|
||||||
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(pitch));
|
stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(pitch));
|
||||||
stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(yaw));
|
stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(yaw));
|
||||||
stack.translate(-0.5f,-0.5f,-0.5f);
|
stack.translate(-0.5f,-0.5f,-0.5f);
|
||||||
@@ -106,7 +106,7 @@ public class ModelTextureBakery {
|
|||||||
RenderSystem.setProjectionMatrix(oldProjection, VertexSorter.BY_DISTANCE);
|
RenderSystem.setProjectionMatrix(oldProjection, VertexSorter.BY_DISTANCE);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, oldFB);
|
glBindFramebuffer(GL_FRAMEBUFFER, oldFB);
|
||||||
GL11C.glViewport(GlStateManager.Viewport.getX(), GlStateManager.Viewport.getY(), GlStateManager.Viewport.getWidth(), GlStateManager.Viewport.getHeight());
|
GL11C.glViewport(GlStateManager.Viewport.getX(), GlStateManager.Viewport.getY(), GlStateManager.Viewport.getWidth(), GlStateManager.Viewport.getHeight());
|
||||||
|
glBlitNamedFramebuffer(this.framebuffer.id, oldFB, 0,0,16,16,0,0,256,256, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
return faces;
|
return faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package me.cortex.zenith.client.core.model;
|
package me.cortex.zenith.client.core.model;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
//Texturing utils to manipulate data from the model bakery
|
//Texturing utils to manipulate data from the model bakery
|
||||||
public class TextureUtils {
|
public class TextureUtils {
|
||||||
//Returns if any pixels are not fully transparent or fully translucent
|
//Returns if any pixels are not fully transparent or fully translucent
|
||||||
@@ -22,25 +24,42 @@ public class TextureUtils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFullyCovered(ColourDepthTextureData texture) {
|
public static final int DEPTH_MODE_AVG = 1;
|
||||||
for (int pixel : texture.colour()) {
|
public static final int DEPTH_MODE_MAX = 2;
|
||||||
if (((pixel>>24)&0xFF) == 0) {
|
public static final int DEPTH_MODE_MIN = 3;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
//Computes depth info based on written pixel data
|
||||||
public static int computeDepth(ColourDepthTextureData texture, int mode) {
|
public static int computeDepth(ColourDepthTextureData texture, int mode) {
|
||||||
final var colourData = texture.colour();
|
final var colourData = texture.colour();
|
||||||
final var depthData = texture.depth();
|
final var depthData = texture.depth();
|
||||||
|
long a = 0;
|
||||||
|
long b = 0;
|
||||||
|
if (mode == DEPTH_MODE_MIN) {
|
||||||
|
a = Long.MAX_VALUE;
|
||||||
|
}
|
||||||
for (int i = 0; i < colourData.length; i++) {
|
for (int i = 0; i < colourData.length; i++) {
|
||||||
if ((colourData[0]&0xFF)==0) {
|
if ((colourData[0]&0xFF)==0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int depth = depthData[0]&0xffffff;
|
int depth = depthData[0]>>>8;
|
||||||
|
if (mode == DEPTH_MODE_AVG) {
|
||||||
|
a++;
|
||||||
|
b += depth;
|
||||||
|
} else if (mode == DEPTH_MODE_MAX) {
|
||||||
|
a = Math.max(a, depth);
|
||||||
|
} else if (mode == DEPTH_MODE_MIN) {
|
||||||
|
a = Math.min(a, depth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
if (mode == DEPTH_MODE_AVG) {
|
||||||
|
if (a == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (int) (b/a);
|
||||||
|
} else if (mode == DEPTH_MODE_MAX || mode == DEPTH_MODE_MIN) {
|
||||||
|
return (int) a;
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ accessWidener v1 named
|
|||||||
|
|
||||||
accessible field net/minecraft/client/texture/SpriteContents image Lnet/minecraft/client/texture/NativeImage;
|
accessible field net/minecraft/client/texture/SpriteContents image Lnet/minecraft/client/texture/NativeImage;
|
||||||
accessible field net/minecraft/client/render/Frustum frustumIntersection Lorg/joml/FrustumIntersection;
|
accessible field net/minecraft/client/render/Frustum frustumIntersection Lorg/joml/FrustumIntersection;
|
||||||
accessible field net/minecraft/client/render/LightmapTextureManager texture Lnet/minecraft/client/texture/NativeImageBackedTexture;
|
accessible field net/minecraft/client/render/LightmapTextureManager texture Lnet/minecraft/client/texture/NativeImageBackedTexture;
|
||||||
|
accessible field net/minecraft/client/color/block/BlockColors providers Lnet/minecraft/util/collection/IdList;
|
||||||
Reference in New Issue
Block a user