initial implementation of DoF
This commit is contained in:
parent
cb51b3ca58
commit
aab1ed34ab
4 changed files with 29 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
|||
#version 120
|
||||
|
||||
#define pixelSize 2 // the size of pixels [1 2 4 8 16]
|
||||
|
||||
#define dithering // whether or not to apply dithering
|
||||
#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 pixelSize 2 // the size of pixels [1 2 4 8 16]
|
||||
|
||||
uniform sampler2D gcolor;
|
||||
uniform sampler2D colortex1;
|
||||
uniform float viewWidth, viewHeight;
|
||||
|
||||
varying vec2 texcoord;
|
||||
|
||||
#include "/module/dof.frag"
|
||||
|
||||
// All components are in the range [0…1], including hue.
|
||||
vec3 rgb2hsv(vec3 c)
|
||||
{
|
||||
|
@ -116,7 +118,9 @@ float dither(float color, float dithersteps) {
|
|||
void main() {
|
||||
// adjust texture coordinate based on pixel size if needed
|
||||
vec2 newcoord = texcoord;
|
||||
#if pixelSize > 1
|
||||
#ifdef dof
|
||||
newcoord = depthOfField();
|
||||
#elif pixelSize > 1
|
||||
vec2 view = vec2(viewWidth, viewHeight) / float(pixelSize);
|
||||
float offset = (ceil(pixelSize * 0.5) - 0.5) / float(pixelSize);
|
||||
newcoord = (floor(newcoord * view) + offset) / view;
|
||||
|
|
|
@ -36,6 +36,8 @@ option.tWarp=Texture Warping
|
|||
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
|
||||
|
|
19
shaders/module/dof.frag
Normal file
19
shaders/module/dof.frag
Normal 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;
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ screen.COLOR=colorMode dithering <empty> rgbSteps <empty> <empty> hueSteps satSt
|
|||
screen.PSX=vWarp tWarp
|
||||
|
||||
# fx
|
||||
screen.FX=worldCurvature
|
||||
screen.FX=dof worldCurvature
|
||||
|
||||
# -- CONDITIONALS --
|
||||
gbuffers_hand.enabled=tWarp
|
||||
|
|
Loading…
Reference in a new issue