48 lines
1.1 KiB
GLSL
48 lines
1.1 KiB
GLSL
#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;
|
|
|
|
#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);
|
|
|
|
float mCenter = texture(mask, uvCenter).r;
|
|
float mTop = texture(mask, uvTop).r;
|
|
float mRight = texture(mask, uvRight).r;
|
|
float mTopRight = texture(mask, uvTopRight).r;
|
|
|
|
float dT = abs(mCenter - mTop);
|
|
float dR = abs(mCenter - mRight);
|
|
float dTR = abs(mCenter - mTopRight);
|
|
|
|
float delta = 0.0;
|
|
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);
|
|
|
|
FragColor = albedo - outline;
|
|
}
|
|
|
|
")";
|
|
#endif |