Results 1 to 2 of 2

Thread: lighting calculations causing transparency??

  1. #1
    Member Contributor
    Join Date
    May 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
    Member Contributor
    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.

Similar Threads

  1. Lighting and Normal Calculations
    By WillsB in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 03-30-2009, 06:54 PM
  2. Lighting calculations for large point cloud
    By thinks in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 12-19-2006, 12:32 AM
  3. lighting and transparency
    By mithun_daa in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-30-2003, 05:55 AM
  4. Lighting Class Causing Errors in gl.h?
    By 31337 in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 12-13-2002, 02:31 AM
  5. Lighting and Transparency
    By cix>foo in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 07-06-2000, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean