/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{neverReached as e}from"../../../../../../core/compilerUtils.js";import{VertexNormal as a}from"../attributes/VertexNormal.glsl.js";import{VertexPosition as o}from"../attributes/VertexPosition.glsl.js";import{glsl as r}from"../../shaderModules/glsl.js";function d(d,i){const l=d.fragment;switch(i.doubleSidedMode){case 0:l.code.add(r`vec3 _adjustDoublesided(vec3 normal) {
return normal;
}`);break;case 1:d.include(o,i),l.code.add(r`vec3 _adjustDoublesided(vec3 normal) {
return dot(normal, vPositionWorldCameraRelative) > 0.0 ? -normal : normal;
}`);break;case 2:l.code.add(r`vec3 _adjustDoublesided(vec3 normal) {
return gl_FrontFacing ? normal : -normal;
}`);break;default:e(i.doubleSidedMode);case 3:}switch(i.normalType){case 0:case 1:d.include(a,i),l.main.add(r`vec3 fragmentFaceNormal = _adjustDoublesided(normalize(vNormalWorld));
vec3 fragmentFaceNormalView = gl_FrontFacing ? normalize(vNormalView) : -normalize(vNormalView);`);break;case 2:d.include(o,i),l.main.add(r`vec3 fragmentFaceNormal = normalize(cross(dFdx(vPositionWorldCameraRelative), dFdy(vPositionWorldCameraRelative)));
vec3 fragmentFaceNormalView = normalize(cross(dFdx(vPosition_view), dFdy(vPosition_view)));`)}i.shadeNormals?l.main.add(r`vec3 fragmentShadingNormal = fragmentFaceNormal;`):i.spherical?(d.include(o,i),l.main.add(r`vec3 fragmentShadingNormal = normalize(positionWorld());`)):l.main.add(r`vec3 fragmentShadingNormal = vec3(0.0, 0.0, 1.0);`)}export{d as computeFragmentNormals};
