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


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;
}

Please use [noparse]

...

or

...

[/noparse] 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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.