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

57 lines
1.4 KiB
GLSL
Raw Normal View History

#ifdef __cplusplus
#include <string>
const std::string shader_pp_outline_step_frag = R"("
#version 300 es
precision mediump float;
out vec4 FragColor;
in vec2 uv;
in vec2 pos;
uniform vec2 viewportSize;
uniform sampler2D albedo;
uniform sampler2D mask;
2024-05-05 02:29:45 -04:00
vec4 outline_color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
float longest(vec3 v){
return max(v.r, max(v.b, v.g));
}
#define LINE_WEIGHT 3.0
void main() {
float dx = (1.0 / viewportSize.x) * LINE_WEIGHT;
float dy = (1.0 / viewportSize.y) * LINE_WEIGHT;
vec2 uvCenter = uv;
vec2 uvRight = vec2(uvCenter.x + dx, uvCenter.y);
vec2 uvTop = vec2(uvCenter.x, uvCenter.y - dx);
vec2 uvTopRight = vec2(uvCenter.x + dx, uvCenter.y - dx);
2024-05-05 02:29:45 -04:00
float mCenter = longest(texture(mask, uvCenter).rgb);
float mTop = longest(texture(mask, uvTop).rgb);
float mRight = longest(texture(mask, uvRight).rgb);
float mTopRight = longest(texture(mask, uvTopRight).rgb);
float dT = abs(mCenter - mTop);
float dR = abs(mCenter - mRight);
float dTR = abs(mCenter - mTopRight);
2024-05-05 02:29:45 -04:00
float delta = 0.0f;
delta = max(delta, dT);
delta = max(delta, dR);
delta = max(delta, dTR);
vec4 outline = vec4(delta, delta, delta, 1.0);
vec4 albedo = texture(albedo, uv);
2024-05-05 02:29:45 -04:00
if (delta <= 0.001)
FragColor = albedo;
else
FragColor = outline_color;
}
")";
#endif