我有一个视频纹理,必须将其输入到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);
但是,这仅给出黑色而不是纹理。我在哪里错了?
答案 0 :(得分:1)
let uniform = { texture0: { type:'t',texture: texture } };
必须这样:
let uniform = { texture0: { value: texture } };