do bilateral upsample on volumetrics to fix pixel gaps around geometry edges. quickly add lava cauldron a lightsource

This commit is contained in:
Xonk
2025-03-13 19:58:12 -04:00
parent 7fe056d00e
commit 1faf3d62fd
5 changed files with 74 additions and 40 deletions

View File

@ -313,26 +313,66 @@ vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
return viewPos.xyz;
}
vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){
// vec2 texcoord = ((gl_FragCoord.xy)*2.0 + 0.5)*texelSize/2.0 ;
vec2 texcoord = gl_FragCoord.xy*texelSize;
vec4 bilateralUpsample(out float outerEdgeResults, float referenceDepth, sampler2D depth){
vec2 VLtexCoord = texcoord * VL_RENDER_RESOLUTION;
vec4 colorSum = vec4(0.0);
float edgeSum = 0.0;
float threshold = 0.005;
vec2 UV = gl_FragCoord.xy + 2 + (ivec2(gl_FragCoord.xy + frameCounter)%2)*2;
const ivec2 SCALE = ivec2(1.0/VL_RENDER_RESOLUTION);
ivec2 UV_DEPTH = ivec2(UV*VL_RENDER_RESOLUTION)*SCALE;
ivec2 UV_COLOR = ivec2(UV*VL_RENDER_RESOLUTION);
ivec2[4] OFFSET = ivec2[4] (
ivec2(-2, -2),
ivec2(-2, 0),
ivec2( 0, 0),
ivec2( 0, -2)
);
for(int i = 0; i < 4; i++) {
#ifdef DISTANT_HORIZONS
float offsetDepth = sqrt(texelFetch2D(depth, UV_DEPTH + OFFSET[i] * SCALE,0).a/65000.0);
#else
float offsetDepth = ld(texelFetch2D(depth, UV_DEPTH + OFFSET[i] * SCALE, 0).r);
#endif
float edgeDiff = abs(offsetDepth - referenceDepth) < threshold ? 1.0 : 1e-7;
outerEdgeResults = max(outerEdgeResults, clamp(referenceDepth - offsetDepth,0.0,1.0));
vec4 offsetColor = texelFetch2D(colortex0, UV_COLOR + OFFSET[i], 0).rgba;
colorSum += offsetColor*edgeDiff;
edgeSum += edgeDiff;
}
outerEdgeResults = outerEdgeResults > 0.1 ? 1.0 : 0.0;
return colorSum / edgeSum;
}
// vec3 closestToCamera = closestToCamera5taps(texcoord, depthtex0);
// vec3 viewPos_5tap = toScreenSpace(closestToCamera);
vec4 VLTemporalFiltering(vec3 viewPos, in float referenceDepth, sampler2D depth){
vec2 offsetTexcoord = gl_FragCoord.xy*texelSize;
vec2 VLtexCoord = offsetTexcoord * VL_RENDER_RESOLUTION;
// get previous frames position stuff for UV
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - texcoord;
previousPosition.xy = texcoord + velocity;
vec2 velocity = previousPosition.xy - offsetTexcoord;
previousPosition.xy = offsetTexcoord + velocity;
vec4 currentFrame = texture2D(colortex0, VLtexCoord);
// return currentFrame;
// to fill pixel gaps in geometry edges, do a bilateral upsample.
// pass a mask to only show upsampled color around the edges of blocks. this is so it doesnt blur reprojected results.
float outerEdgeResults = 0.0;
vec4 upsampledCurrentFrame = bilateralUpsample(outerEdgeResults, referenceDepth, depth);
if (previousPosition.x < 0.0 || previousPosition.y < 0.0 || previousPosition.x > 1.0 || previousPosition.y > 1.0) return currentFrame;
@ -347,18 +387,19 @@ vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){
vec4 colMax = max(currentFrame,max(col1,max(col2,max(col3, max(col4, max(col5, max(col6, max(col7, col8))))))));
vec4 colMin = min(currentFrame,min(col1,min(col2,min(col3, min(col4, min(col5, min(col6, min(col7, col8))))))));
vec4 frameHistory = texture2D(colortex10, previousPosition.xy*RENDER_SCALE);
vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax);
float blendingFactor = 0.1;
if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0;
// DEBUG = abs(clampedFrameHistory.a - frameHistory.a) > 0.1 ? 0. : 1.0;
// DEBUG = clamp(abs(clampedFrameHistory.a - frameHistory.a),0.0,1.0);
return clamp(mix(clampedFrameHistory, currentFrame, blendingFactor),0.0,65000.0);
vec4 reprojectFrame = mix(clampedFrameHistory, currentFrame, blendingFactor);
// return clamp(reprojectFrame,0.0,65000.0);
return clamp(mix(reprojectFrame, upsampledCurrentFrame, outerEdgeResults),0.0,65000.0);
}
uniform float waterEnteredAltitude;
@ -369,7 +410,7 @@ void main() {
////// --------------- SETUP STUFF --------------- //////
vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture2D(depthtex0, texcoord).x;
float z = texelFetch2D(depthtex0, ivec2(gl_FragCoord.xy),0).x;//texture2D(depthtex0, texcoord).x;
float z2 = texture2D(depthtex1, texcoord).x;
float frDepth = ld(z);
@ -397,7 +438,6 @@ void main() {
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 playerPos_normalized = normVec(playerPos);
vec3 playerPos222 = mat3(gbufferModelViewInverse) * toScreenSpace_DH(texcoord/RENDER_SCALE, 1.0,1.0) + gbufferModelViewInverse[3].xyz ;
vec3 viewPos_alt = toScreenSpace(vec3(texcoord/RENDER_SCALE, z2));
vec3 playerPos_alt = mat3(gbufferModelViewInverse) * viewPos_alt + gbufferModelViewInverse[3].xyz;
@ -438,19 +478,15 @@ void main() {
bool isEntity = abs(translucentMasks - 0.9) < 0.01 || isReflectiveEntity;
////// --------------- get volumetrics
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN
float cloudAlpha = 0.0;
#ifdef DISTANT_HORIZONS
float DH_mixedLinearZ = sqrt(texelFetch2D(colortex12,ivec2(gl_FragCoord.xy),0).a/65000.0);
vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, DH_mixedLinearZ, colortex12);
#else
float cloudAlpha = 1.0;
vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, frDepth, depthtex0);
#endif
float DEBUG = 0.0;
vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, z >= 1.0, DEBUG);
gl_FragData[2] = temporallyFilteredVL;
// temporallyFilteredVL = texture2D(colortex0, texcoord*VL_RENDER_RESOLUTION);
float bloomyFogMult = 1.0;
@ -564,6 +600,9 @@ void main() {
bloomyFogMult *= temporallyFilteredVL.a;
#if defined IS_IRIS
// if(z >= 1.0) color = vec3(0,255,0);
// else color = vec3(0.01);
color *= min(temporallyFilteredVL.a + (1-nametagbackground),1.0);
color += temporallyFilteredVL.rgb * nametagbackground;
#else