Created
April 12, 2025 13:20
-
-
Save akella/194ee156aaeb2bc8e0c4b43ac5328db9 to your computer and use it in GitHub Desktop.
sobel.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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