![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Diet Estus |
I am playing around with shaders in my 2D project in Godot 3.
I am trying to write a fragment()
method that samples my sprite’s texture, then checks whether the current pixel has any red neighbors (that is, whether there is a red pixel immediately above, below, left, or right). If the current pixel has any red neighbors, I want to change the current pixel to green.
Sampling my sprite’s texture and changing the current pixel to green are easy.
shader_type canvas_item;
render_mode unshaded;
void fragment()
{
// sample texture to get color data
vec4 tex_color = texture(TEXTURE, UV);
// check if neighbors are red...
// if there is a red neighbor...
// change current pixel to green
{
COLOR = vec4(0.0, 1.0, 0.0, 1.0)
}
}
But how would I go about checking the color of neighboring pixels?