2013-10-27 83 views

回答

0

常用方式,包括你的着色器是把他們在<script>標籤:

<script id="vertexShader" type="x-shader/x-vertex"> 

    void main() { 
     ... 
    } 

</script> 

<script id="fragmentShader" type="x-shader/x-fragment"> 

    void main() { 
     ... 
    } 

</script> 

然後,在你init功能:

// it's useful to have uniforms as a ~global variable, 
// so you can modify them from other functions 
// in animate() or render() for example 
var uniforms = { 
    // here, your shader's uniforms variables 
}; 

var material = new THREE.ShaderMaterial({ 
    uniforms: uniforms 
    vertexShader: document.getElementById('vertexShader').textContent, 
    fragmentShader: document.getElementById('fragmentShader').textContent 
}); 

而在你的裝載機回調

var mesh = event.content; 
mesh.material = material; 

看看這個簡單的着色器的例子http://threejs.org/examples/webgl_shader.html

相關問題