Fix a bunch of lighting issues

This commit is contained in:
mcrcortex
2025-05-08 22:56:58 +10:00
parent cbc8428e23
commit 79f42760b0
6 changed files with 42 additions and 33 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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) {