Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: why are my objects translucent?

  1. #1
    Intern Newbie
    Join Date
    Nov 2010
    Posts
    40

    why are my objects translucent?

    Hello,

    I have this shader and it is turning all of my objects translucent. From the code it looks to me like the color's alpha value will always be 1, but it is not. If I explicitly set 'colorVarying.w' to 1.0 at the end, then the objects appear opaque. Can anyone see how my alpha would be anything but 1 from this code?

    Thanks,
    Bob

    Code glsl:
    in vec4  position;
    in vec3  normal;
    in lowp vec4  color;
    out lowp vec4 colorVarying;
     
     
    uniform mat4 modelViewProjectionMatrix;
    uniform mat3 normalMatrix;
     
     
    void main()
    {
        vec3 eyeNormal = normalize(normalMatrix * normal);
        vec3 lightPosition = vec3(0.0, 0.5, 1.0);
     
     
        float nDotVP = min(1.0,max(0.0, dot(eyeNormal, normalize(lightPosition))));
     
     
        colorVarying = color * nDotVP;                       // both of these produce
        colorVarying = vec4(0.5, 0.5, 0.5, 1.0) * nDotVP;    // translucent objects
     
     
        gl_Position = modelViewProjectionMatrix * position;
    }
    Last edited by Dark Photon; 01-08-2013 at 06:03 PM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Please use [highlight=glsl]...[/highlight] or [code]...[/code] blocks to surround source code. Keeps the indentation and is easier to read. Fixed that for you.

    Well, nDotVP should be in 0..1.
    color is a vec4, which includes alpha (color.a).
    When you multiply color * nDotVP, it's going to scale color.a down too.
    So assuming it started at 1, it's going to be < 1 if nDotVP is < 1.

    As to the 2nd, example -- same thing.

Posting Permissions

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