haoc
haoc

Reputation: 67

GLSL program debugging

#ifdef GL_ES                                
precision lowp float;                        
#endif                                        

varying vec4 v_fragmentColor;                        
varying vec2 v_texCoord;                            
varying vec2 v_texCoordBlendMap;                    
varying vec3 v_normal;                              

varying vec4 v_FogColor;                    
varying float v_distance;                     
uniform sampler2D u_texture;                      
uniform sampler2D u_tex1;                    
uniform sampler2D u_tex2;                     
uniform sampler2D u_tex3;                     
void main()                                    
{                                                
 vec4 colour1    = texture2D(u_texture,          v_texCoord); 
vec4 colour2    = texture2D(u_tex1,      v_texCoord);  
float blendVal = texture2D(u_tex2,       v_texCoordBlendMap).r; 
float fValue = 1.0 - blendVal; 
vec4 texColor  = colour1*fValue +   colour2*blendVal; 
texColor.a = 1;                 
v_fragmentColor.a = 1;          
vec4 finalclr = texColor * v_fragmentColor; 
    if(finalclr.a == 1)         //why not it equal 1        
        {                                       
        gl_FragColor=vec4(1,0,0,1);         
     }                                      
     else                                   
     {                                      
        gl_FragColor=vec4(1,1,1,1);         
    }                                       
}                                           

hi,guys ,sorry about asking it on cellphone。I'm being puzzled by debugging blender script in this week. the above ps script it was used for moduling two RGBA.but for testing and simplification,i 'm writing two Alpha channel to be 1.0 intentionally and expecting red colour of output.but the frag colour output is white instead of red colour. how could it be?

Upvotes: 2

Views: 186

Answers (1)

Preet Kukreti
Preet Kukreti

Reputation: 8607

Try narrowing it down a bit more with:

finalclr.a = texColor.a * v_fragmentColor.a;

It could very well be that:

  • the vector multiplication operator may not be what you are expecting
  • the vector multiplication is introducing floating point inaccuracies.
  • the float multiplication is introducing floating point inaccuracies.
  • v_fragmentColor is not writeable.
  • fragment shaders get a default medium precision AFAIK, you might have to supply precision highp precision specifier

If it comes down to a precision issue you cant get around, compare the difference of floats a and b using something like:

if (abs(a - b) < EPSILON) // absolute value of difference
{
    // consider them equal...
}

where EPSILON is some small value.

Upvotes: 1

Related Questions