35 lines
802 B
GLSL
35 lines
802 B
GLSL
#version 100
|
|
#extension GL_OES_standard_derivatives : enable
|
|
|
|
#ifdef GL_ES
|
|
precision mediump float;
|
|
#endif
|
|
|
|
varying vec2 fragTexCoord;
|
|
varying vec4 fragColor;
|
|
|
|
uniform sampler2D texture0;
|
|
uniform vec4 colDiffuse;
|
|
uniform float pxRange;
|
|
|
|
float median(float r, float g, float b) {
|
|
return max(min(r, g), min(max(r, g), b));
|
|
}
|
|
|
|
float screenPxRange(vec2 uv) {
|
|
vec2 duv_dx = dFdx(uv);
|
|
vec2 duv_dy = dFdy(uv);
|
|
float scale = 0.5 * (length(duv_dx) + length(duv_dy));
|
|
return max(scale * pxRange, 1.0);
|
|
}
|
|
|
|
void main() {
|
|
vec3 msd = texture2D(texture0, fragTexCoord).rgb;
|
|
float sd = median(msd.r, msd.g, msd.b);
|
|
float spx = screenPxRange(fragTexCoord);
|
|
float dist = spx * (sd - 0.5);
|
|
float opacity = clamp(dist + 0.5, 0.0, 1.0);
|
|
|
|
gl_FragColor = vec4(fragColor.rgb, fragColor.a * opacity) * colDiffuse;
|
|
}
|