Compare commits

..

2 commits

Author SHA1 Message Date
3b12a88a76 initial implementation of DoF 2024-04-14 13:28:52 -04:00
76e464acd8 added props and lang lines for curvature 2024-04-14 00:09:19 -04:00
4 changed files with 40 additions and 4 deletions

View file

@ -1,5 +1,7 @@
#version 120 #version 120
#define pixelSize 2 // the size of pixels [1 2 4 8 16]
#define dithering // whether or not to apply dithering #define dithering // whether or not to apply dithering
#define colorMode 0 // hsv/rgb [0 1] #define colorMode 0 // hsv/rgb [0 1]
@ -9,14 +11,14 @@
#define rgbSteps 4 // the number of rgb values to use [2 4 8 16 32 64] #define rgbSteps 4 // the number of rgb values to use [2 4 8 16 32 64]
#define pixelSize 2 // the size of pixels [1 2 4 8 16]
uniform sampler2D gcolor; uniform sampler2D gcolor;
uniform sampler2D colortex1; uniform sampler2D colortex1;
uniform float viewWidth, viewHeight; uniform float viewWidth, viewHeight;
varying vec2 texcoord; varying vec2 texcoord;
#include "/module/dof.frag"
// All components are in the range [0…1], including hue. // All components are in the range [0…1], including hue.
vec3 rgb2hsv(vec3 c) vec3 rgb2hsv(vec3 c)
{ {
@ -116,7 +118,9 @@ float dither(float color, float dithersteps) {
void main() { void main() {
// adjust texture coordinate based on pixel size if needed // adjust texture coordinate based on pixel size if needed
vec2 newcoord = texcoord; vec2 newcoord = texcoord;
#if pixelSize > 1 #ifdef dof
newcoord = depthOfField();
#elif pixelSize > 1
vec2 view = vec2(viewWidth, viewHeight) / float(pixelSize); vec2 view = vec2(viewWidth, viewHeight) / float(pixelSize);
float offset = (ceil(pixelSize * 0.5) - 0.5) / float(pixelSize); float offset = (ceil(pixelSize * 0.5) - 0.5) / float(pixelSize);
newcoord = (floor(newcoord * view) + offset) / view; newcoord = (floor(newcoord * view) + offset) / view;

View file

@ -35,3 +35,13 @@ value.vWarp.32=Silly (32x)
option.tWarp=Texture Warping option.tWarp=Texture Warping
option.tWarp.comment=Emulates affine texture mapping responsible for warping textures on the PSX option.tWarp.comment=Emulates affine texture mapping responsible for warping textures on the PSX
screen.FX=FX
option.dof=Depth of Field
option.dof.comment=Downscale out-of-focus objects
option.worldCurvature=World Curvature
value.worldCurvature.0=Off
value.worldCurvature.1=Chunk
value.worldCurvature.2=Cylinder
value.worldCurvature.3=Polyhedron
value.worldCurvature.4=Sphere

19
shaders/module/dof.frag Normal file
View file

@ -0,0 +1,19 @@
//#define dof
uniform float centerDepthSmooth;
uniform sampler2D depthtex1;
const float centerDepthSmoothHalfLife = 16f;
vec2 depthOfField() {
float depth = texture2D(depthtex1, texcoord).x;
float distance = depth - centerDepthSmooth;
int stops = min(int(distance * 96), 5);
float virtualSize = pow(float(pixelSize), 1 + stops);//1 + stops);
vec2 view = vec2(viewWidth, viewHeight) / virtualSize;
float offset = (ceil(virtualSize * 0.5) - 0.5) / virtualSize;
return (floor(texcoord * view) + offset) / view;
}

View file

@ -9,7 +9,7 @@ profile.VR32=pixelSize=8 colorMode=0 !dithering hueSteps=2 satSteps=2 valSteps=2
# -- SCREENS -- # -- SCREENS --
# default # default
screen=<profile> <empty> pixelSize <empty> [COLOR] [PSX] screen=<profile> <empty> pixelSize <empty> [COLOR] [PSX] [FX]
# colors # colors
screen.COLOR.columns=3 screen.COLOR.columns=3
@ -18,6 +18,9 @@ screen.COLOR=colorMode dithering <empty> rgbSteps <empty> <empty> hueSteps satSt
# psx # psx
screen.PSX=vWarp tWarp screen.PSX=vWarp tWarp
# fx
screen.FX=dof worldCurvature
# -- CONDITIONALS -- # -- CONDITIONALS --
gbuffers_hand.enabled=tWarp gbuffers_hand.enabled=tWarp