0
101 Mar 02, 2007 at 13:39

Hi everyone,

I was wondering if anyone could help me with a problem I’m having with my GLSL shaders. I’m trying to make certain vertices in my geometry (a skydome) partially transparent. The intent being to create a day/night transition by having an outer skydome to represent space beyond the atmosphere, as well as an inner skydome to model the clouds.

I’m running into a problem before I even get off the ground though; I can’t actually get any of the pixels to be tranparent. The way I’ve tried it so far is as follows (this is for the clouds)…

varying vec2 texCoords_Clouds;
void main(void)
{
texCoords_Clouds = gl_MultiTexCoord0.st;
gl_Position = ftransform();
}


uniform sampler2D cloudsTexture;
varying vec2 texCoords_Clouds;

void main (void)
{
vec3 color_Clouds = vec3(texture2D(cloudsTexture, texCoords_Clouds));
float alphaFade = color_Clouds.r / 256.0;
}


I’m using Java3D, and the texture being passed in is a BufferedImage.TYPE_BYTE_GRAY if that makes any difference.

The idea behind my fragment shader is that the grey value determines the transparency of a pixel (black pixels being totally transparent, white pixels being totally opaque).

It makes sense to me in theory to approach it like this, but when I run the program, all the pixels are totally opaque. Even when I just use an artificial value of say… “gl_FragColor = vec4(color_Clouds,0.1);”, I still get all pixels being totally opaque!!

Does anyone have any idea what the problem might be here? Am I even using the fourth value in the vec4 correctly?

Thanks for any advice you can give.

#### 2 Replies

0
101 Mar 02, 2007 at 14:07

Have you enabled GL_BLEND and set glBlendFunc to (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)?

0
101 Mar 02, 2007 at 14:32

Hi hovermonkey,

Thank you, that was exactly the problem. Although, as I mentioned, I am using the Java3D API, so am not making any direct calls to OpenGL.

As a point of interest for anyone who is curious about how to do this in Java3D, the code is as follows…

ShaderAppearance app = new ShaderAppearance();

...
// Other work goes here, like attaching shader programs etc.
...

TransparencyAttributes tranAttrib = new TransparencyAttributes(TransparencyAttributes.BLENDED,1.0f,TransparencyAttributes.BLEND_SRC_ALPHA,TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);

app.setTransparencyAttributes(tranAttrib);


Thanks again hovermonkey, I’ve now got some fairly acceptable looking skies in my project!!