Last active
April 29, 2018 22:44
-
-
Save mootari/8a833089efe5d6375b92552eede001f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMaterial(uniformsCallback) { | |
const material = new THREE.MeshStandardMaterial(/* ... */); | |
material.onBeforeCompile = shader => { | |
shader.uniforms.time = { value: 0 }; | |
if(uniformsCallback) uniformsCallback(shader.uniforms); | |
shader.fragmentShader = applyPatches(shader.fragmentShader, { | |
'varying vec3 vViewPosition;': `$& | |
uniform float time; | |
` | |
}); | |
} | |
return material; | |
} | |
let uniforms; | |
const material = getMaterial(u => uniforms = u); | |
const mesh = initMesh(material); | |
mesh.onBeforeRender = (renderer, scene, camera, geometry, material, group) => { | |
if(!uniforms) renderer.compile(scene, camera); | |
uniforms.time.value = performance.now() / 1000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment