Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alpha not changing transparency of object using glsl shader

Tags:

opengl

glsl

How come when i manually change the alpha value in array, being passed to shader, the result is the same for both 0.0f and 1.0f?

I was expecting the object to be drawn with some level of transparency, depending on alpha value.

I'm not using any textures. I always see my red object against a black background.

accessing glsl variable from java ..

float[] color = {1.0f, 0.0f, 0.0f, 1.0f};

gl2.glGetUniformLocation(shaderProgram, "vColor");
gl2.glUniform4fv(mColorHandle, 1, color, 0);

glsl, fragment shader ..

#version 120

uniform vec4 vColor;

void main() {
    gl_FragColor = vColor;
    gl_FragColor.a = 0.0; // does not make object transparent
    // gl_FragColor.a = 1.0; // does not make object transparent
}
like image 502
bobbyrne01 Avatar asked May 11 '15 00:05

bobbyrne01


People also ask

How do I enable transparency in OpenGL?

OpenGL “transparency” would instead blend the RGB of the red object with the RGB of the green glass, giving a shade of yellow. Instead of using glColor3f( ) to specify the red, green, and blue of an object, use glColor4f( ) to specify red, green, blue, and alpha. Alpha is the transparency factor.

How do I optimize GLSL?

One way to speed up GLSL code, is by marking some variables constant at compile-time. This way the compiler may optimize code (e.g. unroll loops) and remove unused code (e.g. if hard shadows are disabled). The drawback is that changing these constant variables requires that the GLSL code is compiled again.

How does GLSL shaders work?

Shaders use GLSL (OpenGL Shading Language), a special OpenGL Shading Language with syntax similar to C. GLSL is executed directly by the graphics pipeline. There are several kinds of shaders, but two are commonly used to create graphics on the web: Vertex Shaders and Fragment (Pixel) Shaders.

Does Shadertoy use GLSL?

Shadertoy.com is an online community and platform for computer graphics professionals, academics and enthusiasts who share, learn and experiment with rendering techniques and procedural art through GLSL code.


1 Answers

Needed to enable blending ..

gl2.glEnable(GL.GL_BLEND);
gl2.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
like image 106
bobbyrne01 Avatar answered Sep 19 '22 04:09

bobbyrne01