Replicating MeshLambertMaterial Using ShaderMaterial ignores textures

前端 未结 1 664
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 13:08

I noticed that THREE.js uses shaders internally to create core material \"e.g. MeshLambertMaterial\", So I decided to copy the lambert shader from Three.js code into a new s

相关标签:
1条回答
  • 2020-11-28 13:28

    three.js was designed to be easy to use, not easy to modify. This may change in the future...

    You need to set the material.defines like so:

    var defines = {};
    
    defines[ "USE_MAP" ] = "";. 
    

    Then specify defines in the material constructor.

    var material =  new THREE.ShaderMaterial({
       name: "TerrainShader",
       defines     : defines,
       uniforms    : shaderUniforms,
       vertexShader: THREE.MyShader.vertexShader,
       fragmentShader: THREE.MyShader.fragmentShader,
       fog:false,
       lights:true
    });
    

    Regarding the texture repetitions, you need to add the repeat to your uniforms:

    shaderUniforms[ "offsetRepeat" ].value.set( 0, 0, 2, 2 );
    

    three.js r.66

    0 讨论(0)
提交回复
热议问题