Shaders [Solved] A shader works fine on windows but not on linux?

Goldoche

Member
I'm using a very simple shader for my game which displays a sprite pure white.

shader.vsh:
Code:
attribute vec3 in_Position;                  // (x,y,z)
attribute vec4 in_Colour;                    // (r,g,b,a)
attribute vec2 in_TextureCoord;              // (u,v)

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
    vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
    gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
    
    v_vColour = in_Colour;
    v_vTexcoord = in_TextureCoord;
}
shader.fsh:
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

void main()
{
   vec4 couleur = texture2D( gm_BaseTexture, v_vTexcoord );
   if (couleur.a != 0.0)
       gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
This works fine on windows but on linux it just displays a white box.

Windows:


Linux:


I've already tried setting the shader type from "GLSL ES" to "GLSL" but it makes no difference. Anybody knows what could be wrong?

I have two slightly more complex shaders that seem to display fine on Linux.
 

NightFrost

Member
Well that's color data so they are floats. A float containing zero might not be exactly zero, as you've proven with your shader. Using IF in shader at least used to be inadvisable as it was slow, not too sure what the current stance is. Luckily you don't need it at all, as you can just do:
Code:
vec4 couleur = texture2D(gm_BaseTexture, v_vTexcoord);
gl_FragColor = vec4(1.0, 1.0, 1.0 ,couleur.a);
 

Goldoche

Member
Your solution works but I've made a few tests and

Code:
if (couleur.a != 0.0)
{
    gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
else
{
    gl_FragColor = couleur;
}
works fine too. I deduce it wasn't a rounding error but gl_FragColor not resetting for every pixel? Anyway, I'll go with your solution because you're right that it's a bit more efficient.

Thank you very much!
 
Top