Three.js 如何将纹理发送到着色器

Three.js 如何将纹理发送到着色器,three.js,glsl,webgl,Three.js,Glsl,Webgl,我在向着色器发送纹理时遇到问题。这是我正在使用的代码 uniforms = { "rightTexture": { type: "t", value: THREE.ImageUtils.loadTexture( "images/doors_right_512.png" ) }, "tDiffuse": { type: "t", value: null }, "aspect": { type: "v2", value: new THREE.Vector2( 512

我在向着色器发送纹理时遇到问题。这是我正在使用的代码

uniforms = {
    "rightTexture":  { type: "t", value: THREE.ImageUtils.loadTexture( "images/doors_right_512.png" ) },
    "tDiffuse":  { type: "t", value: null },
    "aspect":    { type: "v2", value: new THREE.Vector2( 512, 512 ) },
};
uniform sampler2D rightTexture;
vec3 sample;
sample = texture2D(rightTexture, vUv).rgb;
gl_FragColor = vec4(vec3(sample), 1.0);

当我采样tDiffuse时,一切看起来都很好,但如果我使用rightTexture,我只会得到一个黑屏。这是为什么?

你在等待纹理加载吗?请检查它是否正确上载,我敢说加载有问题。抱歉,我不确定tDiffuse和普通纹理之间是否有根本区别。我不太确定怎样才能让事情等到加载完成。我想我必须使用某种回拨功能?有什么建议吗?它不是three.js,但您可能会使用相同的想法。