From ab10aaa2e3ac0a2d4ea441fd5c187b61d5b5d988 Mon Sep 17 00:00:00 2001 From: Valerie Date: Sun, 14 Apr 2024 13:59:53 -0400 Subject: [PATCH] added option for DoF to affect dither resolution --- shaders/composite.fsh | 5 ++++- shaders/lang/en_US.lang | 4 ++++ shaders/module/dof.frag | 7 ++++++- shaders/shaders.properties | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/shaders/composite.fsh b/shaders/composite.fsh index 8173208..55438a7 100644 --- a/shaders/composite.fsh +++ b/shaders/composite.fsh @@ -1,6 +1,7 @@ #version 120 #define pixelSize 2 // the size of pixels [1 2 4 8 16] +float renderRes = pixelSize; #define dithering // whether or not to apply dithering #define colorMode 0 // hsv/rgb [0 1] @@ -63,7 +64,9 @@ const int indexMatrix8x8[64] = int[](0, 32, 8, 40, 2, 34, 10, 42, 63, 31, 55, 23, 61, 29, 53, 21); float indexValue() { - #if pixelSize > 1 + #if defined(dof) && defined(dofRes) + vec2 coord = gl_FragCoord.xy / renderRes; + #elif pixelSize > 1 vec2 coord = gl_FragCoord.xy / pixelSize; #else vec2 coord = gl_FragCoord.xy; diff --git a/shaders/lang/en_US.lang b/shaders/lang/en_US.lang index b4ab046..c008789 100644 --- a/shaders/lang/en_US.lang +++ b/shaders/lang/en_US.lang @@ -38,6 +38,10 @@ option.tWarp.comment=Emulates affine texture mapping responsible for warping tex screen.FX=FX option.dof=Depth of Field option.dof.comment=Downscale out-of-focus objects +option.dofRes=DoF Dither +option.dofRes.comment=Whether DoF focus affects dither resolution. +value.dofRes.0=Static +value.dofRes.1=Dynamic option.worldCurvature=World Curvature value.worldCurvature.0=Off value.worldCurvature.1=Chunk diff --git a/shaders/module/dof.frag b/shaders/module/dof.frag index 18e830f..85e5886 100644 --- a/shaders/module/dof.frag +++ b/shaders/module/dof.frag @@ -1,5 +1,6 @@ //#define dof +#define dofRes uniform float centerDepthSmooth; uniform sampler2D depthtex1; @@ -9,11 +10,15 @@ const float centerDepthSmoothHalfLife = 16f; vec2 depthOfField() { float depth = texture2D(depthtex1, texcoord).x; float distance = depth - centerDepthSmooth; - int stops = min(int(distance * 96), 5); + int stops = max(min(int(distance * 96), 5), 0); float virtualSize = pow(float(pixelSize), 1 + stops);//1 + stops); vec2 view = vec2(viewWidth, viewHeight) / virtualSize; float offset = (ceil(virtualSize * 0.5) - 0.5) / virtualSize; + + #ifdef dofRes + renderRes = virtualSize; + #endif return (floor(texcoord * view) + offset) / view; } diff --git a/shaders/shaders.properties b/shaders/shaders.properties index 5aea619..291e85f 100644 --- a/shaders/shaders.properties +++ b/shaders/shaders.properties @@ -19,7 +19,7 @@ screen.COLOR=colorMode dithering rgbSteps hueSteps satSt screen.PSX=vWarp tWarp # fx -screen.FX=dof worldCurvature +screen.FX=dof dofRes # -- CONDITIONALS -- gbuffers_hand.enabled=tWarp