/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{clamp as a}from"../../../../../../core/mathUtils.js";import{VertexNormal as e}from"../attributes/VertexNormal.glsl.js";import{VertexPosition as r}from"../attributes/VertexPosition.glsl.js";import{FloatBindUniform as o}from"../../shaderModules/FloatBindUniform.js";import{glsl as d,If as i}from"../../shaderModules/glsl.js";function l(l,n){const m=l.fragment;switch(n.doubleSidedMode){case 0:m.code.add(d`vec3 _adjustDoublesided(vec3 normal) {
return normal;
}`);break;case 1:l.include(r,n),m.code.add(d`vec3 _adjustDoublesided(vec3 normal) {
return dot(normal, vPositionWorldCameraRelative) > 0.0 ? -normal : normal;
}`);break;case 2:m.code.add(d`vec3 _adjustDoublesided(vec3 normal) {
return gl_FrontFacing ? normal : -normal;
}`);break;default:n.doubleSidedMode;case 3:}switch(n.normalType){case 0:case 1:l.include(e,n),m.main.add(d`vec3 fragmentFaceNormal = _adjustDoublesided(normalize(vNormalWorld));
vec3 fragmentFaceNormalView = gl_FrontFacing ? normalize(vNormalView) : -normalize(vNormalView);`);break;case 2:l.include(r,n),m.main.add(d`vec3 fragmentFaceNormal = normalize(cross(dFdx(vPositionWorldCameraRelative), dFdy(vPositionWorldCameraRelative)));
vec3 fragmentFaceNormalView = normalize(cross(dFdx(vPosition_view), dFdy(vPosition_view)));`)}switch(n.shadeNormals){case 3:case 1:m.main.add(d`vec3 fragmentShadingNormal = fragmentFaceNormal;`);break;case 2:l.include(r,n),m.uniforms.add(new o("worldUpShading",e=>a(20*(e.lighting.noonFactor-.9),0,1))).main.add(d`
            vec3 fragmentShadingNormal = fragmentFaceNormal;
            if (worldUpShading > 0.0){
              vec3 worldUpNormal = ${i(n.spherical,"normalize(positionWorld())","vec3(0.0, 0.0, 1.0)")};
              fragmentShadingNormal = mix(fragmentShadingNormal, worldUpNormal, worldUpShading);
            }
          `);break;case 0:n.spherical?(l.include(r,n),m.main.add(d`vec3 fragmentShadingNormal = normalize(positionWorld());`)):m.main.add(d`vec3 fragmentShadingNormal = vec3(0.0, 0.0, 1.0);`);break;default:n.shadeNormals}}export{l as computeFragmentNormals};
