diff --git a/Source/Scene/processModelMaterialsCommon.js b/Source/Scene/processModelMaterialsCommon.js index a52836c720d4..ac94c8b8aa92 100644 --- a/Source/Scene/processModelMaterialsCommon.js +++ b/Source/Scene/processModelMaterialsCommon.js @@ -643,7 +643,7 @@ function generateTechnique( fragmentShader += " vec3 normal = normalize(v_normal);\n"; if (khrMaterialsCommon.doubleSided) { // !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494. - fragmentShader += " if (gl_FrontFacing == false)\n"; + fragmentShader += " if (czm_backFacing())\n"; fragmentShader += " {\n"; fragmentShader += " normal = -normal;\n"; fragmentShader += " }\n"; diff --git a/Source/Scene/processPbrMaterials.js b/Source/Scene/processPbrMaterials.js index b40e6ed50e99..a4b5027269a2 100644 --- a/Source/Scene/processPbrMaterials.js +++ b/Source/Scene/processPbrMaterials.js @@ -768,7 +768,7 @@ function generateTechnique( } if (material.doubleSided) { // !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494. - fragmentShader += " if (gl_FrontFacing == false)\n"; + fragmentShader += " if (czm_backFacing())\n"; fragmentShader += " {\n"; fragmentShader += " n = -n;\n"; fragmentShader += " }\n"; diff --git a/Source/Shaders/Builtin/Functions/backFacing.glsl b/Source/Shaders/Builtin/Functions/backFacing.glsl new file mode 100644 index 000000000000..701244a81546 --- /dev/null +++ b/Source/Shaders/Builtin/Functions/backFacing.glsl @@ -0,0 +1,13 @@ +/** + * Determines if the fragment is back facing + * + * @name czm_backFacing + * @glslFunction + * + * @returns {bool} true if the fragment is back facing; otherwise, false. + */ +bool czm_backFacing() +{ + // !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494. + return gl_FrontFacing == false; +} diff --git a/Source/Shaders/GlobeFS.glsl b/Source/Shaders/GlobeFS.glsl index 2bcee67763f4..b19a94bfd32b 100644 --- a/Source/Shaders/GlobeFS.glsl +++ b/Source/Shaders/GlobeFS.glsl @@ -453,8 +453,7 @@ void main() #endif #ifdef UNDERGROUND_COLOR - // !gl_FrontFacing doesn't work as expected on Mac/Intel so use the more verbose form instead. See https://github.com/CesiumGS/cesium/pull/8494. - if (gl_FrontFacing == false) + if (czm_backFacing()) { float distanceFromEllipsoid = max(czm_cameraHeight, 0.0); float distance = max(v_distance - distanceFromEllipsoid, 0.0);