Fix a bunch of lighting issues
This commit is contained in:
@@ -385,7 +385,7 @@ public class ModelFactory {
|
||||
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;
|
||||
metadata |= (offset > 0.01 || blockRenderLayer == RenderLayer.getTranslucent())?0b1000:0;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -198,7 +198,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;
|
||||
lightAndBiome &= ModelQueries.isBiomeColoured(metadata)?-1:~(0x1FFL<<47);
|
||||
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?
|
||||
|
||||
long quadData = lightAndBiome;
|
||||
@@ -329,6 +329,8 @@ public class RenderDataFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private static final long LM = (0xFFL<<55);
|
||||
|
||||
private static boolean shouldMeshNonOpaqueBlockFace(int face, long quad, long meta, long neighborQuad, long neighborMeta) {
|
||||
if (((quad^neighborQuad)&(0xFFFFL<<26))==0) return false;//This is a hack, if the neigbor and this are the same, dont mesh the face
|
||||
if (!ModelQueries.faceExists(meta, face)) return false;//Dont mesh if no face
|
||||
@@ -340,8 +342,8 @@ public class RenderDataFactory {
|
||||
private static void meshNonOpaqueFace(int face, long quad, long meta, long neighborQuad, long neighborMeta, Mesher mesher) {
|
||||
if (shouldMeshNonOpaqueBlockFace(face, quad, meta, neighborQuad, neighborMeta)) {
|
||||
mesher.putNext((long) (face&1) |
|
||||
quad |
|
||||
((ModelQueries.faceUsesSelfLighting(meta, face)?quad:neighborQuad) & (0xFFL << 55)));
|
||||
(quad&~LM) |
|
||||
((ModelQueries.faceUsesSelfLighting(meta, face)?quad:neighborQuad) & LM));
|
||||
} else {
|
||||
mesher.skip(1);
|
||||
}
|
||||
@@ -397,8 +399,8 @@ public class RenderDataFactory {
|
||||
long selfModel = this.sectionData[iA];
|
||||
long nextModel = this.sectionData[iB];
|
||||
this.blockMesher.putNext(((long) facingForward) |//Facing
|
||||
selfModel |
|
||||
(nextModel & (0xFFL << 55))//Apply lighting
|
||||
(selfModel&~LM) |
|
||||
(nextModel&LM)//Apply lighting
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -462,9 +464,9 @@ public class RenderDataFactory {
|
||||
|
||||
long A = this.sectionData[idx * 2];
|
||||
|
||||
this.blockMesher.putNext((side == 0 ? 0L : 1L) |
|
||||
A |
|
||||
((neighborId&(0xFFL<<56))>>1)
|
||||
this.blockMesher.putNext(((side == 0) ? 0L : 1L) |
|
||||
(A&~LM) |
|
||||
((neighborId & (0xFFL << 56)) >> 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -547,8 +549,8 @@ public class RenderDataFactory {
|
||||
//}
|
||||
|
||||
this.blockMesher.putNext(((long) facingForward) |//Facing
|
||||
A |
|
||||
(lighter&(0xFFL<<55))//Apply lighting
|
||||
(A&~LM) |
|
||||
(lighter&LM)//Apply lighting
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -629,7 +631,7 @@ public class RenderDataFactory {
|
||||
}
|
||||
|
||||
this.blockMesher.putNext((side == 0 ? 0L : 1L) |
|
||||
A |
|
||||
(A&~LM) |
|
||||
((neighborId&(0xFFL<<56))>>1)
|
||||
);
|
||||
}
|
||||
@@ -764,6 +766,8 @@ public class RenderDataFactory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO: LIGHTING
|
||||
if (ModelQueries.faceExists(B, (axis<<1)|1) && ((side==1&&!fail) || (side==0&&!failB))) {
|
||||
this.blockMesher.putNext((long) (false ? 0L : 1L) |
|
||||
A |
|
||||
@@ -928,8 +932,8 @@ public class RenderDataFactory {
|
||||
|
||||
//Example thing thats just wrong but as example
|
||||
mesher.putNext(((long) facingForward) |//Facing
|
||||
selfModel |
|
||||
(nextModel&(0xFFL<<55))
|
||||
(selfModel&~LM) |
|
||||
(nextModel&LM)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -990,7 +994,7 @@ public class RenderDataFactory {
|
||||
ma.skip(skipA); skipA = 0;
|
||||
long A = this.sectionData[(i<<5) * 2];
|
||||
ma.putNext(0L |
|
||||
A |
|
||||
(A&~LM) |
|
||||
((neighborId&(0xFFL<<56))>>1)
|
||||
);
|
||||
} else {skipA++;}
|
||||
@@ -1011,7 +1015,7 @@ public class RenderDataFactory {
|
||||
mb.skip(skipB); skipB = 0;
|
||||
long A = this.sectionData[(i*32+31) * 2];
|
||||
mb.putNext(1L |
|
||||
A |
|
||||
(A&~LM) |
|
||||
((neighborId&(0xFFL<<56))>>1)
|
||||
);
|
||||
} else {skipB++;}
|
||||
@@ -1136,8 +1140,8 @@ public class RenderDataFactory {
|
||||
|
||||
//Example thing thats just wrong but as example
|
||||
mesher.putNext(((long) facingForward) |//Facing
|
||||
A |
|
||||
(lighter&(0xFFL<<55))//Lighting
|
||||
(A&~LM) |
|
||||
(lighter&LM)//Lighting
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1232,13 +1236,14 @@ public class RenderDataFactory {
|
||||
if (oki) {
|
||||
ma.skip(skipA); skipA = 0;
|
||||
|
||||
//TODO: LIGHTING
|
||||
long lightData = ((neighborId&(0xFFL<<56))>>1);//A;
|
||||
//if (!ModelQueries.faceUsesSelfLighting(Am, facingForward|(axis*2))) {//TODO: check this is right
|
||||
// lighter = this.sectionData[bi];
|
||||
//}
|
||||
|
||||
ma.putNext(0L |
|
||||
A |
|
||||
(A&~LM) |
|
||||
lightData
|
||||
);
|
||||
} else {skipA++;}
|
||||
@@ -1292,13 +1297,14 @@ public class RenderDataFactory {
|
||||
if (oki) {
|
||||
mb.skip(skipB); skipB = 0;
|
||||
|
||||
//TODO: LIGHTING
|
||||
long lightData = ((neighborId&(0xFFL<<56))>>1);//A;
|
||||
//if (!ModelQueries.faceUsesSelfLighting(Am, facingForward|(axis*2))) {//TODO: check this is right
|
||||
// lighter = this.sectionData[bi];
|
||||
//}
|
||||
|
||||
mb.putNext(1L |
|
||||
A |
|
||||
(A&~LM) |
|
||||
lightData
|
||||
);
|
||||
} else {skipB++;}
|
||||
@@ -1426,7 +1432,7 @@ public class RenderDataFactory {
|
||||
//TODO: Check (neighborAId!=0) && works oki
|
||||
if ((neighborAId==0 && ModelQueries.faceExists(meta, ((2<<1)|0)^side))||(neighborAId!=0&&shouldMeshNonOpaqueBlockFace(((2<<1)|0)^side, quad, meta, ((long)neighborAId)<<26, neighborAMeta))) {
|
||||
ma.putNext(((long)side)|
|
||||
quad |
|
||||
(quad&~LM) |
|
||||
(ModelQueries.faceUsesSelfLighting(meta, ((2<<1)|0)^side)?quad:(((long)neighborLight)<<55))
|
||||
);
|
||||
} else {
|
||||
@@ -1435,7 +1441,7 @@ public class RenderDataFactory {
|
||||
|
||||
if (shouldMeshNonOpaqueBlockFace(((2<<1)|1)^side, quad, meta, neighborBQuad, neighborBMeta)) {
|
||||
mb.putNext(((long)(side^1))|
|
||||
quad |
|
||||
(quad&~LM) |
|
||||
((ModelQueries.faceUsesSelfLighting(meta, ((2<<1)|1)^side)?quad:neighborBQuad)&(0xFFL<<55))
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,7 @@ import static org.lwjgl.opengl.GL45.glBindTextureUnit;
|
||||
|
||||
public class LightMapHelper {
|
||||
public static void bind(int lightingIndex) {
|
||||
glBindSampler(lightingIndex, 0);
|
||||
glBindTextureUnit(lightingIndex, ((net.minecraft.client.texture.GlTexture)(MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().getGlTexture())).getGlId());
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ layout(binding = LIGHTING_SAMPLER_BINDING) uniform sampler2D lightSampler;
|
||||
|
||||
vec4 getLighting(uint index) {
|
||||
int i2 = int(index);
|
||||
return texelFetch(lightSampler, ivec2((i2>>4)&0xF, i2&0xF), 0);
|
||||
return texture(lightSampler, clamp((vec2((i2>>4)&0xF, i2&0xF))/16, vec2(8.0f/255), vec2(248.0f/255)));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ void main() {
|
||||
flags |= uint(!modelHasMipmaps(model))<<1;
|
||||
|
||||
//Compute lighting
|
||||
tinting = getLighting(extractLightId(quad));
|
||||
tinting = getLighting(extractLightId(quad)).rgb;
|
||||
|
||||
//Apply model colour tinting
|
||||
uint tintColour = model.colourTint;
|
||||
@@ -148,11 +148,11 @@ void main() {
|
||||
if (isShaded) {
|
||||
//TODO: make branchless, infact apply ahead of time to the texture itself in ModelManager since that is
|
||||
// per face
|
||||
if ((face>>1) == 1) {
|
||||
if ((face>>1) == 1) {//NORTH, SOUTH
|
||||
tinting.xyz *= 0.8f;
|
||||
} else if ((face>>1) == 2) {
|
||||
} else if ((face>>1) == 2) {//EAST, WEST
|
||||
tinting.xyz *= 0.6f;
|
||||
} else if (face == 0){
|
||||
} else if (face == 0) {//DOWN
|
||||
tinting.xyz *= 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,21 +131,23 @@ bool isCulledByHiz() {
|
||||
vec2 ssize = size * vec2(screenW, screenH);
|
||||
float miplevel = log2(max(max(ssize.x, ssize.y),1));
|
||||
|
||||
if (miplevel > 9.5f) {
|
||||
//TODO: make a path for if the miplevel would result in the textureSampler sampling a size of 1
|
||||
|
||||
|
||||
miplevel = ceil(miplevel);
|
||||
miplevel = clamp(miplevel, 0, 20);
|
||||
|
||||
if (miplevel >= 10f) {//Level 9 or 10// TODO: FIX THIS JANK SHIT
|
||||
return false;
|
||||
}
|
||||
|
||||
miplevel = ceil(miplevel);
|
||||
//miplevel = clamp(miplevel, 0, 20);
|
||||
|
||||
vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f;
|
||||
//midpoint = clamp(midpoint, vec2(0), vec2(1));
|
||||
|
||||
float testAgainst = minBB.z;
|
||||
//the *2.0f-1.0f converts from the 0->1 range to -1->1 range that depth is in (not having this causes tighter bounds, but causes culling issues in caves)
|
||||
testAgainst = testAgainst*2.0f-1.0f;
|
||||
|
||||
bool culled = textureLod(hizDepthSampler, vec3(midpoint, testAgainst), miplevel) < 0.0001f;
|
||||
bool culled = textureLod(hizDepthSampler, clamp(vec3(midpoint, testAgainst), vec3(0), vec3(1)), miplevel) < 0.0001f;
|
||||
|
||||
//printf("HiZ sample point: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z);
|
||||
//if ((culled) && node22.lodLevel == 0) {
|
||||
|
||||
Reference in New Issue
Block a user