Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gam0022/24bd12699b1a363218275fe0d9c7aec7 to your computer and use it in GitHub Desktop.
Save gam0022/24bd12699b1a363218275fe0d9c7aec7 to your computer and use it in GitHub Desktop.
dFdxとdFdyでわずか4行のお手軽エッジ検出! ref: http://qiita.com/gam0022/items/1342a91d0a6b16a3a9ba
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture2D(iChannel0, uv);
float gray = length(color.rgb);
fragColor = vec4(vec3(dFdy(gray)) * 5.0, 1.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture2D(iChannel0, uv);
float gray = length(color.rgb);
fragColor = vec4(vec3(step(0.07, fwidth(gray))), 1.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture2D(iChannel0, uv);
float gray = length(color.rgb);
fragColor = vec4(vec3(step(0.06, length(vec2(dFdx(gray), dFdy(gray))))), 1.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture2D(iChannel0, uv);
float gray = length(color.rgb);
fragColor = vec4(vec3(length(vec2(dFdx(gray), dFdy(gray)))), 1.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture2D(iChannel0, uv);
float gray = length(color.rgb);
fragColor = vec4(vec3(gray), 1.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
fragColor = texture2D(iChannel0, uv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment