Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: lighting calculations causing transparency??

  1. #1
    Intern Newbie
    Join Date
    Nov 2010

    lighting calculations causing transparency??


    I am just learning OpenGLES 2.0 and am having trouble with textures, blending and shading. I have a working example where I texture-map a cube. I'm working off the tutorials provided here:

    At the end of that tutorial they apply a decal-like second texture map, and they enable blending so that the alpha in the decal is applied correctly.


    However, when I do it, it does work but also it has the side effect of turning all the rest of my objects half-transparent!

    I think this is happening in my vertex shader, in the calculations that create the color:

    attribute vec4 position;
    attribute vec3 normal;

    varying lowp vec4 colorVarying;

    uniform mat4 modelViewProjectionMatrix;
    uniform mat3 normalMatrix;

    attribute vec2 TexCoordIn;
    varying vec2 TexCoordOut;

    void main()
    vec3 eyeNormal = normalize(normalMatrix * normal);
    vec3 lightPosition = vec3(0.0, 0.0, 1.0);
    vec4 diffuseColor = vec4(0.7, 0.7, 1.0, 1.0);

    float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));

    colorVarying = diffuseColor * nDotVP; // this multiplication causes it?

    gl_Position = modelViewProjectionMatrix * position;
    TexCoordOut = TexCoordIn;


    This produces half-transparent objects.
    In my tests though, if I skip the lighting multiplication (*nDotVP) above, and I just set colorVarying = diffuseColor, then the object becomes solid again. It seems like there is something in those lighting-eye calculations which is mangling the alpha value, is that possible? Anyone know why or how I can fix it?


  2. #2
    Intern Newbie
    Join Date
    Oct 2010

    I am a beginner, so...

    In this formula : colorVarying = diffuseColor * nDotVP;
    The last component (alpha) in diffuseColor is 1.0. But after calculation if it is no more 1.0 then your objects are transparent.
    The alpha you want is in diffuseColor. So I would do that :
    colorVarying = diffuseColor * nDotVP;
    colorVarying.a = diffuseColor.a;

    Here you set the alpha you want.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts