我正在尝试为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, 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
替换材料,它可以正常工作。我错过了什么,我需要让它工作?
答案 0 :(得分:7)
简单的解决方案,顶点着色器中矩阵乘法的顺序需要更改为:
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);