Skip to content

Instantly share code, notes, and snippets.

@akella
Created April 12, 2025 13:20
Show Gist options
  • Save akella/194ee156aaeb2bc8e0c4b43ac5328db9 to your computer and use it in GitHub Desktop.
Save akella/194ee156aaeb2bc8e0c4b43ac5328db9 to your computer and use it in GitHub Desktop.
sobel.glsl
float intensity(in vec4 c) {
return sqrt((c.x*c.x)+(c.y*c.y)+(c.z*c.z));
}
float sobel(float step, vec2 res, vec2 center, sampler2D tex) {
float stepX = step/res.x*uDpr;
float stepY = step/res.y*uDpr;
float tLeft = intensity(texture(tex, center+vec2(-stepX, stepY)));
float left = intensity(texture(tex, center+vec2(-stepX, 0)));
float bLeft = intensity(texture(tex, center+vec2(-stepX, -stepY)));
float top = intensity(texture(tex, center+vec2(0, stepY)));
float bottom = intensity(texture(tex, center+vec2(0, -stepY)));
float tRight = intensity(texture(tex, center+vec2(stepX, stepY)));
float right = intensity(texture(tex, center+vec2(stepX, 0)));
float bRight = intensity(texture(tex, center+vec2(stepX, -stepY)));
float x = tLeft+2.0*left+bLeft-tRight-2.0*right-bRight;
float y = -tLeft-2.0*top-tRight+bLeft+2.0*bottom+bRight;
return sqrt((x*x)+(y*y));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment