slang-shaders/bezel/koko-aio/shaders-ng/reflection_blur.slang

128 lines
4.2 KiB
Plaintext
Raw Normal View History

2023-04-14 01:16:48 +10:00
#version 450
#include "config.inc"
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
2023-09-29 00:26:48 +10:00
layout(location = 1) out vec2 vFuzzy_main_pass_stage_1;
2023-04-14 01:16:48 +10:00
#include "includes/functions.include.slang"
2023-09-29 00:26:48 +10:00
#include "includes/blooms.include.slang"
2023-04-14 01:16:48 +10:00
void main() {
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
2023-09-29 00:26:48 +10:00
//Get fuzzy mul and pow factor
vFuzzy_main_pass_stage_1 = apply_fuzzy_main_pass_stage_1();
2023-04-14 01:16:48 +10:00
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
2023-09-29 00:26:48 +10:00
layout(location = 1) in vec2 vFuzzy_main_pass_stage_1;
2023-04-14 01:16:48 +10:00
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 1) uniform sampler2D Source;
2023-04-28 18:03:23 +10:00
layout(set = 0, binding = 2) uniform sampler2D flick_and_noise_pass;
2023-09-29 00:26:48 +10:00
layout(set = 0, binding = 3) uniform sampler2D reflected_blurred_passFeedback;
2023-04-14 01:16:48 +10:00
#include "includes/functions.include.slang"
2023-09-29 00:26:48 +10:00
#include "includes/blooms.include.slang"
2023-04-14 01:16:48 +10:00
float borders_gradient(vec2 co, float smoothness) {
//Draws a square with smooth borders:
float size = 1.0;
vec4 rect = vec4(0.0+smoothness, 0.0+smoothness, size - smoothness, size - smoothness);
vec2 hv = smoothstep(rect.xy - smoothness, rect.xy, co) * smoothstep(co - smoothness, co, rect.zw);
return hv.x * hv.y;
}
void main() {
if (DO_BEZEL == 0.0) return;
//Zoom out the image coordinates by the bezel border size to make room for reflections:
vec2 coords = zoom(vTexCoord, BEZEL_REFL_ZOOMOUT_ROOM);
//Skip unuseful pixels
float skip_border = BEZEL_REFL_SKIP_SIZE;
if (coords.x > skip_border && coords.x < 1.0 - skip_border &&
coords.y > skip_border && coords.y < 1.0 - skip_border ) {
FragColor = vec4(0.0);
return;
}
2023-09-29 00:26:48 +10:00
/*
2023-04-14 01:16:48 +10:00
//Create a gradient near borders to modulate between blurrend and sharp refection.
float smoothness = 0.11;
float shade_sharp_blur = borders_gradient(vTexCoord, smoothness);
2023-09-29 00:26:48 +10:00
shade_sharp_blur = 1.05 - (shade_sharp_blur + BEZEL_RFL_BLR_SHD); //Modulates between sharp and blur via user parameter
*/
float shade_sharp_blur = texture(Source, coords).a;
2023-04-14 01:16:48 +10:00
//Create gradients in the corners to blur more more near corners:
#define CORNER_BLURRINESS 0.6
float fcorners_shade = corners_shade(vTexCoord, 0.9) * CORNER_BLURRINESS;
shade_sharp_blur = max(fcorners_shade, shade_sharp_blur);
2023-09-29 00:26:48 +10:00
/*
2023-04-14 01:16:48 +10:00
//Sample a lod and the next integer one, then do a linear smapling between them
//to blur the reflections as they goes far from the tube.
float shade_sharp_blur_adapted = shade_sharp_blur * 5.5;
float lod0 = floor(shade_sharp_blur_adapted);
float lod1 = lod0 + 1;
vec3 s1 = textureLod( Source, coords, lod0).rgb;
vec3 s2 = textureLod( Source, coords, lod1).rgb;
float lodmix = fract(shade_sharp_blur_adapted);
vec3 pixel_out = mix(s1, s2, lodmix) * BEZEL_REFL_STRENGTH;
2023-09-29 00:26:48 +10:00
*/
float blur_radius= (shade_sharp_blur) * 3.5 ;
blur_radius = clamp(blur_radius, 1.0, 100.0);
//FragColor = vec4(shade_sharp_blur); return;
// FragColor = texture(Source, coords);return;
float blur_quality = 1;
float start_offset = (pi*2.0/8.0/4.0);
vec3 pixel_out = bloom(Source, coords, global.FinalViewportSize, vec2(blur_radius), blur_quality, start_offset, 0.0) ;
pixel_out *= BEZEL_REFL_STRENGTH;
2023-04-14 01:16:48 +10:00
//Next simulate a diffused light
2023-04-28 18:03:23 +10:00
vec3 pixel_diffused = textureLod( flick_and_noise_pass, coords, 6.0).rgb;
2023-04-14 01:16:48 +10:00
pixel_out = mix( pixel_out, pixel_diffused, BEZEL_DIFFUSION_STR);
//multiply the blurred image by the corner shade so that reflections will not be visible in the corners.
//This has been moved to final pass because it didn't worked well with curvature
//at 0.0 inner zoom level.
//pixel_out = pixel_out * (1 - fcorners_shade);
2023-09-29 00:26:48 +10:00
pixel_out = apply_fuzzy_main_pass_stage_2(pixel_out, vFuzzy_main_pass_stage_1);
vec3 pixel_out_fb = texture(reflected_blurred_passFeedback, vTexCoord).rgb;
pixel_out = mix(pixel_out_fb.rgb, pixel_out, 0.5 );
2023-04-14 01:16:48 +10:00
FragColor = vec4(pixel_out, 1.0);
2023-09-29 00:26:48 +10:00
//FragColor = vec4(shade_sharp_blur);
2023-04-14 01:16:48 +10:00
}