Hi I am trying to do what seems like simple shading with threejs. I am using the Up and Running book by O'reilly.
Everything was working fine, until I tried to do this:
var shader = THREE.ShaderLib["normal"];
var uniforms = THREE.UniformsUtils.clone(shader.uniforms);
uniforms["tNormal"].texture = normalMap;
uniforms["tDiffuse"].texture = surfaceMap;
uniforms["tSpecular"].texture = specularMap;
This keeps throwing this error:
TypeError: uniforms.normal is undefined [Break On This Error]
uniforms["normal"].texture = normalMap;
I have been looking around online for a while and am not sure what syntax needs to change to solve this issue.
Any help is appreciated.
Hi I am trying to do what seems like simple shading with threejs. I am using the Up and Running book by O'reilly.
Everything was working fine, until I tried to do this:
var shader = THREE.ShaderLib["normal"];
var uniforms = THREE.UniformsUtils.clone(shader.uniforms);
uniforms["tNormal"].texture = normalMap;
uniforms["tDiffuse"].texture = surfaceMap;
uniforms["tSpecular"].texture = specularMap;
This keeps throwing this error:
TypeError: uniforms.normal is undefined [Break On This Error]
uniforms["normal"].texture = normalMap;
I have been looking around online for a while and am not sure what syntax needs to change to solve this issue.
Any help is appreciated.
Share Improve this question asked May 3, 2013 at 3:58 dotfurydotfury 3225 silver badges13 bronze badges 2-
shader.uniforms
has no "tNormal" attribute. What do you want to do with this shader? – Ovilia Commented May 3, 2013 at 4:04 - I was following along with the book. I also the other lines for diffuse and specular,which also throw similar errors. – dotfury Commented May 3, 2013 at 4:07
3 Answers
Reset to default 5I think that should be like:
uniforms["tNormal"] = {
texture: normalMap
};
Same for tDiffuse
, tSpecular
.
I find that when running your code, after the lines:
var shader = THREE.ShaderLib["normal"];
var uniforms = THREE.UniformsUtils.clone(shader.uniforms);
uniforms is an object with one member: opacity. Thus uniforms["tNormal"] does not yet exist. As Olivia suggested, you could add these in using:
uniforms["tNormal"] = {
texture: normalMap
};
Your error and your code are different. The error reports undefined texture on:
uniforms["normal"].texture = normalMap;
The code you cited says you're using:
uniforms["tNormal"].texture = normalMap;
.
I'm working on the same book examples, try this:
var shader = THREE.ShaderLib[ "normalmap" ];
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
uniforms[ "tNormal" ].texture = normalMap;
uniforms[ "tDiffuse" ].texture = surfaceMap;
uniforms[ "tSpecular" ].texture = specularMap;
uniforms[ "enableDiffuse" ].value = true;
uniforms[ "enableSpecular" ].value = true;