使用着色器无法正确渲染纹理

时间:2019-01-11 07:12:52

标签: three.js glsl textures

我有一个视频纹理,必须将其输入到glsl着色器中。我为此使用threejs。我的代码如下

let texture = new THREE.VideoTexture(video);
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
let vertexShader = `
        varying vec2 vuv;
        void main() {
        vuv = uv; 
        gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
        }`
let fragmentShader = `
      varying vec2 vuv;
      uniform sampler2D texture0;
      void main() {
          gl_FragColor = texture2D(texture0,vuv);
    }`;
let uniform = { texture0: { type:'t',texture: texture } };
let material = new THREE.ShaderMaterial({ uniforms: uniform, fragmentShader: fragmentShader, vertexShader: vertexShader })
let geometry = new THREE.PlaneGeometry(1000, 1000);
let mesh = new THREE.Mesh(geometry, material);
this.scene.add(mesh);

但是,这仅给出黑色而不是纹理。我在哪里错了?

1 个答案:

答案 0 :(得分:1)

let uniform = { texture0: { type:'t',texture: texture } };

必须这样:

let uniform = { texture0: { value: texture } };