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

@ -462,7 +462,7 @@ block.198=lantern \
amendments:wall_lantern:light_level=15:lit=true \ amendments:wall_lantern:light_level=15:lit=true \
mcwlights:striped_lantern mcwlights:covered_lantern mcwlights:chain_lantern mcwlights:tavern_lantern mcwlights:festive_lantern mcwlights:cross_lantern mcwlights:bell_lantern mcwlights:wall_lantern mcwlights:striped_wall_lantern mcwlights:covered_wall_lantern mcwlights:chain_wall_lantern mcwlights:tavern_wall_lantern mcwlights:festive_wall_lantern mcwlights:cross_wall_lantern mcwlights:bell_wall_lantern mcwlights:classic_street_lamp:lit=true:part=top mcwlights:classic_street_lamp:lit=true:part=base mcwlights:double_street_lamp:lit=true:part=top mcwlights:double_street_lamp:lit=true:part=base mcwlights:striped_lantern mcwlights:covered_lantern mcwlights:chain_lantern mcwlights:tavern_lantern mcwlights:festive_lantern mcwlights:cross_lantern mcwlights:bell_lantern mcwlights:wall_lantern mcwlights:striped_wall_lantern mcwlights:covered_wall_lantern mcwlights:chain_wall_lantern mcwlights:tavern_wall_lantern mcwlights:festive_wall_lantern mcwlights:cross_wall_lantern mcwlights:bell_wall_lantern mcwlights:classic_street_lamp:lit=true:part=top mcwlights:classic_street_lamp:lit=true:part=base mcwlights:double_street_lamp:lit=true:part=top mcwlights:double_street_lamp:lit=true:part=base
block.199=lava \ block.199=lava minecraft:lava_cauldron \
flying_stuff:molten_metal:lit=true \ flying_stuff:molten_metal:lit=true \
mcwlights:lava_lamp:lit=true mcwlights:lava_lamp:lit=true

View File

@ -343,20 +343,16 @@ void main() {
float noise = R2_dither(); float noise = R2_dither();
vec2 texcoord = gl_FragCoord.xy*texelSize; vec2 texcoord = gl_FragCoord.xy*texelSize;
float z = texture(depthtex1,texcoord).x; float z = texelFetch2D(depthtex0,ivec2(gl_FragCoord.xy),0).x;
// float z = texelFetch2D(depthtex1,ivec2(gl_FragCoord.xy),0).x;
#ifdef DISTANT_HORIZONS #ifdef DISTANT_HORIZONS
float DH_depth1 = texture2D(dhDepthTex1,texcoord).x; float DH_depth1 = texelFetch2D(dhDepthTex1,ivec2(gl_FragCoord.xy),0).x;
float swappedDepth = z >= 1.0 ? DH_depth1 : z; float swappedDepth = z >= 1.0 ? DH_depth1 : z;
#else #else
float DH_depth1 = 1.0; float DH_depth1 = 1.0;
float swappedDepth = z; float swappedDepth = z;
#endif #endif
vec4 SHADOWDATA = vec4(0.0);
vec4 data = texelFetch2D(colortex1,ivec2(gl_FragCoord.xy),0); vec4 data = texelFetch2D(colortex1,ivec2(gl_FragCoord.xy),0);
vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y)); vec4 dataUnpacked0 = vec4(decodeVec2(data.x),decodeVec2(data.y));
vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w)); vec4 dataUnpacked1 = vec4(decodeVec2(data.z),decodeVec2(data.w));
@ -364,7 +360,7 @@ void main() {
vec2 lightmap = dataUnpacked1.yz; vec2 lightmap = dataUnpacked1.yz;
gl_FragData[1] = vec4(0.0,0.0,0.0, texture2D(colortex14,floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize).a); gl_FragData[1] = vec4(0.0,0.0,0.0, texelFetch2D(colortex14,ivec2((floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize+0.5*texelSize)/texelSize),0).a);
// bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01; // bool lightningBolt = abs(dataUnpacked1.w-0.5) <0.01;

View File

@ -501,13 +501,11 @@ void main() {
vec2 BN = fract(r2_sequence + bnoise); vec2 BN = fract(r2_sequence + bnoise);
// vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize + texelSize*0.5; // vec2 tc = floor(gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize + texelSize*0.5;
vec2 tc = gl_FragCoord.xy/VL_RENDER_RESOLUTION*texelSize;// + texelSize*0.5; vec2 tc = (gl_FragCoord.xy)/VL_RENDER_RESOLUTION*texelSize;
bool iswater = texture2D(colortex7,tc).a > 0.99; bool iswater = texture2D(colortex7,tc).a > 0.99;
vec2 jitter = TAA_Offset/VL_RENDER_RESOLUTION*texelSize*0.5; float depth = texelFetch2D(depthtex0, ivec2(tc/texelSize),0).x;
float depth = texture2D(depthtex0, tc + jitter).x;
float z0 = depth < 0.56 ? convertHandDepth(depth) : depth; float z0 = depth < 0.56 ? convertHandDepth(depth) : depth;
@ -573,6 +571,7 @@ void main() {
} }
// VolumetricFog = raymarchTest2(viewPos0, BN.x);
// VolumetricFog = raymarchTest(viewPos0, BN); // VolumetricFog = raymarchTest(viewPos0, BN);

View File

@ -313,26 +313,66 @@ vec3 toScreenSpace_DH_special(vec3 POS, bool depthCheck ) {
return viewPos.xyz; return viewPos.xyz;
} }
vec4 VLTemporalFiltering(vec3 viewPos, bool depthCheck, out float DEBUG){ vec4 bilateralUpsample(out float outerEdgeResults, float referenceDepth, sampler2D depth){
// vec2 texcoord = ((gl_FragCoord.xy)*2.0 + 0.5)*texelSize/2.0 ;
vec2 texcoord = gl_FragCoord.xy*texelSize;
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); vec4 VLTemporalFiltering(vec3 viewPos, in float referenceDepth, sampler2D depth){
// vec3 viewPos_5tap = toScreenSpace(closestToCamera);
vec2 offsetTexcoord = gl_FragCoord.xy*texelSize;
vec2 VLtexCoord = offsetTexcoord * VL_RENDER_RESOLUTION;
// get previous frames position stuff for UV // get previous frames position stuff for UV
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition); vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz; vec3 previousPosition = mat3(gbufferPreviousModelView) * playerPos + gbufferPreviousModelView[3].xyz;
previousPosition = toClipSpace3Prev(previousPosition); previousPosition = toClipSpace3Prev(previousPosition);
vec2 velocity = previousPosition.xy - texcoord; vec2 velocity = previousPosition.xy - offsetTexcoord;
previousPosition.xy = texcoord + velocity; previousPosition.xy = offsetTexcoord + velocity;
vec4 currentFrame = texture2D(colortex0, VLtexCoord); 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; 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 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 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 frameHistory = texture2D(colortex10, previousPosition.xy*RENDER_SCALE);
vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax); vec4 clampedFrameHistory = clamp(frameHistory, colMin, colMax);
float blendingFactor = 0.1; float blendingFactor = 0.1;
if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0; if(abs(clampedFrameHistory.a - frameHistory.a) > 0.1) blendingFactor = 1.0;
// DEBUG = abs(clampedFrameHistory.a - frameHistory.a) > 0.1 ? 0. : 1.0; vec4 reprojectFrame = mix(clampedFrameHistory, currentFrame, blendingFactor);
// DEBUG = clamp(abs(clampedFrameHistory.a - frameHistory.a),0.0,1.0);
// return clamp(reprojectFrame,0.0,65000.0);
return clamp(mix(clampedFrameHistory, currentFrame, blendingFactor),0.0,65000.0); return clamp(mix(reprojectFrame, upsampledCurrentFrame, outerEdgeResults),0.0,65000.0);
} }
uniform float waterEnteredAltitude; uniform float waterEnteredAltitude;
@ -369,7 +410,7 @@ void main() {
////// --------------- SETUP STUFF --------------- ////// ////// --------------- SETUP STUFF --------------- //////
vec2 texcoord = gl_FragCoord.xy*texelSize; 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 z2 = texture2D(depthtex1, texcoord).x;
float frDepth = ld(z); float frDepth = ld(z);
@ -397,7 +438,6 @@ void main() {
vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz; vec3 playerPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz;
vec3 playerPos_normalized = normVec(playerPos); 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 viewPos_alt = toScreenSpace(vec3(texcoord/RENDER_SCALE, z2));
vec3 playerPos_alt = mat3(gbufferModelViewInverse) * viewPos_alt + gbufferModelViewInverse[3].xyz; 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; bool isEntity = abs(translucentMasks - 0.9) < 0.01 || isReflectiveEntity;
////// --------------- get volumetrics ////// --------------- get volumetrics
#ifdef DISTANT_HORIZONS
#if defined OVERWORLD_SHADER && defined CLOUDS_INTERSECT_TERRAIN float DH_mixedLinearZ = sqrt(texelFetch2D(colortex12,ivec2(gl_FragCoord.xy),0).a/65000.0);
float cloudAlpha = 0.0; vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, DH_mixedLinearZ, colortex12);
#else #else
float cloudAlpha = 1.0; vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, frDepth, depthtex0);
#endif #endif
float DEBUG = 0.0;
vec4 temporallyFilteredVL = VLTemporalFiltering(viewPos, z >= 1.0, DEBUG);
gl_FragData[2] = temporallyFilteredVL; gl_FragData[2] = temporallyFilteredVL;
// temporallyFilteredVL = texture2D(colortex0, texcoord*VL_RENDER_RESOLUTION);
float bloomyFogMult = 1.0; float bloomyFogMult = 1.0;
@ -564,6 +600,9 @@ void main() {
bloomyFogMult *= temporallyFilteredVL.a; bloomyFogMult *= temporallyFilteredVL.a;
#if defined IS_IRIS #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 *= min(temporallyFilteredVL.a + (1-nametagbackground),1.0);
color += temporallyFilteredVL.rgb * nametagbackground; color += temporallyFilteredVL.rgb * nametagbackground;
#else #else

View File

@ -136,10 +136,10 @@ void main() {
vec2 halfResTC2 = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY+0.5+offsets[framemod8]*CLOUDS_QUALITY*0.5); vec2 halfResTC2 = vec2(floor(gl_FragCoord.xy)/CLOUDS_QUALITY+0.5+offsets[framemod8]*CLOUDS_QUALITY*0.5);
#ifdef CLOUDS_INTERSECT_TERRAIN #ifdef CLOUDS_INTERSECT_TERRAIN
float depth = texture2D(depthtex0, halfResTC2*texelSize).x; float depth = texelFetch2D(depthtex0, ivec2(halfResTC2), 0).x;
#ifdef DISTANT_HORIZONS #ifdef DISTANT_HORIZONS
float DH_depth = texture2D(dhDepthTex, halfResTC2*texelSize).x; float DH_depth = texelFetch2D(dhDepthTex, ivec2(halfResTC2),0).x;
vec3 viewPos = toScreenSpace_DH(halfResTC*texelSize, depth, DH_depth); vec3 viewPos = toScreenSpace_DH(halfResTC*texelSize, depth, DH_depth);
#else #else
vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, depth)); vec3 viewPos = toScreenSpace(vec3(halfResTC*texelSize, depth));