double-hit-balls/assets/smaa/edge_fragment.txt

105 lines
2.8 KiB
Plaintext
Executable File

#version 410 compatibility
#define SMAA_THRESHOLD 0.05
#define SMAA_MAX_SEARCH_STEPS 32
#define SMAA_MAX_SEARCH_STEPS_DIAG 16
#define SMAA_CORNER_ROUNDING 25
#ifndef SMAA_DEPTH_THRESHOLD
#define SMAA_DEPTH_THRESHOLD (0.1 * SMAA_THRESHOLD)
#endif
#ifndef SMAA_REPROJECTION
#define SMAA_REPROJECTION 0
#endif
#define SMAA_REPROJECTION_WEIGHT_SCALE 30.0
#ifndef SMAA_AREATEX_MAX_DISTANCE
#define SMAA_AREATEX_MAX_DISTANCE 16
#endif
#ifndef SMAA_AREATEX_MAX_DISTANCE_DIAG
#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
#endif
#define SMAA_AREATEX_PIXEL_SIZE (1.0 / vec2(160.0, 560.0))
#define SMAA_AREATEX_SUBTEX_SIZE (1.0 / 7.0)
/* --- Define section is over ---- */
/**
* Color Edge Detection
*
* IMPORTANT NOTICE: color edge detection requires gamma-corrected colors, and
* thus 'colorTex' should be a non-sRGB texture.
*/
vec4 SMAAColorEdgeDetectionPS(vec2 texcoord,
vec4 offset[3],
sampler2D colorTex
) {
vec2 threshold = vec2(SMAA_THRESHOLD, SMAA_THRESHOLD);
// Calculate color deltas:
vec4 delta;
vec3 C = texture(colorTex, texcoord).rgb;
vec3 Cleft = texture(colorTex, offset[0].xy).rgb;
vec3 t = abs(C - Cleft);
delta.x = max(max(t.r, t.g), t.b);
vec3 Ctop = texture(colorTex, offset[0].zw).rgb;
t = abs(C - Ctop);
delta.y = max(max(t.r, t.g), t.b);
// We do the usual threshold:
vec2 edges = step(threshold, delta.xy);
// Then discard if there is no edge:
if (dot(edges, vec2(1.0, 1.0)) == 0.0)
discard;
// Calculate right and bottom deltas:
vec3 Cright = texture(colorTex, offset[1].xy).rgb;
t = abs(C - Cright);
delta.z = max(max(t.r, t.g), t.b);
vec3 Cbottom = texture(colorTex, offset[1].zw).rgb;
t = abs(C - Cbottom);
delta.w = max(max(t.r, t.g), t.b);
// Calculate the maximum delta in the direct neighborhood:
float maxDelta = max(max(max(delta.x, delta.y), delta.z), delta.w);
// Calculate left-left and top-top deltas:
vec3 Cleftleft = texture(colorTex, offset[2].xy).rgb;
t = abs(C - Cleftleft);
delta.z = max(max(t.r, t.g), t.b);
vec3 Ctoptop = texture(colorTex, offset[2].zw).rgb;
t = abs(C - Ctoptop);
delta.w = max(max(t.r, t.g), t.b);
// Calculate the final maximum delta:
maxDelta = max(max(maxDelta, delta.z), delta.w);
// Local contrast adaptation in action:
edges.xy *= step(0.5 * maxDelta, delta.xy);
return vec4(edges, 0.0, 0.0);
}
/* ------------- Header is over -------------- */
uniform sampler2D albedo_tex;
in vec2 texcoord;
in vec4 offset[3];
in vec4 dummy2;
void main()
{
gl_FragColor = SMAAColorEdgeDetectionPS(texcoord, offset, albedo_tex);
}