Shader bug

Megax60

Member
Here is the daily question:

How do i prevent "my" sprite from this to happen when i apply a shader

http://i.imgur.com/0bTl0TP.png

My shader vertex is the default and the fragment is this:

//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
// Get the original color of the pixel
vec4 OC = texture2D( gm_BaseTexture, v_vTexcoord );

float Average = (OC.r + OC.g + OC.b) / 3.0;
float Alpha = 1.0;

// Create the color
vec4 Color = vec4(Average, Average, Average, Alpha);

// Output the new color
gl_FragColor = Color;
}
 
I think this should fix it:

Code:
void main() {
    vec4 OC = texture2D( gm_BaseTexture, v_vTexcoord );
    float Average = (OC.r + OC.g + OC.b) / 3.0;
    gl_FragColor = vec4(Average, Average, Average, OC.a);
}
You're setting your sprite to fully opaque instead of grabbing the alpha from the original color. So I just replaced 1.0 with OC.a
 

Megax60

Member
I think this should fix it:

Code:
void main() {
    vec4 OC = texture2D( gm_BaseTexture, v_vTexcoord );
    float Average = (OC.r + OC.g + OC.b) / 3.0;
    gl_FragColor = vec4(Average, Average, Average, OC.a);
}
You're setting your sprite to fully opaque instead of grabbing the alpha from the original color. So I just replaced 1.0 with OC.a
It worrked, thankks!
 
Top