2023-08-03 12:23:29 +08:00
|
|
|
#include "/lib/settings.glsl"
|
|
|
|
|
|
|
|
uniform sampler2D colortex7;
|
2024-11-16 06:54:18 +08:00
|
|
|
uniform sampler2D colortex5;
|
|
|
|
uniform sampler2D colortex6;
|
2024-05-05 09:08:24 +08:00
|
|
|
uniform sampler2D colortex14;
|
|
|
|
uniform sampler2D depthtex0;
|
2024-11-16 06:54:18 +08:00
|
|
|
uniform sampler2D depthtex1;
|
2024-06-11 11:26:19 +08:00
|
|
|
uniform sampler2D depthtex2;
|
|
|
|
uniform sampler2D noisetex;
|
|
|
|
|
|
|
|
varying vec2 texcoord;
|
2023-08-03 12:23:29 +08:00
|
|
|
uniform vec2 texelSize;
|
|
|
|
uniform float frameTimeCounter;
|
2024-11-16 06:54:18 +08:00
|
|
|
uniform int frameCounter;
|
2024-05-19 10:58:30 +08:00
|
|
|
uniform float viewHeight;
|
|
|
|
uniform float viewWidth;
|
|
|
|
uniform float aspectRatio;
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
uniform int hideGUI;
|
2023-08-03 12:23:29 +08:00
|
|
|
|
|
|
|
#include "/lib/color_transforms.glsl"
|
|
|
|
#include "/lib/color_dither.glsl"
|
|
|
|
#include "/lib/res_params.glsl"
|
2024-03-28 04:11:28 +08:00
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
uniform float near;
|
|
|
|
uniform float far;
|
|
|
|
float ld(float dist) {
|
|
|
|
return (2.0 * near) / (far + near - dist * (far - near));
|
|
|
|
}
|
2024-05-05 09:08:24 +08:00
|
|
|
float interleaved_gradientNoise(){
|
|
|
|
vec2 coord = gl_FragCoord.xy;
|
|
|
|
float noise = fract(52.9829189*fract(0.06711056*coord.x + 0.00583715*coord.y));
|
|
|
|
return noise;
|
|
|
|
}
|
2024-11-16 06:54:18 +08:00
|
|
|
float blueNoise(){
|
|
|
|
return fract(texelFetch2D(noisetex, ivec2(gl_FragCoord.xy)%512, 0).a + 1.0/1.6180339887 * frameCounter);
|
|
|
|
}
|
2024-05-05 09:08:24 +08:00
|
|
|
|
2024-05-22 12:01:17 +08:00
|
|
|
#include "/lib/gameplay_effects.glsl"
|
|
|
|
|
|
|
|
void doCameraGridLines(inout vec3 color, vec2 UV){
|
|
|
|
|
2024-05-22 12:20:47 +08:00
|
|
|
float lineThicknessY = 0.001;
|
2024-05-22 12:01:17 +08:00
|
|
|
float lineThicknessX = lineThicknessY/aspectRatio;
|
|
|
|
|
|
|
|
float horizontalLines = abs(UV.x-0.33);
|
|
|
|
horizontalLines = min(abs(UV.x-0.66), horizontalLines);
|
|
|
|
|
|
|
|
float verticalLines = abs(UV.y-0.33);
|
|
|
|
verticalLines = min(abs(UV.y-0.66), verticalLines);
|
|
|
|
|
|
|
|
float gridLines = horizontalLines < lineThicknessX || verticalLines < lineThicknessY ? 1.0 : 0.0;
|
|
|
|
|
|
|
|
if(hideGUI > 0.0) gridLines = 0.0;
|
|
|
|
color = mix(color, vec3(1.0), gridLines);
|
|
|
|
}
|
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
uniform vec3 previousCameraPosition;
|
|
|
|
// uniform vec3 cameraPosition;
|
|
|
|
uniform mat4 gbufferPreviousModelView;
|
|
|
|
// uniform mat4 gbufferModelViewInverse;
|
|
|
|
// uniform mat4 gbufferModelView;
|
2024-05-22 12:01:17 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
#include "/lib/util.glsl"
|
|
|
|
#include "/lib/projections.glsl"
|
2024-11-16 06:54:18 +08:00
|
|
|
vec3 tonemap(vec3 col){
|
|
|
|
return col/(1+luma(col));
|
|
|
|
}
|
|
|
|
vec3 invTonemap(vec3 col){
|
|
|
|
return col/(1-luma(col));
|
|
|
|
}
|
2024-05-22 12:01:17 +08:00
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
vec3 doMotionBlur(vec2 texcoord, float depth, float noise, bool hand){
|
2024-06-11 11:26:19 +08:00
|
|
|
|
|
|
|
float samples = 4.0;
|
|
|
|
vec3 color = vec3(0.0);
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
float blurMult = 1.0;
|
2024-11-16 06:54:18 +08:00
|
|
|
if(hand) blurMult = 0.0;
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
vec3 viewPos = toScreenSpace(vec3(texcoord, depth));
|
|
|
|
viewPos = mat3(gbufferModelViewInverse) * viewPos + gbufferModelViewInverse[3].xyz + (cameraPosition - previousCameraPosition);
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
vec3 previousPosition = mat3(gbufferPreviousModelView) * viewPos + gbufferPreviousModelView[3].xyz;
|
|
|
|
previousPosition = toClipSpace3(previousPosition);
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
vec2 velocity = texcoord - previousPosition.xy;
|
|
|
|
|
|
|
|
// thank you Capt Tatsu for letting me use these
|
2024-11-16 06:54:18 +08:00
|
|
|
velocity = (velocity / (1.0 + length(velocity)) ) * 0.05 * blurMult * MOTION_BLUR_STRENGTH;
|
2024-06-11 11:26:19 +08:00
|
|
|
texcoord = texcoord - velocity*(samples*0.5 + noise);
|
2024-11-16 06:54:18 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
vec2 screenEdges = 2.0/vec2(viewWidth, viewHeight);
|
2023-10-08 10:18:20 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
for (int i = 0; i < int(samples); i++) {
|
2024-03-28 04:11:28 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
texcoord += velocity;
|
|
|
|
color += texture2D(colortex7, clamp(texcoord, screenEdges, 1.0-screenEdges)).rgb;
|
2024-03-28 04:11:28 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
}
|
2024-11-16 06:54:18 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
return color / samples;
|
|
|
|
}
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
float convertHandDepth_2(in float depth, bool hand) {
|
|
|
|
if(!hand) return depth;
|
|
|
|
|
|
|
|
float ndcDepth = depth * 2.0 - 1.0;
|
|
|
|
ndcDepth /= MC_HAND_DEPTH;
|
|
|
|
return ndcDepth * 0.5 + 0.5;
|
|
|
|
}
|
|
|
|
|
2024-06-20 09:44:21 +08:00
|
|
|
uniform sampler2D shadowcolor1;
|
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
float doVignette( in vec2 texcoord, in float noise){
|
|
|
|
|
|
|
|
float vignette = 1.0-clamp(1.0-length(texcoord-0.5),0.0,1.0);
|
|
|
|
|
|
|
|
// vignette = pow(1.0-pow(1.0-vignette,3),5);
|
|
|
|
vignette *= vignette*vignette;
|
|
|
|
vignette = 1.0-vignette;
|
|
|
|
vignette *= vignette*vignette*vignette*vignette;
|
|
|
|
|
|
|
|
// stop banding
|
|
|
|
vignette = vignette + vignette*(noise-0.5)*0.01;
|
|
|
|
|
|
|
|
return mix(1.0, vignette, VIGNETTE_STRENGTH);
|
|
|
|
}
|
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
void main() {
|
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
float noise = blueNoise();
|
2023-08-03 12:23:29 +08:00
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
#ifdef MOTION_BLUR
|
2024-11-16 06:54:18 +08:00
|
|
|
float depth = texture2D(depthtex0, texcoord*RENDER_SCALE).r;
|
|
|
|
bool hand = depth < 0.56;
|
|
|
|
float depth2 = convertHandDepth_2(depth, hand);
|
|
|
|
|
|
|
|
vec3 COLOR = doMotionBlur(texcoord, depth2, noise, hand);
|
2024-06-11 11:26:19 +08:00
|
|
|
#else
|
|
|
|
vec3 COLOR = texture2D(colortex7,texcoord).rgb;
|
2024-03-20 05:08:32 +08:00
|
|
|
#endif
|
2024-11-16 06:54:18 +08:00
|
|
|
|
|
|
|
#ifdef VIGNETTE
|
|
|
|
COLOR *= doVignette(texcoord, noise);
|
|
|
|
#endif
|
|
|
|
|
2024-05-19 10:58:30 +08:00
|
|
|
#if defined LOW_HEALTH_EFFECT || defined DAMAGE_TAKEN_EFFECT || defined WATER_ON_CAMERA_EFFECT
|
|
|
|
// for making the fun, more fun
|
2024-06-11 11:26:19 +08:00
|
|
|
applyGameplayEffects(COLOR, texcoord, noise);
|
2024-05-19 10:58:30 +08:00
|
|
|
#endif
|
2024-03-28 04:11:28 +08:00
|
|
|
|
2024-05-22 12:01:17 +08:00
|
|
|
#ifdef CAMERA_GRIDLINES
|
2024-06-11 11:26:19 +08:00
|
|
|
doCameraGridLines(COLOR, texcoord);
|
2024-05-22 12:01:17 +08:00
|
|
|
#endif
|
|
|
|
|
2024-06-20 09:44:21 +08:00
|
|
|
#if DEBUG_VIEW == debug_SHADOWMAP
|
2024-11-16 06:54:18 +08:00
|
|
|
vec2 shadowUV = texcoord * vec2(2.0, 1.0) ;
|
2024-06-20 09:44:21 +08:00
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
// shadowUV -= vec2(0.5,0.0);
|
|
|
|
// float zoom = 0.1;
|
|
|
|
// shadowUV = ((shadowUV-0.5) - (shadowUV-0.5)*zoom) + 0.5;
|
2024-06-20 09:44:21 +08:00
|
|
|
|
2024-11-16 06:54:18 +08:00
|
|
|
if(shadowUV.x < 1.0 && shadowUV.y < 1.0 && hideGUI == 1) COLOR = texture2D(shadowcolor1,shadowUV).rgb;
|
|
|
|
#endif
|
|
|
|
#if DEBUG_VIEW == debug_DEPTHTEX0
|
|
|
|
COLOR = vec3(ld(texture2D(depthtex0, texcoord*RENDER_SCALE).r));
|
|
|
|
#endif
|
|
|
|
#if DEBUG_VIEW == debug_DEPTHTEX1
|
|
|
|
COLOR = vec3(ld(texture2D(depthtex1, texcoord*RENDER_SCALE).r));
|
2024-06-20 09:44:21 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2024-06-11 11:26:19 +08:00
|
|
|
gl_FragColor.rgb = COLOR;
|
2023-08-03 12:23:29 +08:00
|
|
|
}
|