BLT-With-Graphics-Template/include/blt/gfx/renderer/shaders/pp_highlight.frag

45 lines
1.1 KiB
GLSL
Raw Normal View History

2024-05-12 14:06:57 -04:00
#ifdef __cplusplus
#include <string>
const std::string shader_highlight_frag = R"("
#version 300 es
precision mediump float;
out vec4 FragColor;
in vec2 uv;
in vec2 pos;
uniform sampler2D tex;
uniform ivec4 size;
uniform vec4 mousePos;
void main() {
vec2 texelSize = 1.0 / vec2(float(size.x), float(size.y));
vec4 result = vec4(0.0, 0.0, 0.0, 0.0);
for (int x = -size.z; x <= size.z; ++x) {
for (int y = -size.w; y <= size.w; ++y) {
vec2 offset = (vec2(float(x), float(y)) * texelSize);
result += texture(tex, uv + offset);
}
}
float dx = (gl_FragCoord.x - mousePos.x) / float(size.x);
float dy = (gl_FragCoord.y - mousePos.y) / float(size.y);
2024-05-12 21:48:43 -04:00
float distx = 1.0 - sqrt(dx * dx);
float disty = 1.0 - sqrt(dy * dy);
float dist = (distx + disty) / 2.0;
2024-05-12 14:06:57 -04:00
vec4 n_color = result / vec4((float(size.z) * 2.0 + 1.0) * (float(size.w) * 2.0 + 1.0));
2024-05-12 21:48:43 -04:00
n_color = n_color * vec4(16.0);
2024-05-12 14:06:57 -04:00
2024-05-12 21:48:43 -04:00
if (dist >= 0.5)
FragColor = normalize(n_color);
else
FragColor = texture(tex, uv);
2024-05-12 14:06:57 -04:00
//FragColor = ;
}
")";
#endif