veloren/assets/voxygen/shaders/dual-upsample-frag.glsl

36 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-10-28 15:53:35 +00:00
#version 440 core
2021-07-21 08:58:03 +00:00
layout(set = 0, binding = 0)
uniform texture2D t_src_color;
layout(set = 0, binding = 1)
uniform sampler s_src_color;
layout(set = 0, binding = 2)
2021-07-21 09:39:30 +00:00
uniform u_locals {
vec2 halfpixel;
};
2021-07-21 08:58:03 +00:00
layout(location = 0) in vec2 uv;
layout(location = 0) out vec4 tgt_color;
vec4 simplesample(vec2 uv) {
return textureLod(sampler2D(t_src_color, s_src_color), uv, 0);
}
// From: https://community.arm.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-20-66/siggraph2015_2D00_mmg_2D00_marius_2D00_notes.pdf
vec4 upsample(vec2 uv, vec2 halfpixel) {
vec4 sum = simplesample(uv + vec2(-halfpixel.x * 2.0, 0.0));
sum += simplesample(uv + vec2(-halfpixel.x, halfpixel.y)) * 2.0;
sum += simplesample(uv + vec2(0.0, halfpixel.y * 2.0));
sum += simplesample(uv + vec2(halfpixel.x, halfpixel.y)) * 2.0;
sum += simplesample(uv + vec2(halfpixel.x * 2.0, 0.0));
sum += simplesample(uv + vec2(halfpixel.x, -halfpixel.y)) * 2.0;
sum += simplesample(uv + vec2(0.0, -halfpixel.y * 2.0));
sum += simplesample(uv + vec2(-halfpixel.x, -halfpixel.y)) * 2.0;
return sum / 12.0;
}
void main() {
tgt_color = upsample(uv, halfpixel);
}