Skip to content

Commit

Permalink
Add czm_backFacing
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 20, 2020
1 parent c73929d commit 225ed5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/Scene/processModelMaterialsCommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/processPbrMaterials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 13 additions & 0 deletions Source/Shaders/Builtin/Functions/backFacing.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Determines if the fragment is back facing
*
* @name czm_backFacing
* @glslFunction
*
* @returns {bool} <code>true</code> if the fragment is back facing; otherwise, <code>false</code>.
*/
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;
}
3 changes: 1 addition & 2 deletions Source/Shaders/GlobeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 225ed5d

Please sign in to comment.