在這裏,我有一個幾何(金字塔)有四個頂點和4個面 -紋理加載使用ShaderMaterial定製的幾何不three.js所
var geom = new THREE.Geometry();
geom.vertices.push(new THREE.Vector3(0,100,0), new THREE.Vector3(-100,-100,100), new THREE.Vector3(0,-100,-100), new THREE.Vector3(100,-100,100));
geom.faces.push(new THREE.Face3(0, 2, 1), new THREE.Face3(0, 1, 3), new THREE.Face3(0, 3, 2), new THREE.Face3(1, 2, 3));
geom.computeFaceNormals();
這裏是我的RawShaderMaterial -
var geomMaterial = new THREE.RawShaderMaterial({
vertexShader: [
'precision highp float;',
'precision highp int;',
'uniform mat4 modelViewMatrix;',
'uniform mat4 projectionMatrix;',
'attribute vec3 position;',
'attribute vec2 uv;',
'varying vec2 interpolatedUV;',
'void main() {',
'interpolatedUV = uv;',
'gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);',
'}'
].join('\n'),
fragmentShader: [
'precision highp float;',
'precision highp int;',
'uniform sampler2D texSampler;',
'varying vec2 interpolatedUV;',
'void main() {',
'gl_FragColor = texture2D(texSampler, interpolatedUV);',
'}'
].join('\n'),
uniforms: {
texSampler: {
type: 't',
value: new THREE.ImageUtils.loadTexture("images/test.png")
}
}
});
「images/test.png」可以從腳本訪問。對我來說,這看起來很微不足道,但紋理根本不顯示出來。我只能看到一個白色的金字塔。
你能告訴我究竟出了什麼問題嗎?
UPDATE:
周圍挖掘後,我發現我不得不爲我所創建的自定義形狀的UV貼圖。所以我將它這樣 -
var uvs = [];
uvs.push(new THREE.Vector2(0.5, 1.0));
uvs.push(new THREE.Vector2(0.5, 0.0));
uvs.push(new THREE.Vector2(0.0, 0.0));
uvs.push(new THREE.Vector2(1.0, 0.0));
geom.faces.push(new THREE.Face3(0, 2, 1));
geom.faceVertexUvs[0].push(uvs[0], uvs[2], uvs[1]);
geom.faces.push(new THREE.Face3(0, 1, 3));
geom.faceVertexUvs[0].push(uvs[0], uvs[1], uvs[3]);
geom.faces.push(new THREE.Face3(0, 3, 2));
geom.faceVertexUvs[0].push(uvs[0], uvs[3], uvs[2]);
geom.faces.push(new THREE.Face3(1, 2, 3));
geom.faceVertexUvs[0].push(uvs[1], uvs[2], uvs[3]);
但它仍然顯示白色pyramid.And也是我現在收到此錯誤 -
THREE.BufferAttribute.copyVector2sArray():矢量未定義0 THREE.BufferAttribute.copyVector2sArray():矢量未定義1 THREE.BufferAttribute.copyVector2sArray():矢量是未定義2 THREE.BufferAttribute.copyVector2sArray():矢量是未定義3 THREE.BufferAttribute.copyVector2sArray():載體是undefined 4 THREE.BufferAttr ibute.copyVector2sArray():矢量是未定義5 THREE.BufferAttribute.copyVector2sArray():矢量未定義6 THREE.BufferAttribute.copyVector2sArray():載體是未定義7 THREE.BufferAttribute.copyVector2sArray():矢量是未定義8 THREE.BufferAttribute.copyVector2sArray():矢量未定義9 THREE.BufferAttribute.copyVector2sArray():載體是未定義的10 THREE.BufferAttribute.copyVector2sArray():載體是未定義的11
任何有關它的想法?
沒有錯誤?我認爲原始着色器材質不會給你projectionMatrix MVMatrix等 – pailhead
如果我刪除我的自定義幾何並提供sphereGeometry,它工作正常。所以我認爲問題不在那裏。 –
do gl_FragColor = vec4(abs(interpolatedUV),0.,1); 看看它是否給出了任何顏色 – pailhead