Added no mipping

This commit is contained in:
mcrcortex
2024-02-07 14:06:31 +10:00
parent 006a900d41
commit 1ea4b25573
9 changed files with 58 additions and 43 deletions

View File

@@ -52,7 +52,7 @@ import static org.lwjgl.opengl.GL45C.glTextureSubImage2D;
// as leaves and such will be able to be merged
public class ModelManager {
public static final int MODEL_SIZE = 64;
private final ModelTextureBakery bakery;
public final ModelTextureBakery bakery;
private final GlBuffer modelBuffer;
private final GlBuffer modelColourBuffer;
private final GlTexture textures;
@@ -122,7 +122,6 @@ 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
@@ -137,10 +136,6 @@ 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));
@@ -495,7 +490,7 @@ public class ModelManager {
float[] res = new float[6];
for (var dir : Direction.values()) {
var data = textures[dir.getId()];
float fd = TextureUtils.computeDepth(data, TextureUtils.DEPTH_MODE_MIN, checkMode);//Compute the min float depth, smaller means closer to the camera, range 0-1
float fd = TextureUtils.computeDepth(data, TextureUtils.DEPTH_MODE_AVG, checkMode);//Compute the min float depth, smaller means closer to the camera, range 0-1
int depth = Math.round(fd * this.modelTextureSize);
//If fd is -1, it means that there was nothing rendered on that face and it should be discarded
if (fd < -0.1) {

View File

@@ -43,6 +43,7 @@ import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
import static org.lwjgl.opengl.GL13.glActiveTexture;
import static org.lwjgl.opengl.GL14C.glBlendFuncSeparate;
import static org.lwjgl.opengl.GL20C.glUniformMatrix4fv;
import static org.lwjgl.opengl.GL45C.glBlitNamedFramebuffer;
import static org.lwjgl.opengl.GL45C.glGetTextureImage;
//Builds a texture for each face of a model

View File

@@ -7,6 +7,7 @@ import me.cortex.voxy.client.core.gl.shader.Shader;
import me.cortex.voxy.client.core.gl.shader.ShaderType;
import me.cortex.voxy.client.core.rendering.util.UploadStream;
import me.cortex.voxy.client.mixin.joml.AccessFrustumIntersection;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.math.MatrixStack;
@@ -111,7 +112,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
glDisable(GL_BLEND);
//this.models.addEntry(0, Blocks.STONE.getDefaultState());
//this.models.bakery.renderFaces(Blocks.OAK_LEAVES.getDefaultState(), 1234, false);
RenderLayer.getCutoutMipped().startDrawing();
@@ -150,9 +151,7 @@ public class Gl46FarWorldRenderer extends AbstractFarWorldRenderer {
glColorMask(false, false, false, false);
glDepthMask(false);
//glEnable(GL_REPRESENTATIVE_FRAGMENT_TEST_NV);
glDrawElementsInstanced(GL_TRIANGLES, 6 * 2 * 3, GL_UNSIGNED_BYTE, (1 << 16) * 6 * 2, this.geometry.getSectionCount());
//glDisable(GL_REPRESENTATIVE_FRAGMENT_TEST_NV);
glDepthMask(true);
glColorMask(true, true, true, true);

View File

@@ -85,11 +85,6 @@ public class PostProcessing {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glBlitNamedFramebuffer(sourceFB, this.framebuffer.id, 0,0, width, height, 0,0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
//TODO: need to blit a fullscreen quad to generate a stencil mask of where the vanilla terrain is/isnt
// then when rastering voxy terrain, only render to non masked areas
//Hell once the stencil mask is computed, could clear the depth buffer and use a different near/far plane
//Create a stencil mask of terrain generated by minecraft
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
@@ -113,9 +108,6 @@ public class PostProcessing {
glStencilFunc(GL_EQUAL, 1, 0xFF);
//glDisable(GL_STENCIL_TEST);
//TODO: need to figure out how to do translucency cause doing it normally will cause water to have double translucency (i think)
}

View File

@@ -2,11 +2,11 @@
//TODO: FIXME: this isnt actually correct cause depending on the face (i think) it could be 1/64 th of a position off
// but im going to assume that since we are dealing with huge render distances, this shouldent matter that much
float extractFaceIndentation(uint faceData) {
return float((faceData>>16)&63)/63f;
return float((faceData>>16)&63)/63.0;
}
vec4 extractFaceSizes(uint faceData) {
return (vec4(faceData&0xF, (faceData>>4)&0xF, (faceData>>8)&0xF, (faceData>>12)&0xF)/16f)+vec4(0f,1f/16f,0f,1f/16f);
return (vec4(faceData&0xF, (faceData>>4)&0xF, (faceData>>8)&0xF, (faceData>>12)&0xF)/16.0)+vec4(0.0,1.0/16.0,0.0,1.0/16.0);
}
uint faceHasAlphaCuttout(uint faceData) {

View File

@@ -9,14 +9,22 @@ layout(location = 1) in flat vec2 baseUV;
layout(location = 2) in flat vec4 tinting;
layout(location = 3) in flat vec4 addin;
layout(location = 4) in flat uint flags;
layout(location = 5) in flat vec4 conditionalTinting;
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, ((flags>>1)&1)*-4f);
vec2 uv = mod(uv, vec2(1.0))*(1.0/(vec2(3.0,2.0)*256.0));
vec4 colour = texture(blockModelAtlas, uv + baseUV, ((flags>>1)&1)*-4.0);
if ((flags&1) == 1 && colour.a <= 0.25f) {
discard;
}
//Conditional tinting, TODO: FIXME: REPLACE WITH MASK OR SOMETHING, like encode data into the top bit of alpha
if ((flags&(1<<2)) != 0 && abs(colour.r-colour.g) < 0.02f && abs(colour.g-colour.b) < 0.02f) {
colour *= conditionalTinting;
}
outColour = (colour * tinting) + addin;
//outColour = vec4(uv + baseUV, 0, 1);
}

View File

@@ -11,6 +11,7 @@ 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 flags;
layout(location = 5) out flat vec4 conditionalTinting;
uint extractLodLevel() {
return uint(gl_BaseInstance)>>29;
@@ -23,18 +24,18 @@ ivec3 extractRelativeLodPos() {
}
vec4 uint2vec4RGBA(uint colour) {
return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255f;
return vec4((uvec4(colour)>>uvec4(24,16,8,0))&uvec4(0xFF))/255.0;
}
//Gets the face offset with respect to the face direction (e.g. some will be + some will be -)
float getDepthOffset(uint faceData, uint face) {
float offset = extractFaceIndentation(faceData);
return offset * (1f-((int(face)&1)*2f));
return offset * (1.0-((int(face)&1)*2.0));
}
vec2 getFaceSizeOffset(uint faceData, uint corner) {
vec4 faceOffsetsSizes = extractFaceSizes(faceData);
return mix(faceOffsetsSizes.xz, -(1f-faceOffsetsSizes.yw), bvec2(((corner>>1)&1)==1, (corner&1)==1));
return mix(faceOffsetsSizes.xz, -(1.0-faceOffsetsSizes.yw), bvec2(((corner>>1)&1)==1, (corner&1)==1));
}
//TODO: add a mechanism so that some quads can ignore backface culling
@@ -78,14 +79,16 @@ void main() {
offset = offset.zxy;
}
gl_Position = MVP * vec4(corner + offset, 1f);
gl_Position = MVP * vec4(corner + offset, 1.0);
//Compute the uv coordinates
vec2 modelUV = vec2(modelId&0xFF, (modelId>>8)&0xFF)*(1f/(256f));
vec2 modelUV = vec2(modelId&0xFF, (modelId>>8)&0xFF)*(1.0/(256.0));
//TODO: make the face orientated by 2x3 so that division is not a integer div and modulo isnt needed
// as these are very slow ops
baseUV = modelUV + (vec2(face%3, face/3) * (1f/(vec2(3f, 2f)*256f)));
baseUV = modelUV + (vec2(face%3, face/3) * (1.0/(vec2(3.0, 2.0)*256.0)));
//TODO: add an option to scale the quad size by the lod level so that
// e.g. at lod level 2 a face will have 2x2
uv = respectiveQuadSize + faceOffset;//Add in the face offset for 0,0 uv
flags = faceHasAlphaCuttout(faceData);
@@ -103,19 +106,30 @@ void main() {
if (modelHasBiomeLUT(model)) {
tintColour = colourData[tintColour + extractBiomeId(quad)];
}
tinting *= uint2vec4RGBA(tintColour).yzwx;
conditionalTinting = vec4(0);
if (tintColour != uint(-1)) {
flags |= 1u<<2;
conditionalTinting = uint2vec4RGBA(tintColour).yzwx;
}
addin = vec4(0.0);
if (!modelIsTranslucent(model)) {
tinting.w = 0.0;
addin.w = float(face|(lodLevel<<3))/255.0;
//Encode the face, the lod level and
uint encodedData = 0;
encodedData |= face;
encodedData |= (lodLevel<<3);
encodedData |= uint(modelHasMipmaps(model))<<6;//TODO: add if the face has AO as a face property instead of just using if it has mipmaps
addin.w = float(encodedData)/255.0;
}
//Apply face tint
if (face == 0) {
tinting.xyz *= vec3(0.75, 0.75, 0.75);
} else if (face != 1) {
tinting.xyz *= vec3((float(face-2)/4.0)*0.3 + 0.7);
if ((face>>1) == 0) {
tinting.xyz *= 1.0;
} else if ((face>>1) == 1) {
tinting.xyz *= 0.8;
} else {
tinting.xyz *= 0.6;
}
}

View File

@@ -15,7 +15,10 @@ vec3 rev3d(vec3 clip) {
vec3 reDeProject(vec3 pos) {
vec4 view = MVP * vec4(pos, 1);
view.xy /= view.w;
view.z = texture(depthTex, clamp(view.xy*0.5+0.5, 0, 1)).x*2-1;
vec2 UV = clamp(view.xy*0.5+0.5, 0, 1);
//TODO: sample the colour texture and check if the alpha has the hasAO flag
view.z = texture(depthTex, UV).x*2-1;
view.w = 1;
view = invMVP * view;
return view.xyz/view.w;
@@ -38,20 +41,23 @@ void main() {
uint metadata = uint(colour.w*255f);
uint face = metadata&7;
uint lod = (metadata>>3)&7;
bool hasAO = (metadata>>6)!=0;
vec3 pos = rev3d(vec3(point, depth));
//TODO: TODO: only encode the axis, then use then it as as a mask along with pos and multiply by the -sign of everything
vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (float(int(face)&1)*2-1);
//vec3 viewNormal = vec3(uint((face>>1)==2), uint((face>>1)==0), uint((face>>1)==1)) * (-sign(pos));
float d = computeAOAngle(pos, 0.75*(1<<lod), viewNormal);//1
if (d<0.1) {
d = 0f;
float d = 0.0;
if (hasAO) {
d = computeAOAngle(pos, 1*(1<<lod), viewNormal);//1
if (d<0.1) {
d = 0f;
}
}
vec4 ocolour = colour;
ocolour.xyz *= ((1f-d)/2f+0.5f);
ocolour.xyz *= ((1f-d)/3f+0.666666f);
ocolour.w = 1f;
imageStore(colourTex, ivec2(gl_GlobalInvocationID.xy), ocolour);
}