Fix and improve DH SSR

This commit is contained in:
Merlin1809
2025-07-17 15:03:23 +02:00
parent 38017b26bf
commit b32d64caeb
7 changed files with 85 additions and 50 deletions
+34 -32
View File
@@ -104,7 +104,7 @@ float ld(float dist) {
// }
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
return (2.0 * near) / (dhFarPlane + near - dist * (dhFarPlane - near));
}
float DH_inv_ld (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
@@ -154,43 +154,45 @@ uniform int framemod8;
#include "/lib/TAA_jitter.glsl"
vec3 rayTrace(vec3 dir, vec3 position,float dither, float fresnel, bool inwater){
vec3 rayTrace(vec3 dir, vec3 position, float dither, float fresnel) {
float quality = mix(5,SSR_STEPS,fresnel);
float biasAmount = 0.000075;
float quality = mix(5, SSR_STEPS, fresnel);
vec3 clipPosition = DH_toClipSpace3(position);
float rayLength = ((position.z + dir.z * dhFarPlane*sqrt(3.)) > -dhNearPlane) ?
float rayLength = ((position.z + dir.z * dhFarPlane*sqrt(3.)) > -dhNearPlane) ?
(-dhNearPlane - position.z) / dir.z : dhFarPlane*sqrt(3.);
vec3 direction = normalize(DH_toClipSpace3(position+dir*rayLength)-clipPosition); //convert to clip space
direction.xy = normalize(direction.xy);
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.,direction)-clipPosition) / direction;
float mult = min(min(maxLengths.x,maxLengths.y),maxLengths.z);
vec3 stepv = direction * mult / quality * vec3(RENDER_SCALE,1.0);
vec3 spos = clipPosition*vec3(RENDER_SCALE,1.0) + stepv*dither;
float minZ = clipPosition.z;
float maxZ = spos.z+stepv.z*0.5;
spos.xy += offsets[framemod8]*texelSize*0.5/RENDER_SCALE;
vec3 direction = DH_toClipSpace3(position + dir * rayLength) - clipPosition; //convert to clip space
//get at which length the ray intersects with the edge of the screen
vec3 maxLengths = (step(0.0, direction) - clipPosition) / direction;
float mult = min(min(maxLengths.x, maxLengths.y), maxLengths.z);
vec3 stepv = direction * mult / quality;
clipPosition.xy *= RENDER_SCALE;
stepv.xy *= RENDER_SCALE;
vec3 spos = clipPosition + stepv * dither;
spos.xy += offsets[framemod8] * texelSize * 0.5 / RENDER_SCALE;
float minZ = spos.z - 0.00025 / DH_ld(spos.z);
float maxZ = spos.z;
for (int i = 0; i <= int(quality); i++) {
// float sp = DH_inv_ld(sqrt(texelFetch2D(colortex12,ivec2(spos.xy/texelSize/4),0).a/65000.0));
float sp = DH_inv_ld(sqrt(texelFetch2D(colortex12,ivec2(spos.xy/texelSize/4),0).a/64000.0));
if(sp < max(minZ,maxZ) && sp > min(minZ,maxZ)) return vec3(spos.xy/RENDER_SCALE,sp);
float sampleDepth = sqrt(texelFetch2D(colortex4, ivec2(spos.xy / (texelSize * 4.0)), 0).a / 130000.0);
float sp = DH_inv_ld(sampleDepth);
if (sp < max(minZ, maxZ) && sp > min(minZ, maxZ)) {
return vec3(spos.xy / RENDER_SCALE, sp);
}
minZ = maxZ - biasAmount / DH_ld(spos.z);
maxZ += stepv.z;
spos += stepv;
//small bias
minZ = maxZ-0.00005/DH_ld(spos.z);
maxZ += stepv.z;
}
return vec3(1.1);
}
@@ -414,7 +416,7 @@ if (gl_FragCoord.x * texelSize.x < 1.0 && gl_FragCoord.y * texelSize.y < 1.0 )
if(isEyeInWater == 1) fresnel = pow(clamp(1.5 + normalDotEye,0.0,1.0), 25.0);
#endif
#if defined FORWARD_ENVIORNMENT_REFLECTION && defined DH_SCREENSPACE_REFLECTIONS
vec3 rtPos = rayTrace(reflectedVector, viewPos, interleaved_gradientNoise_temporal(), fresnel, false);
vec3 rtPos = rayTrace(reflectedVector, viewPos, interleaved_gradientNoise_temporal(), fresnel);
if (rtPos.z < 1.){
vec3 previousPosition = mat3(gbufferModelViewInverse) * DH_toScreenSpace(rtPos) + gbufferModelViewInverse[3].xyz + cameraPosition-previousCameraPosition;
previousPosition = mat3(gbufferPreviousModelView) * previousPosition + gbufferPreviousModelView[3].xyz;
+2 -1
View File
@@ -114,6 +114,8 @@ uniform float waterEnteredAltitude;
uniform vec3 waterExitedVelocity;
#endif
uniform float dhFarPlane;
#include "/lib/util.glsl"
#include "/lib/Shadow_Params.glsl"
#include "/lib/color_transforms.glsl"
@@ -291,7 +293,6 @@ float ld(float dist) {
return (2.0 * near) / (far + near - dist * (far - near));
}
uniform float dhFarPlane;
#include "/lib/DistantHorizons_projections.glsl"
+1 -1
View File
@@ -6,7 +6,7 @@ const int colortex0Format = RGBA16F; // low res clouds (deferred->composite2)
const int colortex1Format = RGBA16; // terrain gbuffer (gbuffer->composite2)
const int colortex2Format = RGBA16F; // forward + transparencies (gbuffer->composite4)
const int colortex3Format = R11F_G11F_B10F; // frame buffer + bloom (deferred6->final)
const int colortex4Format = RGBA16F; // light values and skyboxes (everything)
const int colortex4Format = RGBA32F; // light values and skyboxes (everything)
const int colortex6Format = R11F_G11F_B10F; // additionnal buffer for bloom (composite3->final)
const int colortex7Format = RGBA8; // Final output, transparencies id (gbuffer->composite4)
const int colortex8Format = RGBA8; // Specular Texture
+33 -11
View File
@@ -24,6 +24,9 @@ uniform float dhNearPlane;
float DH_ld(float dist) {
return (2.0 * dhNearPlane) / (dhFarPlane + dhNearPlane - dist * (dhFarPlane - dhNearPlane));
}
float DH_ld_mixed(float dist) {
return (2.0 * near) / (dhFarPlane + near - dist * (dhFarPlane - near));
}
float DH_invLinZ (float lindepth){
return -((2.0*dhNearPlane/lindepth)-dhFarPlane-dhNearPlane)/(dhFarPlane-dhNearPlane);
}
@@ -58,16 +61,35 @@ void main() {
if(hand) convertHandDepth(newTex);
#ifdef DISTANT_HORIZONS
float QuarterResDepth = texelFetch2D(dhDepthTex, ivec2(gl_FragCoord.xy*4), 0).x;
if(newTex >= 1.0) newTex = sqrt(QuarterResDepth);
gl_FragData[1].a = (DH_ld(QuarterResDepth)*DH_ld(QuarterResDepth))*65000.0;
#endif
if (newTex < 1.0)
gl_FragData[0] = vec4(oldTex, linZ(newTex)*linZ(newTex)*65000.0);
else
gl_FragData[0] = vec4(oldTex, 2.0);
#ifdef DISTANT_HORIZONS
float QuarterResDepth = texelFetch2D(dhDepthTex, ivec2(gl_FragCoord.xy*4), 0).x;
if(newTex == 1.0) {
float depth = DH_ld(QuarterResDepth);
gl_FragData[0] = vec4(oldTex, depth * depth * 130000.0);
gl_FragData[1].a = depth * depth * 65000.0;
} else {
float depth = DH_ld_mixed(newTex);
gl_FragData[0] = vec4(oldTex, depth * depth * 65000.0);
}
//sky
if (newTex == 1.0 && QuarterResDepth == 1.0) {
#ifdef CLOUD_SSR
gl_FragData[0] = vec4(oldTex, 65000.0);
#else
gl_FragData[0] = vec4(oldTex, 650000.0);
#endif
}
#else
if(newTex < 1.0) {
float depth = linZ(newTex);
gl_FragData[0] = vec4(oldTex, depth * depth * 65000.0);
} else {
#ifdef CLOUD_SSR
gl_FragData[0] = vec4(oldTex, 60000.0);
#else
gl_FragData[0] = vec4(oldTex, 600000.0);
#endif
}
#endif
}
+2
View File
@@ -34,6 +34,8 @@
#define USE_QUARTER_RES_DEPTH
#define SNELLS_WINDOW
// #define CLOUD_SSR
////////////////////////////////////////
// ----- PLANT RELATED SETTINGS ----- //
////////////////////////////////////////
+10 -3
View File
@@ -1,6 +1,13 @@
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
#ifdef DISTANT_HORIZONS
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-dhFarPlane-near)/(dhFarPlane-near);
}
#else
float invLinZ (float lindepth){
return -((2.0*near/lindepth)-far-near)/(far-near);
}
#endif
float linZ(float depth) {
return (2.0 * near) / (far + near - depth * (far - near));
// l = (2*n)/(f+n-d(f-n))
+3 -2
View File
@@ -230,7 +230,8 @@ SHADER_VERSION_LABEL <profile> \
DEFERRED_ENVIORNMENT_REFLECTION FORWARD_ENVIORNMENT_REFLECTION \
DEFERRED_BACKGROUND_REFLECTION FORWARD_BACKGROUND_REFLECTION \
DEFERRED_ROUGH_REFLECTION FORWARD_ROUGH_REFLECTION \
Sun_specular_Strength Roughness_Threshold
Sun_specular_Strength Roughness_Threshold \
SSR_STEPS
screen.Subsurface_Scattering.columns=1
screen.Subsurface_Scattering = SSS_TYPE sss_density_multiplier sss_absorbance_multiplier LabSSS_Curve <empty> MISC_BLOCK_SSS MOB_SSS <empty> Ambient_SSS ambientsss_brightness SCREENSPACE_DIRECT_SSS_BLENDING
@@ -422,7 +423,7 @@ SHADER_VERSION_LABEL <profile> \
######## MISC SETTINGS
screen.Misc_Settings = [EXPERIMENTAL_STUFF] DEBUG_VIEW [the_end_orb] display_LUT WhiteWorld SSS_view ambientLight_only LIGHTNING_FLASH DISABLE_ENCHANT_GLINT DISABLE_VANILLA_EMISSIVES PARTICLE_RENDERING_FIX TRANSLUCENT_ENTITIES LIGHTING_EFFECTS_BLUR_FILTER [selection_box_outline] ISOLATE_RESOURCEPACK_SKY [scene_controller]
screen.EXPERIMENTAL_STUFF = CAVE_DETECTION BLOOMY_PARTICLES ORIGINAL_CHOCAPIC_SKY BIOME_TINT_WATER HYPER_DETAILED_WAVES OLD_BLOOM PLANET_GROUND_BRIGHTNESS LIT_PARTICLE_BRIGHTNESS WATER_CAUSTICS_BRIGHTNESS WATER_CAUSTICS_POWER OLD_CAVE_DETECTION FORCE_TRANSLUCENT_GLASS LARGE_WAVE_DISPLACEMENT OLD_INDIRECT_SSS
screen.EXPERIMENTAL_STUFF = CAVE_DETECTION BLOOMY_PARTICLES ORIGINAL_CHOCAPIC_SKY BIOME_TINT_WATER HYPER_DETAILED_WAVES OLD_BLOOM PLANET_GROUND_BRIGHTNESS LIT_PARTICLE_BRIGHTNESS WATER_CAUSTICS_BRIGHTNESS WATER_CAUSTICS_POWER OLD_CAVE_DETECTION FORCE_TRANSLUCENT_GLASS LARGE_WAVE_DISPLACEMENT OLD_INDIRECT_SSS CLOUD_SSR
screen.the_end_orb.columns = 1
screen.the_end_orb = THE_ORB ORB_X ORB_Y ORB_Z ORB_ColMult ORB_R ORB_G ORB_B