mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 21:21:21 +00:00
8207c548cc
This reverts most of commit f420c143e0
again because it turns out GPUs like combined images and samplers.
But: The one thing we don't revert is allowing the C code to select any
combination of sampler and image:
gsk_vulkan_render_get_image_descriptor() now takes a 2nd argument
specifying the sampler.
This allows the same flexibility as before, we just combine things
early.
This change was inspired by
https://developer.nvidia.com/blog/vulkan-dos-donts/
51 lines
1.3 KiB
GLSL
51 lines
1.3 KiB
GLSL
#version 450
|
|
|
|
#include "common.frag.glsl"
|
|
#include "clip.frag.glsl"
|
|
|
|
layout(location = 0) in vec2 inPos;
|
|
layout(location = 1) in flat vec2 inSize;
|
|
layout(location = 2) in vec2 inTexCoord;
|
|
layout(location = 3) in float inRadius;
|
|
layout(location = 4) in flat uint inTexId;
|
|
|
|
layout(location = 0) out vec4 color;
|
|
|
|
const int samples_x = 15; // must be odd
|
|
const int samples_y = 15; // must be odd
|
|
|
|
const int half_samples_x = samples_x / 2;
|
|
const int half_samples_y = samples_y / 2;
|
|
|
|
float Gaussian (float sigma, float x)
|
|
{
|
|
return exp ( - (x * x) / (2.0 * sigma * sigma));
|
|
}
|
|
|
|
vec4 blur_pixel (in vec2 uv)
|
|
{
|
|
float total = 0.0;
|
|
vec4 ret = vec4 (0);
|
|
float pixel_size_x = (1.0 / inSize.x);
|
|
float pixel_size_y = (1.0 / inSize.y);
|
|
|
|
for (int y = 0; y < samples_y; ++y)
|
|
{
|
|
float fy = Gaussian (inRadius, float(y) - float(half_samples_x));
|
|
float offset_y = float(y - half_samples_y) * pixel_size_y;
|
|
for (int x = 0; x < samples_x; ++x)
|
|
{
|
|
float fx = Gaussian (inRadius, float(x) - float(half_samples_x));
|
|
float offset_x = float(x - half_samples_x) * pixel_size_x;
|
|
total += fx * fy;
|
|
ret += texture(get_sampler (inTexId), uv + vec2(offset_x, offset_y)) * fx * fy;
|
|
}
|
|
}
|
|
return ret / total;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
color = clip (inPos, blur_pixel (inTexCoord));
|
|
}
|