问题描述
我只是尝试将法线贴图忍者演示应用于使用以下代码在我的场景中使用立方体 - 使用来自 dev 分支的最新 Three.js 版本:
I just tried to apply the Normal map Ninja demo to a cube in my scene with the following code - using new latest Three.js version from dev branch:
// common material parameters
var ambient = 0x050505, diffuse = 0x331100, specular = 0xffffff, shininess = 10, scale = 23;
// normal map shader
var shader = THREE.ShaderUtils.lib[ "normal" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "enableAO" ].value = true;
uniforms[ "enableDiffuse" ].value = false;
uniforms[ "enableSpecular" ].value = false;
uniforms[ "enableReflection" ].value = true;
uniforms[ "tNormal" ].texture = THREE.ImageUtils.loadTexture( "normal.jpg" );
uniforms[ "tAO" ].texture = THREE.ImageUtils.loadTexture( "ao.jpg" );
uniforms[ "tDisplacement" ].texture = THREE.ImageUtils.loadTexture( "displacement.jpg" );
uniforms[ "uDisplacementBias" ].value = - 0.428408 * scale;
uniforms[ "uDisplacementScale" ].value = 2.436143 * scale;
uniforms[ "uDiffuseColor" ].value.setHex( diffuse );
uniforms[ "uSpecularColor" ].value.setHex( specular );
uniforms[ "uAmbientColor" ].value.setHex( ambient );
uniforms[ "uShininess" ].value = shininess;
uniforms[ "tCube" ].texture = reflectionCube;
uniforms[ "uReflectivity" ].value = 0.1;
uniforms[ "uDiffuseColor" ].value.convertGammaToLinear();
uniforms[ "uSpecularColor" ].value.convertGammaToLinear();
uniforms[ "uAmbientColor" ].value.convertGammaToLinear();
var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: false };
var displacementMaterial = new THREE.ShaderMaterial( parameters );
/*
var diamond = new THREE.Diamond({
material: bumpmapMaterial
});
*/
var diamond = new THREE.Mesh(
new THREE.CubeGeometry(50, 50, 50),
displacementMaterial
);
但是,我在 Chrome 中收到以下 WebGL 错误:
I am, however, getting the following WebGL error in Chrome:
GL_INVALID_OPERATION : glDrawXXX: attempt to access out of range vertices
在 Firefox 中,我没有收到这样的错误,但立方体也不会出现.使用标准彩色 MeshLambertMaterial
,一切正常.因此,需要与 ShaderMaterial
发生冲突.如果我使用 MASTER 分支的最新 Three.js 版本,它不会改善这种情况 - 发生同样的错误.
In Firefox, I am not getting an error like this, but the cube wouldn't show up either.Using a standard colored MeshLambertMaterial
, everything's working fine. So, there needs to be a conflict with the ShaderMaterial
. If I use the latest Three.js version from MASTER branch, it doesn't improve the situation - same error occurs.
知道为什么会出现这种情况以及我需要更改什么才能使其正常工作吗?
Any idea why this may be the case and what I need to change to get it working?
推荐答案
尝试添加这个?
geometry.computeTangents();
这篇关于如何在 THREE.js 中正确制作法线贴图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!