View Issue Details

IDProjectCategoryView StatusLast Update
0033074Open CASCADEOCCT:Visualizationpublic2023-03-19 20:44
Reporterkgv Assigned Tovpozdyayev 
PrioritynormalSeverityminor 
Status closedResolutionfixed 
PlatformLinuxOSUbuntu 20.04 
Product Version7.5.0 
Target Version7.6.3Fixed in Version7.7.0 
Summary0033074: Visualization, TKOpenGl - PBR shader compilation error on Mesa OpenGL 3.1
DescriptionPBR initialization fails on Mesa OpenGL 3.1 implementation.

TKOpenGl | Type: Error | ID: 0 | Severity: High | Message:
  
1: #version 120
2: // Enable extensions used in OCCT GLSL programs
3: #extension GL_ARB_sample_shading : enable
4: #define FRAGMENT_SHADER
5: #define THE_MAX_LIGHTS 0
6: #define THE_MAX_CLIP_PLANES 0
7: #define THE_NB_FRAG_OUTPUTS 1
8: #define THE_IS_PBR
9: 
10: //! @file Declarations.glsl includes definition of common uniform variables in OCCT GLSL programs
11: //! @def THE_MAX_LIGHTS
12: //! Specifies the length of array of lights, which is 8 by default. Defined by Shader Manager.
13: // #define THE_MAX_LIGHTS 8
14: 
15: //! @def THE_MAX_CLIP_PLANES
16: //! Specifies the length of array of clipping planes, which is 8 by default. Defined by Shader Manager.
17: // #define THE_MAX_CLIP_PLANES 8
18: 
19: //! @def THE_NB_FRAG_OUTPUTS
20: //! Specifies the length of array of Fragment Shader outputs, which is 1 by default. Defined by Shader Manager.
21: // #define THE_NB_FRAG_OUTPUTS 1
22: 
23: // compatibility macros
24: #if (__VERSION__ >= 130)
25:   #define THE_ATTRIBUTE  in
26:   #define THE_SHADER_IN  in
27:   #define THE_SHADER_OUT out
28:   #define THE_OUT        out
29:   #define occTexture1D   texture
30:   #define occTexture2D   texture
31:   #define occTexture3D   texture
32:   #define occTextureCube texture
33:   #define occTextureCubeLod textureLod
34: #else
35:   #define THE_ATTRIBUTE  attribute
36:   #define THE_SHADER_IN  varying
37:   #define THE_SHADER_OUT varying
38:   #define THE_OUT
39:   #define occTexture1D   texture1D
40:   #define occTexture2D   texture2D
41:   #define occTexture3D   texture3D
42:   #define occTextureCube textureCube
43:   #if !defined(GL_ES) || defined(textureCubeLod)
44:     #define occTextureCubeLod textureCubeLod
45:   #else // fallback
46:     #define occTextureCubeLod(theSampl,theCoord,theLod) textureCube(theSampl,theCoord)
47:   #endif
48: #endif
49: 
50: #ifdef GL_ES
51: #if (__VERSION__ >= 300)
52:   #define THE_PREC_ENUM highp // lowp should be enough for enums but triggers driver bugs
53: #else
54:   #define THE_PREC_ENUM lowp
55: #endif
56: #else
57:   #define THE_PREC_ENUM
58: #endif
59: 
60: // Vertex attributes
61: #ifdef VERTEX_SHADER
62:   THE_ATTRIBUTE vec4 occVertex;
63:   THE_ATTRIBUTE vec3 occNormal;
64:   THE_ATTRIBUTE vec4 occTexCoord;
65:   THE_ATTRIBUTE vec4 occVertColor;
66: #elif defined(FRAGMENT_SHADER)
67:   #if (__VERSION__ >= 130)
68:     #ifdef OCC_ENABLE_draw_buffers
69:       out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS];
70:       #define occFragColorArrayAlias occFragColorArray
71:       #define occFragColor0 occFragColorArray[0]
72:     #else
73:       out vec4 occFragColor0;
74:     #endif
75:   #else
76:     #ifdef OCC_ENABLE_draw_buffers
77:       #define occFragColorArrayAlias gl_FragData
78:       #define occFragColor0 gl_FragData[0]
79:     #else
80:       #define occFragColor0 gl_FragColor
81:     #endif
82:   #endif
83: 
84:   #if (THE_NB_FRAG_OUTPUTS >= 2)
85:     #define occFragColor1 occFragColorArrayAlias[1]
86:   #else
87:     vec4 occFragColor1;
88:   #endif
89:   #if (THE_NB_FRAG_OUTPUTS >= 3)
90:     #define occFragColor2 occFragColorArrayAlias[2]
91:   #else
92:     vec4 occFragColor2;
93:   #endif
94:   #if (THE_NB_FRAG_OUTPUTS >= 4)
95:     #define occFragColor3 occFragColorArrayAlias[3]
96:   #else
97:     vec4 occFragColor3;
98:   #endif
99: 
100:   // Built-in outputs notation
101:   #define occFragColor    occFragColor0
102:   #define occFragCoverage occFragColor1
103: 
104:   #define occPeelDepth      occFragColor0
105:   #define occPeelFrontColor occFragColor1
106:   #define occPeelBackColor  occFragColor2
107: 
108:   //! Define the main Fragment Shader early return procedure.
109:   bool occFragEarlyReturn();
110: 
111:   //! Define the main Fragment Shader output - color value.
112:   void occSetFragColor (in vec4 theColor);
113: #endif
114: 
115: // Pi number definitions
116: #define PI       3.141592654
117: #define PI_2     6.283185307
118: #define PI_DIV_2 1.570796327
119: #define PI_DIV_3 1.047197551
120: #define PI_DIV_4 0.785398163
121: #define INV_PI   0.318309886
122: #define INV_PI_2 0.159154943
123: 
124: // Matrix state
125: uniform mat4 occWorldViewMatrix;  //!< World-view  matrix
126: uniform mat4 occProjectionMatrix; //!< Projection  matrix
127: uniform mat4 occModelWorldMatrix; //!< Model-world matrix
128: 
129: uniform mat4 occWorldViewMatrixInverse;    //!< Inverse of the world-view  matrix
130: uniform mat4 occProjectionMatrixInverse;   //!< Inverse of the projection  matrix
131: uniform mat4 occModelWorldMatrixInverse;   //!< Inverse of the model-world matrix
132: 
133: uniform mat4 occWorldViewMatrixTranspose;  //!< Transpose of the world-view  matrix
134: uniform mat4 occProjectionMatrixTranspose; //!< Transpose of the projection  matrix
135: uniform mat4 occModelWorldMatrixTranspose; //!< Transpose of the model-world matrix
136: 
137: uniform mat4 occWorldViewMatrixInverseTranspose;  //!< Transpose of the inverse of the world-view  matrix
138: uniform mat4 occProjectionMatrixInverseTranspose; //!< Transpose of the inverse of the projection  matrix
139: uniform mat4 occModelWorldMatrixInverseTranspose; //!< Transpose of the inverse of the model-world matrix
140: 
141: #if defined(THE_IS_PBR)
142: uniform sampler2D   occEnvLUT;             //!< Environment Lookup Table
143: uniform sampler2D   occDiffIBLMapSHCoeffs; //!< Packed diffuse (irradiance) IBL map's spherical harmonics coefficients
144: uniform samplerCube occSpecIBLMap;         //!< Specular IBL map
145: uniform int         occNbSpecIBLLevels;    //!< Number of mipmap levels used in occSpecIBLMap to store different roughness values maps
146: 
147: vec3 occDiffIBLMap (in vec3 theNormal); //!< Unpacks spherical harmonics coefficients to diffuse IBL map's values
148: #endif
149: 
150: // light type enumeration (same as Graphic3d_TypeOfLightSource)
151: const int OccLightType_Direct = 1; //!< directional     light source
152: const int OccLightType_Point  = 2; //!< isotropic point light source
153: const int OccLightType_Spot   = 3; //!< spot            light source
154: 
155: // Light sources
156: uniform               vec4 occLightAmbient;      //!< Cumulative ambient color
157: #if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
158: #if (THE_MAX_LIGHTS > 1)
159:   #define occLight_Index(theId) theId
160: #else
161:   #define occLight_Index(theId) 0
162: #endif
163: uniform THE_PREC_ENUM int  occLightSourcesCount; //!< Total number of light sources
164: 
165: //! Type of light source, int (see OccLightType enum).
166: #define occLight_Type(theId)              occLightSourcesTypes[occLight_Index(theId)]
167: 
168: //! Specular intensity (equals to diffuse), vec3.
169: #define occLight_Specular(theId)          occLightSources[occLight_Index(theId) * 4 + 0].rgb
170: 
171: //! Intensity of light source (>= 0), float.
172: #define occLight_Intensity(theId)         occLightSources[occLight_Index(theId) * 4 + 0].a
173: 
174: //! Is light a headlight, bool? DEPRECATED method.
175: #define occLight_IsHeadlight(theId) false
176: 
177: //! Position of specified light source or direction of directional light source, vec3.
178: #define occLight_Position(theId)          occLightSources[occLight_Index(theId) * 4 + 1].xyz
179: 
180: //! Direction of specified spot light source, vec3.
181: #define occLight_SpotDirection(theId)     occLightSources[occLight_Index(theId) * 4 + 2].xyz
182: 
183: //! Range on which point light source (positional or spot) can affect (>= 0), float.
184: #define occLight_Range(theId)             occLightSources[occLight_Index(theId) * 4 + 2].w
185: 
186: //! Maximum spread angle of the spot light (in radians), float.
187: #define occLight_SpotCutOff(theId)        occLightSources[occLight_Index(theId) * 4 + 3].z
188: 
189: //! Attenuation of the spot light intensity (from 0 to 1), float.
190: #define occLight_SpotExponent(theId)      occLightSources[occLight_Index(theId) * 4 + 3].w
191: 
192: #if !defined(THE_IS_PBR)
193: //! Diffuse intensity (equals to Specular), vec3.
194: #define occLight_Diffuse(theId)           occLightSources[occLight_Index(theId) * 4 + 0].rgb
195: 
196: //! Const attenuation factor of positional light source, float.
197: #define occLight_ConstAttenuation(theId)  occLightSources[occLight_Index(theId) * 4 + 3].x
198: 
199: //! Linear attenuation factor of positional light source, float.
200: #define occLight_LinearAttenuation(theId) occLightSources[occLight_Index(theId) * 4 + 3].y
201: #endif
202: #endif
203: 
204: #if defined(THE_IS_PBR)
205: //! Converts roughness value from range [0, 1] to real value for calculations
206: float occRoughness (in float theNormalizedRoughness);
207: 
208: // Front/back material properties accessors
209: vec4  occPBRMaterial_Color(in bool theIsFront);    //!< Base color of PBR material
210: float occPBRMaterial_Metallic(in bool theIsFront); //!< Metallic coefficient
211: float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient
212: vec3  occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material
213: float occPBRMaterial_IOR(in bool theIsFront);      //!< Index of refraction
214: #define occMaterial_Emission occPBRMaterial_Emission
215: #define occMaterial_Color occPBRMaterial_Color
216: #else
217: vec4  occMaterial_Diffuse(in bool theIsFront);     //!< Diffuse  reflection
218: vec3  occMaterial_Specular(in bool theIsFront);    //!< Specular reflection
219: float occMaterial_Shininess(in bool theIsFront);   //!< Specular exponent
220: vec3  occMaterial_Ambient(in bool theIsFront);     //!< Ambient  reflection
221: vec3  occMaterial_Emission(in bool theIsFront);    //!< Emission color
222: #define occMaterial_Color occMaterial_Diffuse
223: #endif
224: 
225: #ifdef THE_HAS_DEFAULT_SAMPLER
226: #define occActiveSampler    occSampler0  //!< alias for backward compatibility
227: #define occSamplerBaseColor occSampler0  //!< alias to a base color texture
228: uniform sampler2D           occSampler0; //!< current active sampler;
229: #endif                                   //!  occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
230: 
231: #if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)
232: #define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))
233: #else
234: #define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)
235: #endif
236: 
237: #if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)
238: uniform sampler2D occSamplerOcclusion;   //!< R occlusion texture sampler
239: #define occMaterialOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;
240: #else
241: #define occMaterialOcclusion(theColor, theTexCoord)
242: #endif
243: 
244: #if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)
245: uniform sampler2D occSamplerEmissive;    //!< RGB emissive texture sampler
246: #define occMaterialEmission(theIsFront, theTexCoord) (occMaterial_Emission(theIsFront) * occTexture2D(occSamplerEmissive, theTexCoord).rgb)
247: #else
248: #define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)
249: #endif
250: 
251: #if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)
252: uniform sampler2D occSamplerNormal;      //!< XYZ normal texture sampler with W==0 indicating no texture
253: #define occTextureNormal(theTexCoord) occTexture2D(occSamplerNormal, theTexCoord)
254: #else
255: #define occTextureNormal(theTexCoord) vec4(0.0) // no normal map
256: #endif
257: 
258: #if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)
259: uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler
260: #define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
261: #define occMaterialMetallic(theIsFront,  theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)
262: #else
263: #define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)
264: #define occMaterialMetallic(theIsFront,  theTexCoord) occPBRMaterial_Metallic(theIsFront)
265: #endif
266: 
267: uniform               vec4      occColor;              //!< color value (in case of disabled lighting)
268: uniform THE_PREC_ENUM int       occDistinguishingMode; //!< Are front and back faces distinguished?
269: uniform THE_PREC_ENUM int       occTextureEnable;      //!< Is texture enabled?
270: uniform               vec4      occTexTrsf2d[2];       //!< 2D texture transformation parameters
271: uniform               float     occPointSize;          //!< point size
272: 
273: //! Parameters of blended order-independent transparency rendering algorithm
274: uniform               int       occOitOutput;      //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage)
275: uniform               float     occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment
276: uniform               float     occAlphaCutoff;    //!< alpha test cutoff value
277: 
278: //! Parameters of clipping planes
279: #if defined(THE_MAX_CLIP_PLANES) && (THE_MAX_CLIP_PLANES > 0)
280: uniform               vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
281: uniform THE_PREC_ENUM int  occClipPlaneChains[THE_MAX_CLIP_PLANES]; //! Indicating the number of planes in the Chain
282: uniform THE_PREC_ENUM int  occClipPlaneCount;   //!< Total number of clip planes
283: #endif
284: //! @endfile Declarations.glsl
285: 
286: //! @file DeclarationsImpl.glsl includes implementation of common functions and properties accessors
287: #if defined(FRAGMENT_SHADER)
288: 
289: #if defined(OCC_DEPTH_PEEL_OIT)
290: uniform sampler2D occDepthPeelingDepth;
291: uniform sampler2D occDepthPeelingFrontColor;
292: int IsFrontPeelLayer = -1;
293: bool occFragEarlyReturn()
294: {
295:   #define THE_DEPTH_CLEAR_VALUE -1e15f
296:   ivec2  aFragCoord = ivec2 (gl_FragCoord.xy);
297:   vec2   aLastDepth = texelFetch (occDepthPeelingDepth, aFragCoord, 0).rg;
298:   occPeelFrontColor = texelFetch (occDepthPeelingFrontColor, aFragCoord, 0);
299:   occPeelDepth.rg   = vec2 (THE_DEPTH_CLEAR_VALUE); // depth value always increases, so that MAX blend equation can be used
300:   occPeelBackColor  = vec4 (0.0); // back color is blend after each peeling pass
301: 
302:   float aNearDepth = -aLastDepth.x;
303:   float aFarDepth  =  aLastDepth.y;
304:   float aFragDepth = gl_FragCoord.z; // 0 - 1
305:   if (aFragDepth < aNearDepth || aFragDepth > aFarDepth)
306:   {
307:     return true; // skip peeled depth
308:   }
309:   else if (aFragDepth > aNearDepth && aFragDepth < aFarDepth)
310:   {
311:     // to be rendered at next peeling pass
312:     occPeelDepth.rg = vec2 (-aFragDepth, aFragDepth);
313:     return true;
314:   }
315: 
316:   IsFrontPeelLayer = (gl_FragCoord.z == aNearDepth) ? 1 : 0;
317:   return false;
318: }
319: #else
320: bool occFragEarlyReturn() { return false; }
321: #endif
322: 
323: void occSetFragColor (in vec4 theColor)
324: {
325: #if defined(OCC_ALPHA_TEST)
326:   if (theColor.a < occAlphaCutoff) discard;
327: #endif
328: #if defined(OCC_WRITE_WEIGHT_OIT_COVERAGE)
329:   float aWeight     = theColor.a * clamp (1e+2 * pow (1.0 - gl_FragCoord.z * occOitDepthFactor, 3.0), 1e-2, 1e+2);
330:   occFragCoverage.r = theColor.a * aWeight;
331:   occFragColor      = vec4 (theColor.rgb * theColor.a * aWeight, theColor.a);
332: #elif defined(OCC_DEPTH_PEEL_OIT)
333:   if (IsFrontPeelLayer == 1) // front is blended directly
334:   {
335:     vec4 aLastColor = occPeelFrontColor;
336:     float anAlphaMult = 1.0 - aLastColor.a;
337:     occPeelFrontColor.rgb = aLastColor.rgb + theColor.rgb * theColor.a * anAlphaMult;
338:     occPeelFrontColor.a = 1.0 - anAlphaMult * (1.0 - theColor.a);
339:   }
340:   else if (IsFrontPeelLayer == 0) // back is blended afterwards
341:   {
342:     occPeelBackColor = theColor;
343:   }
344: #else
345:   occFragColor = theColor;
346: #endif
347: }
348: #endif
349: 
350: #if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
351: // arrays of light sources
352: uniform               vec4 occLightSources[THE_MAX_LIGHTS * 4]; //!< packed light sources parameters
353: uniform THE_PREC_ENUM int occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types
354: #endif
355: 
356: #if defined(THE_IS_PBR)
357: vec3 occDiffIBLMap (in vec3 theNormal)
358: {
359:   vec3 aSHCoeffs[9];
360:   for (int i = 0; i < 9; ++i)
361:   {
362:     aSHCoeffs[i] = occTexture2D (occDiffIBLMapSHCoeffs, vec2 ((float(i) + 0.5) / 9.0, 0.0)).rgb;
363:   }
364:   return aSHCoeffs[0]
365: 
366:        + aSHCoeffs[1] * theNormal.x
367: 	   + aSHCoeffs[2] * theNormal.y
368: 	   + aSHCoeffs[3] * theNormal.z
369: 
370: 	   + aSHCoeffs[4] * theNormal.x * theNormal.z
371: 	   + aSHCoeffs[5] * theNormal.y * theNormal.z
372: 	   + aSHCoeffs[6] * theNormal.x * theNormal.y
373: 
374: 	   + aSHCoeffs[7] * (3.0 * theNormal.z * theNormal.z - 1.0)
375: 	   + aSHCoeffs[8] * (theNormal.x * theNormal.x - theNormal.y * theNormal.y);
376: }
377: #endif
378: 
379: // front and back material properties accessors
380: #if defined(THE_IS_PBR)
381: uniform vec4 occPbrMaterial[3 * 2];
382: 
383: #define MIN_ROUGHNESS 0.01
384: float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }
385: vec4  occPBRMaterial_Color(in bool theIsFront)     { return theIsFront ? occPbrMaterial[0]     : occPbrMaterial[3]; }
386: vec3  occPBRMaterial_Emission(in bool theIsFront)  { return theIsFront ? occPbrMaterial[1].rgb : occPbrMaterial[4].rgb; }
387: float occPBRMaterial_IOR(in bool theIsFront)       { return theIsFront ? occPbrMaterial[1].w   : occPbrMaterial[4].w; }
388: float occPBRMaterial_Metallic(in bool theIsFront)  { return theIsFront ? occPbrMaterial[2].b   : occPbrMaterial[5].b; }
389: float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].g : occPbrMaterial[5].g; }
390: #else
391: uniform vec4 occCommonMaterial[4 * 2];
392: 
393: vec4  occMaterial_Diffuse(in bool theIsFront)   { return theIsFront ? occCommonMaterial[0]     : occCommonMaterial[4]; }
394: vec3  occMaterial_Emission(in bool theIsFront)  { return theIsFront ? occCommonMaterial[1].rgb : occCommonMaterial[5].rgb; }
395: vec3  occMaterial_Specular(in bool theIsFront)  { return theIsFront ? occCommonMaterial[2].rgb : occCommonMaterial[6].rgb; }
396: float occMaterial_Shininess(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].a   : occCommonMaterial[6].a; }
397: vec3  occMaterial_Ambient(in bool theIsFront)   { return theIsFront ? occCommonMaterial[3].rgb : occCommonMaterial[7].rgb; }
398: #endif
399: 
400: // 2D texture coordinates transformation
401: vec2  occTextureTrsf_Translation(void) { return occTexTrsf2d[0].xy; }
402: vec2  occTextureTrsf_Scale(void)       { return occTexTrsf2d[0].zw; }
403: float occTextureTrsf_RotationSin(void) { return occTexTrsf2d[1].x; }
404: float occTextureTrsf_RotationCos(void) { return occTexTrsf2d[1].y; }
405: //! @endfile DeclarationsImpl.glsl
406: 
407: vec3 cubemapVectorTransform (in vec3 theVector,
408:                              in int  theYCoeff,
409:                              in int  theZCoeff)
410: {
411:   theVector = theVector.yzx;
412:   theVector.y *= float(theYCoeff);
413:   theVector.z *= float(theZCoeff);
414:   return theVector;
415: }//! Calculates micro facet normals distribution.
416: float occPBRDistribution (in float theCosH,
417:                           in float theRoughness)
418: {
419:   float aDistribution = theRoughness * theRoughness;
420:   aDistribution = aDistribution / (theCosH * theCosH * (aDistribution * aDistribution - 1.0) + 1.0);
421:   aDistribution = INV_PI * aDistribution * aDistribution;
422:   return aDistribution;
423: }
424: 
425: #define THE_TO_BAKE_SPECULAR
426: THE_SHADER_IN vec3 ViewDirection; //!< direction of fetching from environment cubemap
427: 
428: #if (__VERSION__ >= 120)
429: uniform int uSamplesNum;     //!< number of samples in Monte-Carlo integration
430: #else
431: const int uSamplesNum = 256;
432: #endif
433: uniform samplerCube uEnvMap; //!< source of baking (environment cubemap)
434: 
435: #ifdef THE_TO_BAKE_DIFFUSE
436: uniform int uYCoeff; //!< coefficient of Y controlling horizontal flip of cubemap
437: uniform int uZCoeff; //!< coefficient of Z controlling vertical flip of cubemap
438: #endif
439: 
440: #ifdef THE_TO_BAKE_SPECULAR
441: uniform int   uCurrentLevel;        //!< current level of specular IBL map (ignored in case of diffuse map's processing)
442: uniform float uEnvSolidAngleSource; //!< source solid angle sample computed from one edge's size of source environment map's zero mipmap level
443: #endif
444: 
445: //! Returns coordinates of point theNumber from Hammersley point set having size theSize.
446: vec2 hammersley (in int theNumber,
447:                  in int theSize)
448: {
449:   int aDenominator = 2;
450:   int aNumber = theNumber;
451:   float aVanDerCorput = 0.0;
452:   for (int i = 0; i < 32; ++i)
453:   {
454:     if (aNumber > 0)
455:     {
456:       aVanDerCorput += mod(float(aNumber), 2.0) / float(aDenominator);
457:       aNumber /= 2;
458:       aDenominator *= 2;
459:     }
460:   }
461:   return vec2(float(theNumber) / float(theSize), aVanDerCorput);
462: }
463: 
464: //! This function does importance sampling on hemisphere surface using GGX normal distribution function
465: //! in tangent space (positive z axis is surface normal direction).
466: vec3 importanceSample (in vec2  theHammersleyPoint,
467:                        in float theRoughness)
468: {
469:   float aPhi = PI_2 * theHammersleyPoint.x;
470:   theRoughness *= theRoughness;
471:   theRoughness *= theRoughness;
472:   float aCosTheta = sqrt((1.0 - theHammersleyPoint.y) / (1.0 + (theRoughness - 1.0) * theHammersleyPoint.y));
473:   float aSinTheta = sqrt(1.0 - aCosTheta * aCosTheta);
474:   return vec3(aSinTheta * cos(aPhi),
475:               aSinTheta * sin(aPhi),
476:               aCosTheta);
477: }
478: 
479: //! This function uniformly generates samples on whole sphere.
480: vec3 sphereUniformSample (in vec2 theHammersleyPoint)
481: {
482:   float aPhi = PI_2 * theHammersleyPoint.x;
483:   float aCosTheta = 2.0 * theHammersleyPoint.y - 1.0;
484:   float aSinTheta = sqrt(1.0 - aCosTheta * aCosTheta);
485:   return vec3(aSinTheta * cos(aPhi),
486:               aSinTheta * sin(aPhi),
487:               aCosTheta);
488: }
489: 
490: //! Transforms resulted sampled direction from tangent space to world space considering the surface normal.
491: vec3 fromTangentSpace (in vec3 theVector,
492:                        in vec3 theNormal)
493: {
494:   vec3 anUp = (abs(theNormal.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
495:   vec3 anX = normalize(cross(anUp, theNormal));
496:   vec3 anY = cross(theNormal, anX);
497:   return anX * theVector.x + anY * theVector.y + theNormal * theVector.z;
498: }
499: 
500: #ifdef THE_TO_BAKE_DIFFUSE
501: #if (__VERSION__ >= 120)
502: const float aSHBasisFuncCoeffs[9] = float[9]
503: (
504:   0.282095 * 0.282095,
505:   0.488603 * 0.488603,
506:   0.488603 * 0.488603,
507:   0.488603 * 0.488603,
508:   1.092548 * 1.092548,
509:   1.092548 * 1.092548,
510:   1.092548 * 1.092548,
511:   0.315392 * 0.315392,
512:   0.546274 * 0.546274
513: );
514: const float aSHCosCoeffs[9] = float[9]
515: (
516:   3.141593,
517:   2.094395,
518:   2.094395,
519:   2.094395,
520:   0.785398,
521:   0.785398,
522:   0.785398,
523:   0.785398,
524:   0.785398
525: );
526: #else
527: uniform float aSHBasisFuncCoeffs[9];
528: uniform float aSHCosCoeffs[9];
529: #endif
530: 
531: //! Bakes diffuse IBL map's spherical harmonics coefficients.
532: vec3 bakeDiffuseSH()
533: {
534:   int anId = int(gl_FragCoord.x);
535:   float aCoef;
536: #if (__VERSION__ >= 120)
537:   aCoef = aSHCosCoeffs[anId] * aSHBasisFuncCoeffs[anId];
538: #else
539:   if      (anId == 0) { aCoef = aSHCosCoeffs[0] * aSHBasisFuncCoeffs[0]; }
540:   else if (anId == 1) { aCoef = aSHCosCoeffs[1] * aSHBasisFuncCoeffs[1]; }
541:   else if (anId == 2) { aCoef = aSHCosCoeffs[2] * aSHBasisFuncCoeffs[2]; }
542:   else if (anId == 3) { aCoef = aSHCosCoeffs[3] * aSHBasisFuncCoeffs[3]; }
543:   else if (anId == 4) { aCoef = aSHCosCoeffs[4] * aSHBasisFuncCoeffs[4]; }
544:   else if (anId == 5) { aCoef = aSHCosCoeffs[5] * aSHBasisFuncCoeffs[5]; }
545:   else if (anId == 6) { aCoef = aSHCosCoeffs[6] * aSHBasisFuncCoeffs[6]; }
546:   else if (anId == 7) { aCoef = aSHCosCoeffs[7] * aSHBasisFuncCoeffs[7]; }
547:   else                { aCoef = aSHCosCoeffs[8] * aSHBasisFuncCoeffs[8]; }
548: #endif
549:   vec3 aRes = vec3 (0.0);
550:   for (int aSampleIter = 0; aSampleIter < uSamplesNum; ++aSampleIter)
551:   {
552:     vec2 aHammersleyPoint = hammersley (aSampleIter, uSamplesNum);
553:     vec3 aDir = sphereUniformSample (aHammersleyPoint);
554: 
555:     vec3 aVal = occTextureCube (uEnvMap, cubemapVectorTransform (aDir, uYCoeff, uZCoeff)).rgb;
556:   #if (__VERSION__ >= 120)
557:     float aFunc[9];
558:     aFunc[0] = 1.0;
559: 
560:     aFunc[1] = aDir.x;
561:     aFunc[2] = aDir.y;
562:     aFunc[3] = aDir.z;
563: 
564:     aFunc[4] = aDir.x * aDir.z;
565:     aFunc[5] = aDir.y * aDir.z;
566:     aFunc[6] = aDir.x * aDir.y;
567: 
568:     aFunc[7] = 3.0 * aDir.z * aDir.z - 1.0;
569:     aFunc[8] = aDir.x * aDir.x - aDir.y * aDir.y;
570: 
571:     aRes += aVal * aFunc[anId];
572:   #else
573:     if      (anId == 0) { aRes += aVal * 1.0; }
574:     else if (anId == 1) { aRes += aVal * aDir.x; }
575:     else if (anId == 2) { aRes += aVal * aDir.y; }
576:     else if (anId == 3) { aRes += aVal * aDir.z; }
577:     else if (anId == 4) { aRes += aVal * (aDir.x * aDir.z); }
578:     else if (anId == 5) { aRes += aVal * (aDir.y * aDir.z); }
579:     else if (anId == 6) { aRes += aVal * (aDir.x * aDir.y); }
580:     else if (anId == 7) { aRes += aVal * (3.0 * aDir.z * aDir.z - 1.0); }
581:     else                { aRes += aVal * (aDir.x * aDir.x - aDir.y * aDir.y); }
582:   #endif
583:   }
584: 
585:   return 4.0 * aRes * aCoef / float(uSamplesNum);
586: }
587: #endif
588: 
589: #ifdef THE_TO_BAKE_SPECULAR
590: //! Computes a single sample for specular IBL map.
591: vec4 specularMapSample (in vec3  theNormal,
592:                         in float theRoughness,
593:                         in int   theNumber,
594:                         in int   theSize)
595: {
596:   vec2 aHammersleyPoint = hammersley (theNumber, theSize);
597:   vec3 aHalf = importanceSample (aHammersleyPoint, occRoughness (theRoughness));
598:   float aHdotV = aHalf.z;
599:   aHalf = fromTangentSpace (aHalf, theNormal);
600:   vec3  aLight = -reflect (theNormal, aHalf);
601:   float aNdotL = dot (aLight, theNormal);
602:   if (aNdotL > 0.0)
603:   {
604:     float aSolidAngleSample = 1.0 / (float(theSize) * (occPBRDistribution (aHdotV, theRoughness) * 0.25 + 0.0001) + 0.0001);
605:     float aLod = (theRoughness == 0.0) ? 0.0 : 0.5 * log2 (aSolidAngleSample / uEnvSolidAngleSource);
606:     return vec4 (occTextureCubeLod (uEnvMap, aLight, aLod).rgb * aNdotL, aNdotL);
607:   }
608:   return vec4 (0.0);
609: }
610: 
611: //! Bakes specular IBL map.
612: vec3 bakeSpecularMap (in vec3  theNormal,
613:                       in float theRoughness)
614: {
615:   vec4 aResult = vec4(0.0);
616:   if (theRoughness == 0.0)
617:   {
618:     aResult = specularMapSample (theNormal, theRoughness, 0, 1);
619:   }
620:   else
621:   {
622:     for (int aSampleIter = 0; aSampleIter < uSamplesNum; ++aSampleIter)
623:     {
624:       aResult += specularMapSample (theNormal, theRoughness, aSampleIter, uSamplesNum);
625:     }
626:   }
627:   return aResult.xyz / aResult.w;
628: }
629: #endif
630: 
631: void main()
632: {
633:   vec3 aViewDirection = normalize (ViewDirection);
634: #ifdef THE_TO_BAKE_DIFFUSE
635:   vec4 aRes = vec4 (bakeDiffuseSH(), 1.0);
636: #ifdef THE_TO_PACK_FLOAT
637:   int aCompIndex = int(gl_FragCoord.y);
638:   float aComp = aCompIndex == 0 ? aRes.x : (aCompIndex == 1 ? aRes.y : aRes.z);
639:   int aFixedPrec = int(aComp * 2147483647.0);
640:   int aFixedDiv1 = aFixedPrec / 256;
641:   int aFixedDiv2 = aFixedDiv1 / 256;
642:   int aFixedDiv3 = aFixedDiv2 / 256;
643:   vec4 aPacked = vec4(float(aFixedPrec), float(aFixedDiv1), float(aFixedDiv2), float(aFixedDiv3));
644:   aRes = fract (aPacked * (1.0 / 256.0));
645: #endif
646:   occFragColor = aRes;
647: #else
648:   float aRoughness = float(uCurrentLevel) / float(occNbSpecIBLLevels - 1);
649:   occFragColor = vec4 (bakeSpecularMap (aViewDirection, aRoughness), 1.0);
650: #endif
651: }
TKOpenGl | Type: Error | ID: 0 | Severity: High | Message:
  Failed to compile Fragment Shader [occt_pbr_env_baking_specular0000]. Compilation log:
0:606(15): error: no function with name 'textureCubeLod'
0:606(15): error: type mismatch
0:606(15): error: operands to arithmetic operators must be numeric
0:606(9): error: cannot construct `vec4' from a non-numeric data type
0:606(2): error: `return' with wrong type error, in function `specularMapSample' returning vec4

TKOpenGl | Type: Performance | ID: 0 | Severity: High | Message:
  Error: baking PBR environment 512x512 takes too much time!.
TKOpenGl | Type: Portability | ID: 0 | Severity: Low | Message:
  Fragment Shader [occt_phong-pbr-l_d-0000] compilation log:
0:575(2): warning: `BaseColor' used uninitialized
0:575(13): warning: `Metallic' used uninitialized
0:575(23): warning: `Roughness' used uninitialized
0:575(34): warning: `IOR' used uninitialized
0:610(58): warning: `Normal' used uninitialized

vlight headlight -enabled 0 
TKOpenGl | Type: Portability | ID: 0 | Severity: Low | Message:
  Fragment Shader [occt_phong-pbr-l_-0000] compilation log:
0:589(58): warning: `Normal' used uninitialized
Steps To Reproduce
test opengl background skydome
TagsNo tags attached.
Test case numberN/A

Relationships

child of 0030700 closedapn Visualization, TKOpenGl - support PBR Metallic-Roughness shading model 

Activities

git

2022-07-22 10:55

administrator   ~0109937

Branch CR33074 has been created by kgv.

SHA-1: e22a231f876249110a7c1294dacc7bce10db6d4f


Detailed log of new commits:

Author: kgv
Date: Fri Jul 22 10:55:28 2022 +0300

    0033074: Visualization, TKOpenGl - PBR shader compilation error on Mesa OpenGL 3.10033074
    
    Graphic3d_ShaderManager::getPBREnvBakingProgram() - fix setting Graphic3d_ShaderProgram::SetPBR()
    before defining GLSL version via defaultGlslVersion() that relies on this property.

kgv

2022-07-22 12:37

developer   ~0109940

Please raise the patch
- OCCT: branch CR33074.

http://jenkins-test-occt.nnov.opencascade.com/view/CR33074-master-KGV/

smoskvin

2022-07-23 14:12

administrator   ~0109961

Combination -
OCCT branch : IR-2022-07-22
master SHA - changes and them, and you can discard any commits you make in this
cb8519be19a3533b741f016d703119320de72ea6
changes and them, and you can discard any commits you make in this
e0ceb716c70188b98130b1550914140d0502a6f9
Products branch : IR-2022-07-22 SHA - 7d10377b57d1c1ddf69852bf5b4e764f581c282f
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 18704.32000000071 / 18688.950000000597 [+0.08%]
Products
Total CPU difference: 11922.590000000118 / 11921.05000000012 [+0.01%]
Windows-64-VC14:
OCCT
Total CPU difference: 20723.546875 / 20746.84375 [-0.11%]
Products
Total CPU difference: 13486.40625 / 13479.375 [+0.05%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention

git

2022-07-23 15:38

administrator   ~0109969

Branch CR33074 has been deleted by mnt.

SHA-1: e22a231f876249110a7c1294dacc7bce10db6d4f

Related Changesets

occt: master cb8519be

2022-07-22 10:55:28

kgv


Committer: smoskvin Details Diff
0033074: Visualization, TKOpenGl - PBR shader compilation error on Mesa OpenGL 3.10033074

Graphic3d_ShaderManager::getPBREnvBakingProgram() - fix setting Graphic3d_ShaderProgram::SetPBR()
before defining GLSL version via defaultGlslVersion() that relies on this property.
Affected Issues
0033074
mod - src/Graphic3d/Graphic3d_ShaderManager.cxx Diff File

Issue History

Date Modified Username Field Change
2022-07-22 10:52 kgv New Issue
2022-07-22 10:52 kgv Assigned To => kgv
2022-07-22 10:53 kgv Description Updated
2022-07-22 10:55 git Note Added: 0109937
2022-07-22 10:59 kgv Relationship added child of 0030700
2022-07-22 10:59 kgv Product Version 7.6.0 => 7.5.0
2022-07-22 10:59 kgv Target Version 7.7.0 => 7.6.3
2022-07-22 10:59 kgv Test case number => N/A
2022-07-22 12:37 kgv Assigned To kgv => bugmaster
2022-07-22 12:37 kgv Status new => resolved
2022-07-22 12:37 kgv Note Added: 0109940
2022-07-22 12:37 kgv Status resolved => reviewed
2022-07-23 14:12 smoskvin Status reviewed => tested
2022-07-23 14:12 smoskvin Note Added: 0109961
2022-07-23 15:29 smoskvin Changeset attached => occt master cb8519be
2022-07-23 15:29 kgv Assigned To bugmaster => kgv
2022-07-23 15:29 kgv Status tested => verified
2022-07-23 15:29 kgv Resolution open => fixed
2022-07-23 15:38 git Note Added: 0109969
2022-10-19 15:50 smoskvin Assigned To kgv => vpozdyayev
2023-03-19 20:44 vglukhik Status verified => closed
2023-03-19 20:44 vglukhik Fixed in Version => 7.7.0