1 // This file has been automatically generated from resource file src/Shaders/DeclarationsImpl.glsl
3 static const char Shaders_DeclarationsImpl_glsl[] =
5 "//! @file DeclarationsImpl.glsl includes implementation of common functions and properties accessors\n"
6 "#if defined(FRAGMENT_SHADER)\n"
8 "#if defined(OCC_DEPTH_PEEL_OIT)\n"
9 "uniform sampler2D occDepthPeelingDepth;\n"
10 "uniform sampler2D occDepthPeelingFrontColor;\n"
11 "int IsFrontPeelLayer = -1;\n"
12 "bool occFragEarlyReturn()\n"
14 " #define THE_DEPTH_CLEAR_VALUE -1e15f\n"
15 " ivec2 aFragCoord = ivec2 (gl_FragCoord.xy);\n"
16 " vec2 aLastDepth = texelFetch (occDepthPeelingDepth, aFragCoord, 0).rg;\n"
17 " occPeelFrontColor = texelFetch (occDepthPeelingFrontColor, aFragCoord, 0);\n"
18 " occPeelDepth.rg = vec2 (THE_DEPTH_CLEAR_VALUE); // depth value always increases, so that MAX blend equation can be used\n"
19 " occPeelBackColor = vec4 (0.0); // back color is blend after each peeling pass\n"
21 " float aNearDepth = -aLastDepth.x;\n"
22 " float aFarDepth = aLastDepth.y;\n"
23 " float aFragDepth = gl_FragCoord.z; // 0 - 1\n"
24 " if (aFragDepth < aNearDepth || aFragDepth > aFarDepth)\n"
26 " return true; // skip peeled depth\n"
28 " else if (aFragDepth > aNearDepth && aFragDepth < aFarDepth)\n"
30 " // to be rendered at next peeling pass\n"
31 " occPeelDepth.rg = vec2 (-aFragDepth, aFragDepth);\n"
35 " IsFrontPeelLayer = (gl_FragCoord.z == aNearDepth) ? 1 : 0;\n"
39 "bool occFragEarlyReturn() { return false; }\n"
42 "void occSetFragColor (in vec4 theColor)\n"
44 "#if defined(OCC_ALPHA_TEST)\n"
45 " if (theColor.a < occAlphaCutoff) discard;\n"
47 "#if defined(OCC_WRITE_WEIGHT_OIT_COVERAGE)\n"
48 " float aWeight = theColor.a * clamp (1e+2 * pow (1.0 - gl_FragCoord.z * occOitDepthFactor, 3.0), 1e-2, 1e+2);\n"
49 " occFragCoverage.r = theColor.a * aWeight;\n"
50 " occFragColor = vec4 (theColor.rgb * theColor.a * aWeight, theColor.a);\n"
51 "#elif defined(OCC_DEPTH_PEEL_OIT)\n"
52 " if (IsFrontPeelLayer == 1) // front is blended directly\n"
54 " vec4 aLastColor = occPeelFrontColor;\n"
55 " float anAlphaMult = 1.0 - aLastColor.a;\n"
56 " occPeelFrontColor.rgb = aLastColor.rgb + theColor.rgb * theColor.a * anAlphaMult;\n"
57 " occPeelFrontColor.a = 1.0 - anAlphaMult * (1.0 - theColor.a);\n"
59 " else if (IsFrontPeelLayer == 0) // back is blended afterwards\n"
61 " occPeelBackColor = theColor;\n"
64 " occFragColor = theColor;\n"
69 "#if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)\n"
70 "// arrays of light sources\n"
71 "uniform vec4 occLightSources[THE_MAX_LIGHTS * 4]; //!< packed light sources parameters\n"
72 "uniform THE_PREC_ENUM int occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types\n"
75 "#if defined(THE_IS_PBR)\n"
76 "vec3 occDiffIBLMap (in vec3 theNormal)\n"
78 " vec3 aSHCoeffs[9];\n"
79 " for (int i = 0; i < 9; ++i)\n"
81 " aSHCoeffs[i] = occTexture2D (occDiffIBLMapSHCoeffs, vec2 ((float(i) + 0.5) / 9.0, 0.0)).rgb;\n"
83 " return aSHCoeffs[0]\n"
85 " + aSHCoeffs[1] * theNormal.x\n"
86 " + aSHCoeffs[2] * theNormal.y\n"
87 " + aSHCoeffs[3] * theNormal.z\n"
89 " + aSHCoeffs[4] * theNormal.x * theNormal.z\n"
90 " + aSHCoeffs[5] * theNormal.y * theNormal.z\n"
91 " + aSHCoeffs[6] * theNormal.x * theNormal.y\n"
93 " + aSHCoeffs[7] * (3.0 * theNormal.z * theNormal.z - 1.0)\n"
94 " + aSHCoeffs[8] * (theNormal.x * theNormal.x - theNormal.y * theNormal.y);\n"
98 "// front and back material properties accessors\n"
99 "#if defined(THE_IS_PBR)\n"
100 "uniform vec4 occPbrMaterial[3 * 2];\n"
102 "#define MIN_ROUGHNESS 0.01\n"
103 "float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }\n"
104 "vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrMaterial[0] : occPbrMaterial[3]; }\n"
105 "vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].rgb : occPbrMaterial[4].rgb; }\n"
106 "float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].w : occPbrMaterial[4].w; }\n"
107 "float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].b : occPbrMaterial[5].b; }\n"
108 "float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].g : occPbrMaterial[5].g; }\n"
110 "uniform vec4 occCommonMaterial[4 * 2];\n"
112 "vec4 occMaterial_Diffuse(in bool theIsFront) { return theIsFront ? occCommonMaterial[0] : occCommonMaterial[4]; }\n"
113 "vec3 occMaterial_Emission(in bool theIsFront) { return theIsFront ? occCommonMaterial[1].rgb : occCommonMaterial[5].rgb; }\n"
114 "vec3 occMaterial_Specular(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].rgb : occCommonMaterial[6].rgb; }\n"
115 "float occMaterial_Shininess(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].a : occCommonMaterial[6].a; }\n"
116 "vec3 occMaterial_Ambient(in bool theIsFront) { return theIsFront ? occCommonMaterial[3].rgb : occCommonMaterial[7].rgb; }\n"
119 "// 2D texture coordinates transformation\n"
120 "vec2 occTextureTrsf_Translation(void) { return occTexTrsf2d[0].xy; }\n"
121 "vec2 occTextureTrsf_Scale(void) { return occTexTrsf2d[0].zw; }\n"
122 "float occTextureTrsf_RotationSin(void) { return occTexTrsf2d[1].x; }\n"
123 "float occTextureTrsf_RotationCos(void) { return occTexTrsf2d[1].y; }\n"
124 "//! @endfile DeclarationsImpl.glsl\n";