TotallyAverageGamez
Member
Hey All,
Have a question about shader code. I am trying to create an outline shader that draws a border (highlight) 1px wide around an object. The code I am using so far is this:
The logic goes:
-If there is a color already here (alpha != 0.0) leave the pixel alone.
-else if the pixel one to the right (x +1) has an alpha, change to the outline color (yellow).
I plan on doing -x, +y, and -y once I get +x working. The thing is for some reason the line:
I have the sprite on its own texture page with plenty of border and the automatic crop option disabled in the texture group settings as well.
Am I just not using the texture2D function correctly? Or is there some other way I should be doing this? Any and all help appreciated!
Thanks!
Have a question about shader code. I am trying to create an outline shader that draws a border (highlight) 1px wide around an object. The code I am using so far is this:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec4 outlineColor;
void main()
{
vec4 originalColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord);
vec4 newColor = outlineColor;
newColor.a = 1.0;
if(originalColor.a != 0.0)
{
newColor = originalColor;
}
else if(texture2D(gm_BaseTexture, v_vTexcoord + vec2(1.0, 0.0)).a != 0.0)
{
newColor = outlineColor;
}
gl_FragColor = newColor;
}
varying vec4 v_vColour;
uniform vec4 outlineColor;
void main()
{
vec4 originalColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord);
vec4 newColor = outlineColor;
newColor.a = 1.0;
if(originalColor.a != 0.0)
{
newColor = originalColor;
}
else if(texture2D(gm_BaseTexture, v_vTexcoord + vec2(1.0, 0.0)).a != 0.0)
{
newColor = outlineColor;
}
gl_FragColor = newColor;
}
The logic goes:
-If there is a color already here (alpha != 0.0) leave the pixel alone.
-else if the pixel one to the right (x +1) has an alpha, change to the outline color (yellow).
I plan on doing -x, +y, and -y once I get +x working. The thing is for some reason the line:
if(texture2D(gm_BaseTexture, v_vTexcoord + vec2(1.0, 0.0)).a != 0.0)
Is always returning true and the entire sprite (outside of the original pixels) is completely highlighted yellow.
I have the sprite on its own texture page with plenty of border and the automatic crop option disabled in the texture group settings as well.
Am I just not using the texture2D function correctly? Or is there some other way I should be doing this? Any and all help appreciated!
Thanks!