Note that there are some explanatory texts on larger screens.

plurals
  1. POThree js - Cloning a shader and changing uniform values
    primarykey
    data
    text
    <p>I'm working on creating a shader to generate terrain with shadows.</p> <p>My starting point is to clone the lambert shader and use a ShaderMaterial to eventually customise it with my own script.</p> <p>The standard method works well:</p> <pre><code>var material = new MeshLambertMaterial({map:THREE.ImageUtils.loadTexture('images/texture.jpg')}); var mesh = new THREE.Mesh(geometry, material); etc </code></pre> <p>The result: <img src="https://i.stack.imgur.com/BTRD1.png" alt="Result with standard lambert material"></p> <p>However I'd like to use the lambert material as a base and work on top of it, so I tried this:</p> <pre><code>var lambertShader = THREE.ShaderLib['lambert']; var uniforms = THREE.UniformsUtils.clone(lambertShader.uniforms); var texture = THREE.ImageUtils.loadTexture('images/texture.jpg'); uniforms['map'].texture = texture; var material = new THREE.ShaderMaterial({ uniforms: uniforms, vertexShader: lambertShader.vertexShader, fragmentShader: lambertShader.fragmentShader, lights:true, fog: true }); var mesh = new THREE.Mesh(geometry, material); </code></pre> <p>The result for this one: <img src="https://i.stack.imgur.com/I6480.png" alt="Result for cloning lambert shader and changing map uniforms"></p> <p>It looks as if the shader is not taking into account the new texture I have added, however looking at the inspector when I logged the uniforms, the map object has the correct values.</p> <p>I'm pretty new to three so I might be doing something fundamentally wrong, if someone could point me in the right direction here, that would be great.</p> <p>I can also put up demo links if that would be helpful?</p> <p>Thanks, Will</p> <p>EDIT:</p> <p>Here are some demo links.</p> <p>Demo with shader material: <a href="http://dev.thinkjam.com/experiments/threejs/terrain/terrain-shader-material.html" rel="nofollow noreferrer">http://dev.thinkjam.com/experiments/threejs/terrain/terrain-shader-material.html</a></p> <p>Demo with working lambert material: <a href="http://dev.thinkjam.com/experiments/threejs/terrain/terrain-lambert-material.html" rel="nofollow noreferrer">http://dev.thinkjam.com/experiments/threejs/terrain/terrain-lambert-material.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload