1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029337: Visualization, TKOpenGl - visual artifacts on Intel Broadwell GPU

Enable multiple draw buffers in shader program only if its required by specific application.

occSetFragColor() - a new GLSL function has been introduced
as an alternative to setting occFragColor/occFragCoverage variables.
This commit is contained in:
apl
2017-11-27 15:16:21 +03:00
committed by apn
parent 12d71ad6a5
commit b17e5bae1a
12 changed files with 201 additions and 75 deletions

View File

@@ -24,6 +24,10 @@
//! Specifies the length of array of clipping planes, which is 8 by default. Defined by Shader Manager.
// #define THE_MAX_CLIP_PLANES 8
//! @def THE_NB_FRAG_OUTPUTS
//! Specifies the length of array of Fragment Shader outputs, which is 1 by default. Defined by Shader Manager.
// #define THE_NB_FRAG_OUTPUTS 1
// compatibility macros
#if (__VERSION__ >= 130)
#define THE_ATTRIBUTE in
@@ -58,20 +62,43 @@
#elif defined(FRAGMENT_SHADER)
#if (__VERSION__ >= 130)
#ifdef OCC_ENABLE_draw_buffers
out vec4 occFragColorArray[2];
#define occFragColor occFragColorArray[0]
#define occFragCoverage occFragColorArray[1]
out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS];
#define occFragColorArrayAlias occFragColorArray
#define occFragColor0 occFragColorArray[0]
#else
out vec4 occFragColor;
out vec4 occFragColor0;
#endif
#else
#ifdef OCC_ENABLE_draw_buffers
#define occFragColor gl_FragData[0]
#define occFragCoverage gl_FragData[1]
#define occFragColorArrayAlias gl_FragData
#define occFragColor0 gl_FragData[0]
#else
#define occFragColor gl_FragColor
#define occFragColor0 gl_FragColor
#endif
#endif
#if (THE_NB_FRAG_OUTPUTS >= 2)
#define occFragColor1 occFragColorArrayAlias[1]
#else
vec4 occFragColor1;
#endif
#if (THE_NB_FRAG_OUTPUTS >= 3)
#define occFragColor2 occFragColorArrayAlias[2]
#else
vec4 occFragColor2;
#endif
#if (THE_NB_FRAG_OUTPUTS >= 4)
#define occFragColor3 occFragColorArrayAlias[3]
#else
vec4 occFragColor3;
#endif
// Built-in outputs notation
#define occFragColor occFragColor0
#define occFragCoverage occFragColor1
//! Define the main Fragment Shader output - color value.
void occSetFragColor (in vec4 theColor);
#endif
// Matrix state

View File

@@ -15,6 +15,21 @@
// This file includes implementation of common functions and properties accessors
#if defined(FRAGMENT_SHADER)
#if defined(OCC_WRITE_WEIGHT_OIT_COVERAGE)
//! Output color and coverage for accumulation by OIT algorithm.
void occSetFragColor (in vec4 theColor)
{
float aWeight = theColor.a * clamp (1e+2 * pow (1.0 - gl_FragCoord.z * occOitDepthFactor, 3.0), 1e-2, 1e+2);
occFragCoverage.r = theColor.a * aWeight;
occFragColor = vec4 (theColor.rgb * theColor.a * aWeight, theColor.a);
}
#else
//! Output color.
void occSetFragColor (in vec4 theColor) { occFragColor = theColor; }
#endif
#endif
#if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
// arrays of light sources
uniform THE_PREC_ENUM ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types

View File

@@ -186,14 +186,6 @@ void main()
}
}
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);
}
vec4 aColor = computeLighting (normalize (Normal), normalize (View), Position);
occSetFragColor (aColor);
}

View File

@@ -18,6 +18,21 @@ static const char Shaders_DeclarationsImpl_glsl[] =
"\n"
"// This file includes implementation of common functions and properties accessors\n"
"\n"
"#if defined(FRAGMENT_SHADER)\n"
"#if defined(OCC_WRITE_WEIGHT_OIT_COVERAGE)\n"
"//! Output color and coverage for accumulation by OIT algorithm.\n"
"void occSetFragColor (in vec4 theColor)\n"
"{\n"
" float aWeight = theColor.a * clamp (1e+2 * pow (1.0 - gl_FragCoord.z * occOitDepthFactor, 3.0), 1e-2, 1e+2);\n"
" occFragCoverage.r = theColor.a * aWeight;\n"
" occFragColor = vec4 (theColor.rgb * theColor.a * aWeight, theColor.a);\n"
"}\n"
"#else\n"
"//! Output color.\n"
"void occSetFragColor (in vec4 theColor) { occFragColor = theColor; }\n"
"#endif\n"
"#endif\n"
"\n"
"#if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)\n"
"// arrays of light sources\n"
"uniform THE_PREC_ENUM ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types\n"

View File

@@ -27,6 +27,10 @@ static const char Shaders_Declarations_glsl[] =
"//! Specifies the length of array of clipping planes, which is 8 by default. Defined by Shader Manager.\n"
"// #define THE_MAX_CLIP_PLANES 8\n"
"\n"
"//! @def THE_NB_FRAG_OUTPUTS\n"
"//! Specifies the length of array of Fragment Shader outputs, which is 1 by default. Defined by Shader Manager.\n"
"// #define THE_NB_FRAG_OUTPUTS 1\n"
"\n"
"// compatibility macros\n"
"#if (__VERSION__ >= 130)\n"
" #define THE_ATTRIBUTE in\n"
@@ -61,20 +65,43 @@ static const char Shaders_Declarations_glsl[] =
"#elif defined(FRAGMENT_SHADER)\n"
" #if (__VERSION__ >= 130)\n"
" #ifdef OCC_ENABLE_draw_buffers\n"
" out vec4 occFragColorArray[2];\n"
" #define occFragColor occFragColorArray[0]\n"
" #define occFragCoverage occFragColorArray[1]\n"
" out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS];\n"
" #define occFragColorArrayAlias occFragColorArray\n"
" #define occFragColor0 occFragColorArray[0]\n"
" #else\n"
" out vec4 occFragColor;\n"
" out vec4 occFragColor0;\n"
" #endif\n"
" #else\n"
" #ifdef OCC_ENABLE_draw_buffers\n"
" #define occFragColor gl_FragData[0]\n"
" #define occFragCoverage gl_FragData[1]\n"
" #define occFragColorArrayAlias gl_FragData\n"
" #define occFragColor0 gl_FragData[0]\n"
" #else\n"
" #define occFragColor gl_FragColor\n"
" #define occFragColor0 gl_FragColor\n"
" #endif\n"
" #endif\n"
"\n"
" #if (THE_NB_FRAG_OUTPUTS >= 2)\n"
" #define occFragColor1 occFragColorArrayAlias[1]\n"
" #else\n"
" vec4 occFragColor1;\n"
" #endif\n"
" #if (THE_NB_FRAG_OUTPUTS >= 3)\n"
" #define occFragColor2 occFragColorArrayAlias[2]\n"
" #else\n"
" vec4 occFragColor2;\n"
" #endif\n"
" #if (THE_NB_FRAG_OUTPUTS >= 4)\n"
" #define occFragColor3 occFragColorArrayAlias[3]\n"
" #else\n"
" vec4 occFragColor3;\n"
" #endif\n"
"\n"
" // Built-in outputs notation\n"
" #define occFragColor occFragColor0\n"
" #define occFragCoverage occFragColor1\n"
"\n"
" //! Define the main Fragment Shader output - color value.\n"
" void occSetFragColor (in vec4 theColor);\n"
"#endif\n"
"\n"
"// Matrix state\n"