0

I am trying to run the following simple shader with three.js

mat = new THREE.ShaderMaterial({
  uniforms: {
    color: { type: 'v3', value: new THREE.Color(0xcccccc) }
  },
  vertexShader: 'attribute vec3 vert;\n'
              + 'void main() {\n' 
              + '  gl_Position = vec4(vert, 1.0);\n'
              + '}',
  fragmentShader: 'uniform vec3 color;\n'
                + 'void main() {\n'
                + '  gl_FragColor = vec4(color,1);\n'
                + '}'
})

The shaders compile but the object that has this material is invisible.

This should display the object in a constant light grey color.

When I run this with kick.js shader editor it works as expected.

Predefined materials all work great.

Am I missing something?

2
  • what is this shader supposed to do? what is the expected result? Commented Apr 11, 2015 at 17:58
  • probably to do with settings the gl_Position with the vert attribute. Are you sure it has a value? Take a look at some of the three.js shader experiments I have been doing. Commented Apr 11, 2015 at 18:04

1 Answer 1

3

Your vertex shader should be:

// Multiply each vertex by the model-view matrix and the projection matrix
// (both provided by Three.js) to get a final vertex position. 
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
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.