Repository: playcanvas/engine
File: src/scene/materials/standard-material-options-builder.js (JavaScript)

Code before:
                             notWhite(stdMat.specular);

        const specularityFactorTint = useSpecular && stdMat.useMetalnessSpecularColor &&
                                      (stdMat.specularityFactorTint || (stdMat.specularityFactor < 1 && !stdMat.specularityFactorMap));

        const isPackedNormalMap = stdMat.normalMap ? (stdMat.normalMap.format === PIXELFORMAT_DXT5 || stdMat.normalMap.type === TEXTURETYPE_SWIZZLEGGGR) : false;

        const equalish = (a, b) => Math.abs(a - b) < 1e-4;

        options.specularTint = specularTint;
        options.specularityFactorTint = specularityFactorTint;
        options.metalnessTint = (stdMat.useMetalness && stdMat.metalness < 1);
        options.glossTint = true;
        options.diffuseEncoding = stdMat.diffuseMap?.encoding;
        options.diffuseDetailEncoding = stdMat.diffuseDetailMap?.encoding;
        options.emissiveEncoding = stdMat.emissiveMap?.encoding;
        options.lightMapEncoding = stdMat.lightMap?.encoding;
        options.packedNormal = isPackedNormalMap;
        options.refractionTint = equalish(stdMat.refraction, 1.0);
        options.refractionIndexTint = equalish(stdMat.refractionIndex, 1.0 / 1.5);
        options.thicknessTint = (stdMat.useDynamicRefraction && stdMat.thickness !== 1.0);
        options.specularEncoding = stdMat.specularEncoding || 'linear';
        options.sheenEncoding = stdMat.sheenEncoding || 'linear';
        options.aoMapUv = stdMat.aoUvSet; // backwards compatibility
        options.aoDetail = !!stdMat.aoMap;
        options.diffuseDetail = !!stdMat.diffuseMap;
        options.normalDetail = !!stdMat.normalMap;
        options.diffuseDetailMode = stdMat.diffuseDetailMode;
        options.aoDetailMode = stdMat.aoDetailMode;
        options.clearCoatTint = equalish(stdMat.clearCoat, 1.0);
        options.clearCoatGloss = !!stdMat.clearCoatGloss;
        options.clearCoatGlossTint = (stdMat.clearCoatGloss !== 1.0);
        options.iorTint = equalish(stdMat.refractionIndex, 1.0 / 1.5);

        options.iridescenceTint = stdMat.iridescence !== 1.0;

        options.glossInvert = stdMat.glossInvert;
        options.sheenGlossInvert = stdMat.sheenGlossInvert;
        options.clearCoatGlossInvert = stdMat.clearCoatGlossInvert;

        options.useSpecularColor = useSpecularColor;

        // LIT OPTIONS
        options.litOptions.separateAmbient = false;    // store ambient light color in separate variable, instead of adding it to diffuse directly
        options.litOptions.customFragmentShader = stdMat.customFragmentShader;
        options.litOptions.pixelSnap = stdMat.pixelSnap;

        options.litOptions.ambientSH = !!stdMat.ambientSH;
        options.litOptions.twoSidedLighting = stdMat.twoSidedLighting;
        options.litOptions.occludeSpecular = stdMat.occludeSpecular;
        options.litOptions.occludeSpecularFloat = (stdMat.occludeSpecularIntensity !== 1.0);

Review comment (suggestion):
This looks incongruous with the surrounding lines. I'd expect this to be `!!stdMap.diffuseMap` based on the other lines.

Code after:
                             notWhite(stdMat.specular);

        const specularityFactorTint = useSpecular && stdMat.useMetalnessSpecularColor &&
                                      (stdMat.specularityFactorTint || (stdMat.specularityFactor < 1 && !stdMat.specularityFactorMap));

        const isPackedNormalMap = stdMat.normalMap ? (stdMat.normalMap.format === PIXELFORMAT_DXT5 || stdMat.normalMap.type === TEXTURETYPE_SWIZZLEGGGR) : false;

        const equalish = (a, b) => Math.abs(a - b) < 1e-4;

        options.specularTint = specularTint;
        options.specularityFactorTint = specularityFactorTint;
        options.metalnessTint = (stdMat.useMetalness && stdMat.metalness < 1);
        options.glossTint = true;
        options.diffuseEncoding = stdMat.diffuseMap?.encoding;
        options.diffuseDetailEncoding = stdMat.diffuseDetailMap?.encoding;
        options.emissiveEncoding = stdMat.emissiveMap?.encoding;
        options.lightMapEncoding = stdMat.lightMap?.encoding;
        options.packedNormal = isPackedNormalMap;
        options.refractionTint = equalish(stdMat.refraction, 1.0);
        options.refractionIndexTint = equalish(stdMat.refractionIndex, 1.0 / 1.5);
        options.thicknessTint = (stdMat.useDynamicRefraction && stdMat.thickness !== 1.0);
        options.specularEncoding = stdMat.specularEncoding || 'linear';
        options.sheenEncoding = stdMat.sheenEncoding || 'linear';
        options.aoMapUv = stdMat.aoUvSet; // backwards compatibility
        options.aoDetail = !!stdMat.aoMap;
        options.diffuseDetail = !!stdMat.diffuseDetailMap;
        options.normalDetail = !!stdMat.normalMap;
        options.diffuseDetailMode = stdMat.diffuseDetailMode;
        options.aoDetailMode = stdMat.aoDetailMode;
        options.clearCoatTint = equalish(stdMat.clearCoat, 1.0);
        options.clearCoatGloss = !!stdMat.clearCoatGloss;
        options.clearCoatGlossTint = (stdMat.clearCoatGloss !== 1.0);
        options.iorTint = equalish(stdMat.refractionIndex, 1.0 / 1.5);

        options.iridescenceTint = stdMat.iridescence !== 1.0;

        options.glossInvert = stdMat.glossInvert;
        options.sheenGlossInvert = stdMat.sheenGlossInvert;
        options.clearCoatGlossInvert = stdMat.clearCoatGlossInvert;

        options.useSpecularColor = useSpecularColor;

        // LIT OPTIONS
        options.litOptions.separateAmbient = false;    // store ambient light color in separate variable, instead of adding it to diffuse directly
        options.litOptions.customFragmentShader = stdMat.customFragmentShader;
        options.litOptions.pixelSnap = stdMat.pixelSnap;

        options.litOptions.ambientSH = !!stdMat.ambientSH;
        options.litOptions.twoSidedLighting = stdMat.twoSidedLighting;
        options.litOptions.occludeSpecular = stdMat.occludeSpecular;
        options.litOptions.occludeSpecularFloat = (stdMat.occludeSpecularIntensity !== 1.0);