From 85a1b68bf04153fe6a330744f2c2ddded09e7aa9 Mon Sep 17 00:00:00 2001 From: Sasha Date: Wed, 13 Mar 2024 23:38:04 +0000 Subject: [PATCH] fixed jitter dof and added it to dh geometry --- shaders/dimensions/DH_solid.vsh | 27 +++++++++++++++ shaders/dimensions/DH_translucent.vsh | 28 ++++++++++++++++ shaders/dimensions/all_translucent.vsh | 18 ++++++++++ shaders/dimensions/composite11.fsh | 46 +++++++++++++++++++++++++- shaders/lang/en_us.lang | 16 +++++---- shaders/shaders.properties | 2 +- 6 files changed, 129 insertions(+), 8 deletions(-) diff --git a/shaders/dimensions/DH_solid.vsh b/shaders/dimensions/DH_solid.vsh index 6b2083d..b0e92a9 100644 --- a/shaders/dimensions/DH_solid.vsh +++ b/shaders/dimensions/DH_solid.vsh @@ -11,6 +11,15 @@ flat varying float EMISSIVE; uniform vec2 texelSize; uniform int framemod8; +#if DOF_QUALITY == 5 +uniform int hideGUI; +uniform int frameCounter; +uniform float aspectRatio; +uniform float screenBrightness; +uniform float far; +#include "/lib/bokeh.glsl" +#endif + const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(-1.,3.)/8., vec2(5.0,1.)/8., @@ -74,4 +83,22 @@ void main() { float MATERIALS = 0.65; normals_and_materials = vec4(normalize(gl_NormalMatrix * gl_Normal), MATERIALS); + + #if DOF_QUALITY == 5 + vec2 jitter = clamp(jitter_offsets[frameCounter % 64], -1.0, 1.0); + jitter = rotate(radians(float(frameCounter))) * jitter; + jitter.y *= aspectRatio; + jitter.x *= DOF_ANAMORPHIC_RATIO; + + #if MANUAL_FOCUS == -2 + float focusMul = 0; + #elif MANUAL_FOCUS == -1 + float focusMul = gl_Position.z + (far / 3.0) - mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25); + #else + float focusMul = gl_Position.z + (far / 3.0) - MANUAL_FOCUS; + #endif + + vec2 totalOffset = (jitter * JITTER_STRENGTH) * focusMul * 1e-2; + gl_Position.xy += hideGUI >= 1 ? totalOffset : vec2(0); + #endif } \ No newline at end of file diff --git a/shaders/dimensions/DH_translucent.vsh b/shaders/dimensions/DH_translucent.vsh index f378d2c..183d25c 100644 --- a/shaders/dimensions/DH_translucent.vsh +++ b/shaders/dimensions/DH_translucent.vsh @@ -27,6 +27,16 @@ uniform float sunElevation; uniform vec2 texelSize; uniform int framemod8; +#if DOF_QUALITY == 5 +uniform int hideGUI; +uniform int frameCounter; +uniform float aspectRatio; +uniform float screenBrightness; +uniform float far; +#include "/lib/bokeh.glsl" +#endif + + const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), vec2(-1.,3.)/8., vec2(5.0,1.)/8., @@ -93,4 +103,22 @@ void main() { gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; #endif + #if DOF_QUALITY == 5 + vec2 jitter = clamp(jitter_offsets[frameCounter % 64], -1.0, 1.0); + jitter = rotate(radians(float(frameCounter))) * jitter; + jitter.y *= aspectRatio; + jitter.x *= DOF_ANAMORPHIC_RATIO; + + #if MANUAL_FOCUS == -2 + float focusMul = 0; + #elif MANUAL_FOCUS == -1 + float focusMul = gl_Position.z + (far / 3.0) - mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25); + #else + float focusMul = gl_Position.z + (far / 3.0) - MANUAL_FOCUS; + #endif + + vec2 totalOffset = (jitter * JITTER_STRENGTH) * focusMul * 1e-2; + gl_Position.xy += hideGUI >= 1 ? totalOffset : vec2(0); + #endif + } \ No newline at end of file diff --git a/shaders/dimensions/all_translucent.vsh b/shaders/dimensions/all_translucent.vsh index 1c08fce..3fed393 100644 --- a/shaders/dimensions/all_translucent.vsh +++ b/shaders/dimensions/all_translucent.vsh @@ -150,4 +150,22 @@ void main() { #ifdef TAA gl_Position.xy += offsets[framemod8] * gl_Position.w*texelSize; #endif + + #if DOF_QUALITY == 5 + vec2 jitter = clamp(jitter_offsets[frameCounter % 64], -1.0, 1.0); + jitter = rotate(radians(float(frameCounter))) * jitter; + jitter.y *= aspectRatio; + jitter.x *= DOF_ANAMORPHIC_RATIO; + + #if MANUAL_FOCUS == -2 + float focusMul = 0; + #elif MANUAL_FOCUS == -1 + float focusMul = gl_Position.z - mix(pow(512.0, screenBrightness), 512.0 * screenBrightness, 0.25); + #else + float focusMul = gl_Position.z - MANUAL_FOCUS; + #endif + + vec2 totalOffset = (jitter * JITTER_STRENGTH) * focusMul * 1e-2; + gl_Position.xy += hideGUI >= 1 ? totalOffset : vec2(0); + #endif } diff --git a/shaders/dimensions/composite11.fsh b/shaders/dimensions/composite11.fsh index 1cbfa93..72284b5 100644 --- a/shaders/dimensions/composite11.fsh +++ b/shaders/dimensions/composite11.fsh @@ -32,6 +32,7 @@ uniform float far; uniform float rainStrength; uniform float screenBrightness; uniform vec4 Moon_Weather_properties; // R = cloud coverage G = fog density +uniform int hideGUI; uniform int framemod8; const vec2[8] offsets = vec2[8](vec2(1./8.,-3./8.), @@ -67,6 +68,8 @@ float ld(float depth) { // uniform sampler2D depthtex0; uniform sampler2D dhDepthTex; +uniform float dhNearPlane; +uniform float dhFarPlane; // uniform mat4 gbufferProjectionInverse; uniform mat4 dhProjectionInverse; @@ -110,6 +113,9 @@ vec3 ACESFilm2(vec3 x){ return clamp((x*(a*x+b))/(x*(c*x+d)+e),0.0,1.0); } +float linearizeDepthFast(const in float depth, const in float near, const in float far) { + return (near * far) / (depth * (near - far) + far); +} #define linear_to_srgb(x) (pow(x, vec3(1.0/2.2))) void main() { @@ -117,7 +123,7 @@ void main() { float vignette = (1.5-dot(texcoord-0.5,texcoord-0.5)*2.); vec3 col = texture2D(colortex5,texcoord).rgb; - #if DOF_QUALITY >= 0 && DOF_QUALITY < 5 + #if DOF_QUALITY >= 0 /*--------------------------------*/ float z = ld(texture2D(depthtex0, texcoord.st*RENDER_SCALE).r)*far; #if MANUAL_FOCUS == -2 @@ -127,6 +133,7 @@ void main() { #elif MANUAL_FOCUS > 0 float focus = MANUAL_FOCUS; #endif + #if DOF_QUALITY < 5 float pcoc = min(abs(aperture * (focal/100.0 * (z - focus)) / (z * (focus - focal/100.0))),texelSize.x*15.0); #ifdef FAR_BLUR_ONLY pcoc *= float(z > focus); @@ -144,6 +151,7 @@ void main() { bcolor += texture2DLod(colortex5, texcoord.xy + bokeh_offsets[i]*pcoc*vec2(DOF_ANAMORPHIC_RATIO,aspectRatio), dofLodLevel).rgb; } col = bcolor/BOKEH_SAMPLES; + #endif #endif vec2 clampedRes = max(vec2(viewWidth,viewHeight),vec2(1920.0,1080.)); @@ -192,4 +200,40 @@ void main() { #endif gl_FragData[0].rgb = clamp(int8Dither(col,texcoord),0.0,1.0); + + + #if DOF_QUALITY == 5 + #if FOCUS_LASER_COLOR == 0 // Red + vec3 laserColor = vec3(25, 0, 0); + #elif FOCUS_LASER_COLOR == 1 // Green + vec3 laserColor = vec3(0, 25, 0); + #elif FOCUS_LASER_COLOR == 2 // Blue + vec3 laserColor = vec3(0, 0, 25); + #elif FOCUS_LASER_COLOR == 3 // Pink + vec3 laserColor = vec3(25, 10, 15); + #elif FOCUS_LASER_COLOR == 4 // Yellow + vec3 laserColor = vec3(25, 25, 0); + #elif FOCUS_LASER_COLOR == 5 // White + vec3 laserColor = vec3(25); + #endif + float depth = texture(depthtex0, texcoord).r; + + #ifdef DISTANT_HORIZONS + float _near = near; + float _far = far*4.0; + + if (depth >= 1.0) { + depth = texture2D(dhDepthTex, texcoord).x; + _near = dhNearPlane; + _far = dhFarPlane; + } + + depth = linearizeDepthFast(depth, _near, _far); + #else + depth = linearizeDepthFast(depth, near, far); + #endif + + // focus = gl_FragCoord.x * 0.1; + if( hideGUI < 1) gl_FragData[0].rgb += laserColor * pow( clamp( 1.0-abs(focus-abs(depth)) ,0,1),25) ; + #endif } \ No newline at end of file diff --git a/shaders/lang/en_us.lang b/shaders/lang/en_us.lang index 4ede8b3..94d74bb 100644 --- a/shaders/lang/en_us.lang +++ b/shaders/lang/en_us.lang @@ -430,12 +430,16 @@ option.DOF_QUALITY=Depth Of Field option.DOF_ANAMORPHIC_RATIO=Anamorphic Ratio value.MANUAL_FOCUS.-2=Autofocus value.MANUAL_FOCUS.-1=Brightness Slider - value.FOCUS_LASER_COLOR.0=Red - value.FOCUS_LASER_COLOR.1=Green - value.FOCUS_LASER_COLOR.2=Blue - value.FOCUS_LASER_COLOR.3=Pink - value.FOCUS_LASER_COLOR.4=Yellow - value.FOCUS_LASER_COLOR.5=White + + screen.JITTER_DOF=Jitter DOF Settings + option.JITTER_STRENGTH=Jitter Strength + option.FOCUS_LASER_COLOR=Focus + value.FOCUS_LASER_COLOR.0=Red + value.FOCUS_LASER_COLOR.1=Green + value.FOCUS_LASER_COLOR.2=Blue + value.FOCUS_LASER_COLOR.3=Pink + value.FOCUS_LASER_COLOR.4=Yellow + value.FOCUS_LASER_COLOR.5=White option.AEROCHROME_MODE=Aerochrome Mode option.AEROCHROME_PINKNESS=Aerochrome Red:Pink Ratio diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 078fb0b..f766592 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -270,7 +270,7 @@ BLISS_SHADERS \ screen.TAA_OPTIONS= SCREENSHOT_MODE TAA BLEND_FACTOR TAA_UPSCALING SCALE_FACTOR ### DOF screen.DepthOfField.columns = 1 - screen.DepthOfField = [JITTER_DOF] DOF_QUALITY DOF_ANAMORPHIC_RATIO AUTOFOCUS focal aperture MANUAL_FOCUS DoF_Adaptation_Speed FAR_BLUR_ONLY + screen.DepthOfField = DOF_QUALITY DOF_ANAMORPHIC_RATIO AUTOFOCUS focal aperture MANUAL_FOCUS DoF_Adaptation_Speed FAR_BLUR_ONLY [JITTER_DOF] screen.JITTER_DOF.columns=1 screen.JITTER_DOF = JITTER_STRENGTH FOCUS_LASER_COLOR SCREENSHOT_MODE ### EXPOSURE