standardMaterial using shaderMaterial. USE_MAP suddenly stopped working, "maptexelToLinear; no matching overloaded function found"

Viewed 889


I am using the latest three.js build from github, it was updated the night before.

This code worked a few days back, but without changing the code this stopped working yesterday. It gives the error message maptexelToLinear; no matching overloaded function found on line 6 in the map_fragment shaderChunk:

vec4 texelColor = texture2D( map, vUv );
texelColor = mapTexelToLinear( texelColor ); //here

Did something change? Is this still the correct way of creating a standard material from a shadermaterial? With the defines, extensions and map uniform?

https://jsfiddle.net/EthanHermsey/c4sea1rg/119/

    let texture = new THREE.TextureLoader().load(

        document.getElementById( 'blockDiff' ).src

    );


    // this works fine
    /* let mat = new THREE.MeshStandardMaterial( {

           map: texture

    } ) */



    // this does not
    let mat = new THREE.ShaderMaterial( {

        //custom shaders
        // vertexShader: document.getElementById( 'blockVertexShader' ).textContent,
        // fragmentShader: document.getElementById( 'blockFragmentShader' ).textContent,

        //The standard shaders do not even work :/
        vertexShader: THREE.ShaderLib[ 'standard' ].vertexShader,
        fragmentShader: THREE.ShaderLib[ 'standard' ].fragmentShader,

        uniforms: THREE.UniformsUtils.merge( [

            THREE.ShaderLib[ 'standard' ].uniforms,
            {

                blockScale: { value: new THREE.Vector3() } // used in custom shaders

            }

        ] ),

        defines: {

            "STANDARD": '',
            "USE_UV": '',
            "USE_MAP": ''

        },

        lights: true

    } );

    mat.uniforms.map.value = texture;

    mat.extensions.derivatives = true;
    mat.uniformsNeedUpdate = true;
    
1 Answers

There was actually an error in previous three.js versions that injected maptexelToLinear() with a wrong implementation into shader code. This problems was fixed with r118. However, it requires from user code that your custom shader material has a property called map.

Updated code: https://jsfiddle.net/og8Lmp6e/

In this way, it's also not necessary to set custom defines like USE_MAP or USE_UV anymore. That happens automatically. And of course the implementation of maptexelToLinear() now respects the encoding of your texture.

BTW: It's actually best to modify built-in materials with Material.onBeforeCompile().

Related