mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0027925: Visualization - implement order-independent transparency algorithm within rasterization rendering
Weighted, Blended Order-Independent Transparency algorithm has been added rasterization pipeline. In contrast to classical blending transparency it makes transparent objects look independent from point of view. It also gives better depth occlusion when being used together with a weight factor based on value of a GL depth buffer. The feature supports desktop OpenGL, OpenGL ES 3.0, ANGLE and can be used together with MSAA on desktop GL. To be used it require availability of: 1) Shaders pipeline. 2) Floating point color format for framebuffer (GL_ARB_color_buffer_float). 3) Multiple render targets (GL_ARB_draw_buffers). Patch does not modify API and does not require application porting. It adds new rendering options to Graphic3d_RenderingParams structure: a) Transparency method from enumeration. b) Scalar factor [0-1] controlling influence of a fragment's depth to its visibility. Patch also simplifies processing of transparent objects for standard method: rendering priority of transparent graphical structures is managed automatically, therefore there is no need to care about it at application's side.
This commit is contained in:
@@ -47,8 +47,16 @@
|
||||
THE_ATTRIBUTE vec4 occVertColor;
|
||||
#elif (__VERSION__ >= 130)
|
||||
out vec4 occFragColor;
|
||||
#ifdef OCC_ENABLE_draw_buffers
|
||||
out vec4 occFragCoverage;
|
||||
#endif
|
||||
#else
|
||||
#define occFragColor gl_FragColor
|
||||
#ifdef OCC_ENABLE_draw_buffers
|
||||
#define occFragColor gl_FragData[0]
|
||||
#define occFragCoverage gl_FragData[1]
|
||||
#else
|
||||
#define occFragColor gl_FragColor
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Matrix state
|
||||
@@ -110,6 +118,10 @@ uniform sampler2D occActiveSampler; //!< Current active sampl
|
||||
uniform vec4 occTexTrsf2d[2]; //!< 2D texture transformation parameters
|
||||
uniform float occPointSize; //!< point size
|
||||
|
||||
//! Parameters of blended order-independent transparency rendering algorithm
|
||||
uniform int occOitOutput; //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage)
|
||||
uniform float occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment
|
||||
|
||||
//! Parameters of clipping planes
|
||||
uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
|
||||
uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes
|
||||
|
@@ -166,10 +166,11 @@ vec4 computeLighting (in vec3 theNormal,
|
||||
vec4 aMaterialDiffuse = gl_FrontFacing ? occFrontMaterial_Diffuse() : occBackMaterial_Diffuse();
|
||||
vec4 aMaterialSpecular = gl_FrontFacing ? occFrontMaterial_Specular() : occBackMaterial_Specular();
|
||||
vec4 aMaterialEmission = gl_FrontFacing ? occFrontMaterial_Emission() : occBackMaterial_Emission();
|
||||
return vec4 (Ambient, 1.0) * aMaterialAmbient
|
||||
+ vec4 (Diffuse, 1.0) * aMaterialDiffuse
|
||||
+ vec4 (Specular, 1.0) * aMaterialSpecular
|
||||
+ aMaterialEmission;
|
||||
vec3 aColor = Ambient * aMaterialAmbient.rgb
|
||||
+ Diffuse * aMaterialDiffuse.rgb
|
||||
+ Specular * aMaterialSpecular.rgb
|
||||
+ aMaterialEmission.rgb;
|
||||
return vec4 (aColor, aMaterialDiffuse.a);
|
||||
}
|
||||
|
||||
//! Entry point to the Fragment Shader
|
||||
@@ -185,7 +186,14 @@ void main()
|
||||
}
|
||||
}
|
||||
|
||||
gl_FragColor = computeLighting (normalize (Normal),
|
||||
occFragColor = computeLighting (normalize (Normal),
|
||||
normalize (View),
|
||||
Position);
|
||||
|
||||
if (occOitOutput != 0)
|
||||
{
|
||||
float aWeight = occFragColor.a * clamp (1e+2 * pow (1.0 - gl_FragCoord.z * occOitDepthFactor, 3.0), 1e-2, 1e+2);
|
||||
occFragCoverage.r = occFragColor.a * aWeight;
|
||||
occFragColor = vec4 (occFragColor.rgb * occFragColor.a * aWeight, occFragColor.a);
|
||||
}
|
||||
}
|
||||
|
@@ -50,8 +50,16 @@ static const char Shaders_Declarations_glsl[] =
|
||||
" THE_ATTRIBUTE vec4 occVertColor;\n"
|
||||
"#elif (__VERSION__ >= 130)\n"
|
||||
" out vec4 occFragColor;\n"
|
||||
" #ifdef OCC_ENABLE_draw_buffers\n"
|
||||
" out vec4 occFragCoverage;\n"
|
||||
" #endif\n"
|
||||
"#else\n"
|
||||
" #define occFragColor gl_FragColor\n"
|
||||
" #ifdef OCC_ENABLE_draw_buffers\n"
|
||||
" #define occFragColor gl_FragData[0]\n"
|
||||
" #define occFragCoverage gl_FragData[1]\n"
|
||||
" #else\n"
|
||||
" #define occFragColor gl_FragColor\n"
|
||||
" #endif\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"// Matrix state\n"
|
||||
@@ -113,6 +121,10 @@ static const char Shaders_Declarations_glsl[] =
|
||||
"uniform vec4 occTexTrsf2d[2]; //!< 2D texture transformation parameters\n"
|
||||
"uniform float occPointSize; //!< point size\n"
|
||||
"\n"
|
||||
"//! Parameters of blended order-independent transparency rendering algorithm\n"
|
||||
"uniform int occOitOutput; //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage)\n"
|
||||
"uniform float occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment\n"
|
||||
"\n"
|
||||
"//! Parameters of clipping planes\n"
|
||||
"uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];\n"
|
||||
"uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes\n";
|
||||
|
Reference in New Issue
Block a user