1

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?

2
  • It works fine for me. It must be some other piece of code you aren't showing. Commented Oct 8, 2012 at 0:24
  • Couldbe there some problem with geometry? I am loading that like array of vertices and indices, but with MeshBasic material it works great..i will try to find it deeper in my code.. Commented Oct 8, 2012 at 7:05

1 Answer 1

3

I found the problem: I had to use:

 renderer = new THREE.WebGLRenderer();

instead of :

 renderer = new THREE.CanvasRenderer();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.