prosperon/shaders/postsharpen.cg

38 lines
1,022 B
Plaintext
Raw Normal View History

@block frag
uniform float offset_amt;
// Sharpen kernel
float kernel[9] = float[](
-1, -1, -1,
-1, 9, -1,
-1, -1, -1
);
void frag()
{
vec2 offset = vec2(1/offset_amt, 1/offset_amt);
vec2 offsets[9] = vec2[](
vec2(-offset.x, offset.y), // top-left
vec2(0.0, offset.y), // top-center
vec2(offset.x, offset.y), // top-right
vec2(-offset.x, 0.0), // center-left
vec2(0.0, 0.0), // center-center (current pixel)
vec2(offset.x, 0.0), // center-right
vec2(-offset.x, -offset.y), // bottom-left
vec2(0.0, -offset.y), // bottom-center
vec2(offset.x, -offset.y) // bottom-right
);
color = vec4(0.0);
// Apply the kernel to the current pixel and its neighbors
for (int i = 0; i < 9; i++) {
vec3 samp = texture(sampler2D(diffuse,smp),uv+offsets[i]).rgb;
color.rgb += samp * kernel[i];
}
color.a = 1.0;
}
@end
#include <postbase.cg>