Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: two direction transparency

  1. #1
    Junior Member Newbie techwinder's Avatar
    Join Date
    Feb 2016
    Paris, France

    two direction transparency

    Hi everyone,
    Need some help after having struggled unsuccessfully with this problem for some time.
    Click image for larger version. 

Name:	transparency.jpg 
Views:	18 
Size:	7.7 KB 
ID:	2889
    The transparency and light are OK seen from one side, but not from the other.
    The objects are arrays of triangles drawn using
    Code :
    Am I missing something?
    Thanks in advance for any help.

    The fragment shader:
    Code :
    #version 410
    in vec3 Position_viewSpace;
    in vec3 Normal_viewSpace;
    in vec3 EyeDirection_viewSpace;
    in vec3 LightDirection_viewSpace;
    in vec3 vPosition;
    in vec4 vertexcolor;
    uniform int lightOn;
    uniform vec3 LightPosition_viewSpace;
    uniform vec4 LightColor;
    uniform float LightAmbient, LightDiffuse, LightSpecular;
    uniform float Kc, Kl, Kq;
    uniform float MaterialShininess;
    uniform vec4 clipPlane0; // defined in view-space
    out vec4 fragColor;
    void main()
    	// Material properties
    	vec4 MaterialAmbientColor, MaterialDiffuseColor, MaterialSpecularColor;
    	if (vPosition.z > clipPlane0.w)
    		MaterialAmbientColor  = vec4(vertexcolor.rgb * LightAmbient, vertexcolor.a);
    		MaterialDiffuseColor  = vec4(vertexcolor.rgb * LightDiffuse, vertexcolor.a);
    		MaterialSpecularColor = vec4(1.0, 1.0, 1.0, 1.0);
    		// Distance to the light
    		float distance = length(LightPosition_viewSpace - Position_viewSpace);
    		// Normal of the computed fragment, in viewSpace
    		vec3 N = normalize(Normal_viewSpace);
    		// Direction from the fragment to the light
    		vec3 L = normalize(LightDirection_viewSpace);
    		// Cosine of the angle between the normal and the light direction, clamped above 0
    		float cosTheta = clamp(dot(N,L), 0.0, 1.0);
    		// Direction from the vertex to the eye, in view space.
    		vec3 E = normalize(EyeDirection_viewSpace);
    		// Direction in which the triangle reflects the light
    		vec3 R = reflect(-L,N);
    		// Cosine of the angle between the Eye vector and the Reflect vector,
    		float cosAlpha = clamp(dot(E,R), 0.0, 1.0);
    		float attenuation_factor = clamp(1.0/(Kc + Kl*distance + Kq*distance*distance), 0.00001, 1.0);
    		gl_FragColor =
    			  MaterialAmbientColor  * LightColor +
    			 (MaterialDiffuseColor  * LightDiffuse  * cosTheta)                         * LightColor * attenuation_factor
    			+(MaterialSpecularColor * LightSpecular * pow(cosAlpha, MaterialShininess)) * LightColor * attenuation_factor;
    		gl_FragColor  = vertexcolor;

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Quote Originally Posted by techwinder View Post
    The transparency and light are OK seen from one side, but not from the other.
    Translucent polygons usually need to be drawn in a particular order (either back-to-front or front-to-back, depending upon the blending mode). BSP trees are one common solution to this issue.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Search the archives of these forums for "order independent transparency" and you'll come up with a number other options for dealing with this. Examples: A-buffer, Weighted Average blending, Depth Peeling, MSAA Alpha (ALPHA_TO_COVERAGE), etc.

Tags for this Thread

Posting Permissions

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