Repository: playcanvas/engine
File: src/scene/shader-lib/programs/standard.js (JavaScript)

Code before:
        const transformPropName = `${mapPropName}Transform`;
        const channelPropName = `${mapPropName}Channel`;
        const vertexColorChannelPropName = `${propName}VertexColorChannel`;
        const tintPropName = `${propName}Tint`;
        const vertexColorPropName = `${propName}VertexColor`;
        const detailModePropName = `${propName}Mode`;
        const invertName = `${propName}Invert`;

        const tintOption = options[tintPropName];
        const vertexColorOption = options[vertexColorPropName];
        const textureOption = options[mapPropName];
        const textureIdentifier = options[identifierPropName];
        const detailModeOption = options[detailModePropName];

        const chunkCode = chunks.get(chunkName);
        Debug.assert(chunkCode, `Shader chunk ${chunkName} not found.`);

        // log errors if the chunk format is deprecated (format changed in engine 2.7)
        Debug.call(() => {
            if (chunkCode) {
                // strip comments from the chunk
                const code = chunks.get(chunkName).replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1');

                this._validateMapChunk(code, propNameCaps, chunkName, chunks);

                if (vertexColorOption && options.vertexColorGamma) {
                    if (code.includes('gammaCorrectInputVec3(saturate3(vVertexColor.') || code.includes('gammaCorrectInput(saturate(vVertexColor.')) {
                        Debug.errorOnce(`Shader chunk ${chunkName} contains gamma correction code which is incompatible with vertexColorGamma=true. Please remove gamma correction calls from the chunk.`, { code: code });
                    }
                }
            }
        });

        if (textureOption) {

            fDefines.set(`STD_${propNameCaps}_TEXTURE`, '');

            const uv = this._getUvSourceExpression(transformPropName, uVPropName, options);

            // chunk injection defines
            fDefines.set(`{STD_${propNameCaps}_TEXTURE_UV}`, uv);
            fDefines.set(`{STD_${propNameCaps}_TEXTURE_CHANNEL}`, options[channelPropName]);

            // texture sampler define
            const textureId = `{STD_${propNameCaps}_TEXTURE_NAME}`;
            if (chunkCode.includes(textureId)) {
                let samplerName = `texture_${mapPropName}`;
                const alias = mapping[textureIdentifier];
                if (alias) {
                    samplerName = alias;
                } else {

Review comment (suggestion):
I think this part `&& options.vertexColorGamma` should not be there. We want user to remove gamma correction in every case, as the color always comes as linear.

Code after:
        const transformPropName = `${mapPropName}Transform`;
        const channelPropName = `${mapPropName}Channel`;
        const vertexColorChannelPropName = `${propName}VertexColorChannel`;
        const tintPropName = `${propName}Tint`;
        const vertexColorPropName = `${propName}VertexColor`;
        const detailModePropName = `${propName}Mode`;
        const invertName = `${propName}Invert`;

        const tintOption = options[tintPropName];
        const vertexColorOption = options[vertexColorPropName];
        const textureOption = options[mapPropName];
        const textureIdentifier = options[identifierPropName];
        const detailModeOption = options[detailModePropName];

        const chunkCode = chunks.get(chunkName);
        Debug.assert(chunkCode, `Shader chunk ${chunkName} not found.`);

        // log errors if the chunk format is deprecated (format changed in engine 2.7)
        Debug.call(() => {
            if (chunkCode) {
                // strip comments from the chunk
                const code = chunks.get(chunkName).replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1');

                this._validateMapChunk(code, propNameCaps, chunkName, chunks);

                if (vertexColorOption) {
                    if (code.includes('gammaCorrectInputVec3(saturate3(vVertexColor.') || code.includes('gammaCorrectInput(saturate(vVertexColor.')) {
                        Debug.errorOnce(`Shader chunk ${chunkName} contains gamma correction code which is incompatible with vertexColorGamma=true. Please remove gamma correction calls from the chunk.`, { code: code });
                    }
                }
            }
        });

        if (textureOption) {

            fDefines.set(`STD_${propNameCaps}_TEXTURE`, '');

            const uv = this._getUvSourceExpression(transformPropName, uVPropName, options);

            // chunk injection defines
            fDefines.set(`{STD_${propNameCaps}_TEXTURE_UV}`, uv);
            fDefines.set(`{STD_${propNameCaps}_TEXTURE_CHANNEL}`, options[channelPropName]);

            // texture sampler define
            const textureId = `{STD_${propNameCaps}_TEXTURE_NAME}`;
            if (chunkCode.includes(textureId)) {
                let samplerName = `texture_${mapPropName}`;
                const alias = mapping[textureIdentifier];
                if (alias) {
                    samplerName = alias;
                } else {