match sodium culling
This commit is contained in:
@@ -359,6 +359,7 @@ public class ModelFactory {
|
|||||||
boolean faceCoversFullBlock = faceSize[0] == 0 && faceSize[2] == 0 &&
|
boolean faceCoversFullBlock = faceSize[0] == 0 && faceSize[2] == 0 &&
|
||||||
faceSize[1] == (MODEL_TEXTURE_SIZE-1) && faceSize[3] == (MODEL_TEXTURE_SIZE-1);
|
faceSize[1] == (MODEL_TEXTURE_SIZE-1) && faceSize[3] == (MODEL_TEXTURE_SIZE-1);
|
||||||
|
|
||||||
|
//TODO: use faceSize and the depths to compute if mesh can be correctly rendered
|
||||||
|
|
||||||
metadata |= faceCoversFullBlock?2:0;
|
metadata |= faceCoversFullBlock?2:0;
|
||||||
|
|
||||||
@@ -660,6 +661,7 @@ public class ModelFactory {
|
|||||||
return this.metadataCache[clientId];
|
return this.metadataCache[clientId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: redo to batch blit, instead of 6 seperate blits, and also fix mipping
|
||||||
private void putTextures(int id, ColourDepthTextureData[] textures) {
|
private void putTextures(int id, ColourDepthTextureData[] textures) {
|
||||||
int X = (id&0xFF) * MODEL_TEXTURE_SIZE*3;
|
int X = (id&0xFF) * MODEL_TEXTURE_SIZE*3;
|
||||||
int Y = ((id>>8)&0xFF) * MODEL_TEXTURE_SIZE*2;
|
int Y = ((id>>8)&0xFF) * MODEL_TEXTURE_SIZE*2;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import me.cortex.voxy.client.core.rendering.util.UploadStream;
|
|||||||
import me.cortex.voxy.common.Logger;
|
import me.cortex.voxy.common.Logger;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Vector3f;
|
||||||
import org.joml.Vector3i;
|
import org.joml.Vector3i;
|
||||||
import org.lwjgl.system.MemoryUtil;
|
import org.lwjgl.system.MemoryUtil;
|
||||||
|
|
||||||
@@ -84,17 +85,23 @@ public class ChunkBoundRenderer {
|
|||||||
|
|
||||||
long ptr = UploadStream.INSTANCE.upload(this.uniformBuffer, 0, 128);
|
long ptr = UploadStream.INSTANCE.upload(this.uniformBuffer, 0, 128);
|
||||||
long matPtr = ptr; ptr += 4*4*4;
|
long matPtr = ptr; ptr += 4*4*4;
|
||||||
|
|
||||||
|
final float renderDistance = 32*16;
|
||||||
{//This is recomputed to be in chunk section space not worldsection
|
{//This is recomputed to be in chunk section space not worldsection
|
||||||
int sx = MathHelper.floor(viewport.cameraX) >> 4;
|
int sx = MathHelper.floor(viewport.cameraX) >> 4;
|
||||||
int sy = MathHelper.floor(viewport.cameraY) >> 4;
|
int sy = MathHelper.floor(viewport.cameraY) >> 4;
|
||||||
int sz = MathHelper.floor(viewport.cameraZ) >> 4;
|
int sz = MathHelper.floor(viewport.cameraZ) >> 4;
|
||||||
new Vector3i(sx, sy, sz).getToAddress(ptr); ptr += 4*4;
|
new Vector3i(sx, sy, sz).getToAddress(ptr); ptr += 4*4;
|
||||||
|
|
||||||
viewport.MVP.translate(
|
var negInnerSec = new Vector3f(
|
||||||
-(float) (viewport.cameraX - (sx << 4)),
|
-(float) (viewport.cameraX - (sx << 4)),
|
||||||
-(float) (viewport.cameraY - (sy << 4)),
|
-(float) (viewport.cameraY - (sy << 4)),
|
||||||
-(float) (viewport.cameraZ - (sz << 4)),
|
-(float) (viewport.cameraZ - (sz << 4)));
|
||||||
new Matrix4f()).getToAddress(matPtr);
|
|
||||||
|
viewport.MVP.translate(negInnerSec, new Matrix4f()).getToAddress(matPtr);
|
||||||
|
|
||||||
|
negInnerSec.getToAddress(ptr); ptr += 4*3;
|
||||||
|
MemoryUtil.memPutFloat(ptr, renderDistance); ptr += 4;
|
||||||
}
|
}
|
||||||
UploadStream.INSTANCE.commit();
|
UploadStream.INSTANCE.commit();
|
||||||
|
|
||||||
|
|||||||
@@ -101,11 +101,12 @@ public class MixinRenderSectionManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@ModifyReturnValue(method = "getSearchDistance", at = @At("RETURN"))
|
@ModifyReturnValue(method = "getSearchDistance", at = @At("RETURN"))
|
||||||
private float voxy$increaseSearchDistanceFix(float searchDistance) {
|
private float voxy$increaseSearchDistanceFix(float searchDistance) {
|
||||||
if (((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem() == null) {
|
if (((IGetVoxyRenderSystem)(this.level.worldRenderer)).getVoxyRenderSystem() == null) {
|
||||||
return searchDistance;
|
return searchDistance;
|
||||||
}
|
}
|
||||||
return searchDistance + 32;
|
return searchDistance + 32;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#version 460
|
#version 460
|
||||||
|
|
||||||
layout(location = 0) out vec2 uv;
|
|
||||||
layout(binding = 0, std140) uniform SceneUniform {
|
layout(binding = 0, std140) uniform SceneUniform {
|
||||||
mat4 MVP;
|
mat4 MVP;
|
||||||
ivec4 section;
|
ivec4 section;
|
||||||
|
vec4 negInnerSec;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(binding = 1, std430) restrict readonly buffer ChunkPosBuffer {
|
layout(binding = 1, std430) restrict readonly buffer ChunkPosBuffer {
|
||||||
@@ -14,12 +14,24 @@ ivec3 unpackPos(ivec2 pos) {
|
|||||||
return ivec3(pos.y>>10, (pos.x<<12)>>12, ((pos.y<<22)|int(uint(pos.x)>>10))>>10);
|
return ivec3(pos.y>>10, (pos.x<<12)>>12, ((pos.y<<22)|int(uint(pos.x)>>10))>>10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldRender(ivec3 icorner) {
|
||||||
|
vec3 corner = vec3(icorner*16)+negInnerSec.xyz;
|
||||||
|
//closest point TODO: OPTIMIZE
|
||||||
|
corner = mix(mix(vec3(0), corner, lessThan(vec3(0), corner)), corner+16, lessThan(corner+16, vec3(0)));
|
||||||
|
return (corner.x*corner.x + corner.z*corner.z < negInnerSec.w*negInnerSec.w) && abs(corner.y) < negInnerSec.w;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3);
|
uint id = (gl_InstanceID<<5)+gl_BaseInstance+(gl_VertexID>>3);
|
||||||
|
|
||||||
ivec3 origin = unpackPos(chunkPos[id]);
|
ivec3 origin = unpackPos(chunkPos[id]);
|
||||||
origin -= section.xyz;
|
origin -= section.xyz;
|
||||||
|
|
||||||
|
if (!shouldRender(origin)) {
|
||||||
|
gl_Position = vec4(-100.0f, -100.0f, -100.0f, 0.0f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ivec3 cubeCornerI = ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1);
|
ivec3 cubeCornerI = ivec3(gl_VertexID&1, (gl_VertexID>>2)&1, (gl_VertexID>>1)&1);
|
||||||
//Expand the y height to be big (will be +- 8192)
|
//Expand the y height to be big (will be +- 8192)
|
||||||
//TODO: make it W.R.T world height and offsets
|
//TODO: make it W.R.T world height and offsets
|
||||||
|
|||||||
Reference in New Issue
Block a user