Custom shader - Three.js

六月ゝ 毕业季﹏ 提交于 2019-12-24 12:33:03

问题


I am trying to use a custom shader with Three.js. I tried to do it like the many examples, but it doesn't work. My code is:

var vertex = "void main(){vec4 mvPosition = modelViewMatrix * vec4( position, 1.0    );gl_Position = projectionMatrix * mvPosition;}";
var fragment = "precision highp float;void main(void){gl_FragColor = vec4(0.0,1.0,0.0,1.0);}";
material = new THREE.ShaderMaterial({
                vertexShader: vertex,
                fragmentShader: fragment
        });
var mesh = new THREE.Mesh(geometry,material);

…and everything is blank. But if I use this material :

material = new THREE.MeshBasicMaterial({ color: 0xff0000, wireframe: true });

…everything works perfectly. What's wrong?


回答1:


I found the problem: I had to use:

 renderer = new THREE.WebGLRenderer();

instead of :

 renderer = new THREE.CanvasRenderer();


来源:https://stackoverflow.com/questions/12773388/custom-shader-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!