barry + shift

This commit is contained in:
mcrcortex
2025-11-05 15:30:03 +10:00
parent 1c9ef1ea16
commit 8426006435
7 changed files with 26 additions and 14 deletions

View File

@@ -27,6 +27,7 @@ public class Capabilities {
public final boolean subgroup;
public final boolean sparseBuffer;
public final boolean isNvidia;
public final boolean nvBarryCoords;
public Capabilities() {
var cap = GL.getCapabilities();
@@ -73,6 +74,8 @@ public class Capabilities {
this.totalDedicatedMemory = -1;
this.totalDynamicMemory = -1;
}
this.nvBarryCoords = cap.GL_NV_fragment_shader_barycentric;
}
public static void init() {

View File

@@ -199,7 +199,7 @@ public class RenderDataFactory {
private static long packPartialQuadData(int modelId, long state, long metadata) {
//This uses hardcoded data to shuffle things
long lightAndBiome = (state&((0x1FFL<<47)|(0xFFL<<56)))>>1;
long lightAndBiome = (state&((0x1FFL<<47)|(0xFFL<<56)))>>>1;
lightAndBiome &= ModelQueries.isBiomeColoured(metadata)?-1:~(0x1FFL<<46);//46 not 47 because is already shifted by 1 THIS WASTED 4 HOURS ;-; aaaaaAAAAAA
lightAndBiome &= ModelQueries.isFullyOpaque(metadata)?~(0xFFL<<55):-1;//If its fully opaque it always uses neighbor light?
@@ -221,7 +221,7 @@ public class RenderDataFactory {
for (int i = 0; i < 32*32*32;) {
long block = rawSectionData[i];//Get the block mapping
if (Mapper.isAir(block)) {//If it is air, just emit lighting
sectionData[i * 2] = (block&(0xFFL<<56))>>1;
sectionData[i * 2] = (block&(0xFFL<<56))>>>1;
sectionData[i * 2 + 1] = 0;
} else {
int modelId = rawModelIds[Mapper.getBlockId(block)];
@@ -484,7 +484,7 @@ public class RenderDataFactory {
this.blockMesher.putNext(((side == 0) ? 0L : 1L) |
(A&~LM) |
((neighborId & (0xFFL << 56)) >> 1)
((neighborId & (0xFFL << 56)) >>> 1)
);
}
}
@@ -650,7 +650,7 @@ public class RenderDataFactory {
this.blockMesher.putNext((side == 0 ? 0L : 1L) |
(A&~LM) |
((neighborId&(0xFFL<<56))>>1)
((neighborId&(0xFFL<<56))>>>1)
);
}
}
@@ -1017,7 +1017,7 @@ public class RenderDataFactory {
long A = this.sectionData[(i<<5) * 2];
ma.putNext(0L |
(A&~LM) |
((neighborId&(0xFFL<<56))>>1)
((neighborId&(0xFFL<<56))>>>1)
);
} else {skipA++;}
} else {skipA++;}
@@ -1039,7 +1039,7 @@ public class RenderDataFactory {
long A = this.sectionData[(i*32+31) * 2];
mb.putNext(1L |
(A&~LM) |
((neighborId&(0xFFL<<56))>>1)
((neighborId&(0xFFL<<56))>>>1)
);
} else {skipB++;}
} else {skipB++;}
@@ -1261,7 +1261,7 @@ public class RenderDataFactory {
ma.skip(skipA); skipA = 0;
//TODO: LIGHTING
long lightData = ((neighborId&(0xFFL<<56))>>1);//A;
long lightData = ((neighborId&(0xFFL<<56))>>>1);//A;
//if (!ModelQueries.faceUsesSelfLighting(Am, facingForward|(axis*2))) {//TODO: check this is right
// lighter = this.sectionData[bi];
//}
@@ -1322,7 +1322,7 @@ public class RenderDataFactory {
mb.skip(skipB); skipB = 0;
//TODO: LIGHTING
long lightData = ((neighborId&(0xFFL<<56))>>1);//A;
long lightData = ((neighborId&(0xFFL<<56))>>>1);//A;
//if (!ModelQueries.faceUsesSelfLighting(Am, facingForward|(axis*2))) {//TODO: check this is right
// lighter = this.sectionData[bi];
//}

View File

@@ -104,6 +104,8 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
.defineIf("TAA_PATCH", taa != null)
.defineIf("DEBUG_RENDER", false)
//.defineIf("USE_NV_BARRY", Capabilities.INSTANCE.nvBarryCoords)
.defineIf("DARKENED_TINTING", Minecraft.getInstance().level.effects().constantAmbientLight())//TODO: FIXME: this is really jank atm
.addSource(ShaderType.VERTEX, vertex);

View File

@@ -2,6 +2,9 @@
//Use quad shuffling to compute fragment mip
//#extension GL_KHR_shader_subgroup_quad: enable
#ifdef USE_NV_BARRY
#extension GL_NV_fragment_shader_barycentric: require
#endif
layout(binding = 0) uniform sampler2D blockModelAtlas;
layout(binding = 2) uniform sampler2D depthTex;
@@ -12,7 +15,9 @@ layout(binding = 2) uniform sampler2D depthTex;
// however they are not a full block
layout(location = 0) in flat uvec4 interData;
#ifndef USE_NV_BARRY
layout(location = 1) in vec2 uv;
#endif
#ifdef DEBUG_RENDER
layout(location = 7) in flat uint quadDebug;
@@ -109,6 +114,10 @@ void main() {
//vec2 uv = vec2(0);
//Tile is the tile we are in
vec2 tile;
#ifdef USE_NV_BARRY
vec2 uv = mix(gl_BaryCoordNV.yx, 1-gl_BaryCoordNV.xz, gl_PrimitiveID&1)*(vec2((interData.x>>8)&0xFu, (interData.x>>12)&0xFu)+1);
#endif
vec2 uv2 = modf(uv, tile)*(1.0/(vec2(3.0,2.0)*256.0));
vec4 colour;
vec2 texPos = uv2 + getBaseUV();

View File

@@ -7,15 +7,13 @@
#define POSITION_SCRATCH_BINDING 5
#define LIGHTING_SAMPLER_BINDING 1
#define USE_INTERPOLATED_UV
#import <voxy:lod/quad_format.glsl>
#import <voxy:lod/block_model.glsl>
#import <voxy:lod/gl46/bindings.glsl>
#import <voxy:lod/quad_util.glsl>
layout(location = 0) out flat uvec4 interData;
#ifdef USE_INTERPOLATED_UV
#ifndef USE_NV_BARRY
layout(location = 1) out vec2 uv;
#endif
@@ -37,7 +35,7 @@ void main() {
uint cornerId = gl_VertexID&3;
gl_Position = getQuadCornerPos(quad, cornerId);
#ifdef USE_INTERPOLATED_UV
#ifndef USE_NV_BARRY
uv = getCornerUV(quad, cornerId);
#endif

View File

@@ -182,7 +182,7 @@ vec4 getQuadCornerPos(in QuadData quad, uint cornerId) {
return pos;
}
#ifdef USE_INTERPOLATED_UV
#ifndef USE_NV_BARRY
vec2 getCornerUV(const in QuadData quad, uint cornerId) {
return quad.uvCorner + quad.quadSizeAddin*vec2((cornerId>>1)&1u, cornerId&1u);
}