我正在尝试为Three.js制作最简单的自定义着色器,但我还没弄清楚如何使其工作.我正在使用着色器的对象根本没有出现.
在我的页面html中,我有:
<script id="simplefs" type="x-shader/x-fragment"> void main(void) { gl_FragColor = vec4(0.0,1.0,0.0,1.0); } </script> <script id="simplevs" type="x-shader/x-vertex"> void main(void) { gl_Position = modelViewMatrix * projectionMatrix * vec4(position,1.0); } </script>
然后在javascript中:
var vertShader = document.getElementById("simplevs").innerHTML; var fragShader = document.getElementById("simplefs").innerHTML; var myMaterial = new THREE.ShaderMaterial({ vertexShader : vertShader,fragmentShader: fragShader }); var baseBevel = new THREE.Mesh(new THREE.CylinderGeometry(BaseRadius - BaseBevel,BaseRadius,BaseBevel,100,false),myMaterial ) baseBevel.position.x = x; baseBevel.position.y = y; baseBevel.position.z = BaseHeight - (BaseBevel / 2.0); baseBevel.rotation.x = Math.PI / 2.0; scene.add(baseBevel);
对象应该在哪里,什么也没有.如果我用MeshLambertMaterial替换材质,它工作正常.我错过了什么,我需要让它工作?
解决方法
简单的解决方案,顶点着色器中矩阵乘法的顺序需要更改为:
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);