/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{VertexTextureCoordinates as e}from"../attributes/VertexTextureCoordinates.glsl.js";import{Float3DrawUniform as o}from"../../shaderModules/Float3DrawUniform.js";import{Float3PassUniform as r}from"../../shaderModules/Float3PassUniform.js";import{glsl as s,If as t}from"../../shaderModules/glsl.js";import{Texture2DDrawUniform as c}from"../../shaderModules/Texture2DDrawUniform.js";import{Texture2DPassUniform as l}from"../../shaderModules/Texture2DPassUniform.js";import{schematicMRRFactors as u}from"../../../materials/pbrUtils.js";import{NoParameters as a}from"../../../../../webgl/NoParameters.js";class i extends a{constructor(e,o){super(),this.textureOcclusion=e,this.textureMetallicRoughness=o,this.mrrFactors=u}}function n(u,a){const i=a.pbrMode,n=u.fragment;if(2!==i&&0!==i&&1!==i)return void n.code.add(s`void applyPBRFactors() {}`);if(0===i)return void n.code.add(s`void applyPBRFactors() {}
float getBakedOcclusion() { return 1.0; }`);if(2===i)return void n.code.add(s`vec3 mrr = vec3(0.0, 0.6, 0.2);
float occlusion = 1.0;
void applyPBRFactors() {}
float getBakedOcclusion() { return 1.0; }`);const{hasMetallicRoughnessTexture:d,hasMetallicRoughnessTextureTransform:m,hasOcclusionTexture:p,hasOcclusionTextureTransform:f,bindType:h}=a;(d||p)&&u.include(e,a),n.code.add(s`vec3 mrr;
float occlusion;`),d&&n.uniforms.add(1===h?new l("texMetallicRoughness",e=>e.textureMetallicRoughness):new c("texMetallicRoughness",e=>e.textureMetallicRoughness)),p&&n.uniforms.add(1===h?new l("texOcclusion",e=>e.textureOcclusion):new c("texOcclusion",e=>e.textureOcclusion)),n.uniforms.add(1===h?new r("mrrFactors",e=>e.mrrFactors):new o("mrrFactors",e=>e.mrrFactors)),n.code.add(s`
    ${t(d,s`void applyMetallicRoughness(vec2 uv) {
            vec3 metallicRoughness = textureLookup(texMetallicRoughness, uv).rgb;
            mrr[0] *= metallicRoughness.b;
            mrr[1] *= metallicRoughness.g;
          }`)}

    ${t(p,"void applyOcclusion(vec2 uv) { occlusion *= textureLookup(texOcclusion, uv).r; }")}

    float getBakedOcclusion() {
      return ${p?"occlusion":"1.0"};
    }

    void applyPBRFactors() {
      mrr = mrrFactors;
      occlusion = 1.0;

      ${t(d,`applyMetallicRoughness(${m?"metallicRoughnessUV":"vuv0"});`)}
      ${t(p,`applyOcclusion(${f?"occlusionUV":"vuv0"});`)}
    }
  `)}export{i as PBRRenderingParameters,n as PhysicallyBasedRenderingParameters};
