I have been trying to make normal maps work in three.js, but to no avail. Although there are already questions asking this (including Three.js Normal Mapping forcing mesh to not render and How to make a normal map in THREE.js correctly?), none of them have been very helpful because they are outdated and the way of doing the normal maps no longer works (in r71, which is what I'm using, and which is the most recent as of this post). I have tried the following, but I do not know why it does not work. There are no errors, only a lack of visible changes when the normal map is used.
There is a JSFiddle of what I have tried. Also, the code of what I have tried:
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var ambient = 0x050505,
diffuse = 0x331100,
specular = 0xffffff,
shininess = 10,
scale = 23;
scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 0;
camera.position.y = 0;
camera.lookAt({
x: 0,
y: 0,
z: 0
});
scene.add(camera);
camera.position.set(0, 100, 1000);
camera.lookAt(new THREE.Vector3(0, 0, 0));
scene = new THREE.Scene();
var ambientLight = new THREE.AmbientLight(0x222222);
scene.add(ambientLight);
var light = new THREE.PointLight(0xffffff, 1);
light.position.copy(camera.position);
scene.add(light);
var plane = new THREE.Mesh(new THREE.PlaneGeometry(500, 500), new THREE.MeshLambertMaterial({
color: 0x22FF11,
side: THREE.DoubleSide
}));
plane.position.set(0, 0, -500);
plane.receiveShadow = true;
scene.add(plane);
var cube = new THREE.Mesh(new THREE.BoxGeometry(50, 50, 50), new THREE.MeshPhongMaterial({
color: 0xCC0000,
}));
//A picture I found on the internet:
var normalMap = THREE.ImageUtils.loadTexture('http://4.bp.blogspot.com/-nVnWCcT-VkY/VC2FnM6ZOmI/AAAAAAAAA4k/bWRniM20L_s/s1600/T_Wood512_N.jpg', undefined, function () {
cube.material.normalMap = normalMap;
renderer.render(scene, camera);
});
cube.position.set(0, 0, -250);
scene.add(cube);
renderer.render(scene, camera);
Is there something I am doing incorrectly or an up-to-date reference that I can use?