/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{VertexNormal as e}from"../attributes/VertexNormal.glsl.js";import{VertexPosition as a}from"../attributes/VertexPosition.glsl.js";import{glsl as o}from"../../shaderModules/glsl.js";function r(r,d){const i=r.fragment;switch(d.doubleSidedMode){case 0:i.code.add(o`vec3 _adjustDoublesided(vec3 normal) {
return normal;
}`);break;case 1:r.include(a,d),i.code.add(o`vec3 _adjustDoublesided(vec3 normal) {
return dot(normal, vPositionWorldCameraRelative) > 0.0 ? -normal : normal;
}`);break;case 2:i.code.add(o`vec3 _adjustDoublesided(vec3 normal) {
return gl_FrontFacing ? normal : -normal;
}`);break;default:d.doubleSidedMode;case 3:}switch(d.normalType){case 0:case 1:r.include(e,d),i.main.add(o`vec3 fragmentFaceNormal = _adjustDoublesided(normalize(vNormalWorld));
vec3 fragmentFaceNormalView = gl_FrontFacing ? normalize(vNormalView) : -normalize(vNormalView);`);break;case 2:r.include(a,d),i.main.add(o`vec3 fragmentFaceNormal = normalize(cross(dFdx(vPositionWorldCameraRelative), dFdy(vPositionWorldCameraRelative)));
vec3 fragmentFaceNormalView = normalize(cross(dFdx(vPosition_view), dFdy(vPosition_view)));`)}d.shadeNormals?i.main.add(o`vec3 fragmentShadingNormal = fragmentFaceNormal;`):d.spherical?(r.include(a,d),i.main.add(o`vec3 fragmentShadingNormal = normalize(positionWorld());`)):i.main.add(o`vec3 fragmentShadingNormal = vec3(0.0, 0.0, 1.0);`)}export{r as computeFragmentNormals};
