2

I have a small issue with the three.js example fresnel shader.

'lights : true' - if this is 'true' then I get the following error:

Uncaught TypeError: Cannot set property 'value' of undefined 

I'm clueless. Thanks for any suggestions.

WestLangley
  • 102,557
  • 10
  • 276
  • 276
SuddenHero
  • 45
  • 8

1 Answers1

3

When you set ShaderMaterial.lights = true, the renderer will populate the shader lights uniform parameters for you.

But you have to ensure that your shader has the necessary lights uniforms in the first place.

THREE.FresnelShader does not use lights as written; it relies on an environment map instead. Consequently, setting lights: true will have no effect.

But if you want to do it, and are willing to modify the shader, you have to replace

var shader = THREE.FresnelShader;
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );

with

var shader = THREE.FresnelShader;

var uniforms = THREE.UniformsUtils.merge( [

    THREE.UniformsLib[ "lights" ],
    shader.uniforms

] );

three.js r.59

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Can I send you a beer? :) Thank you for the explanation! – SuddenHero Aug 04 '13 at 18:02
  • I wish, but my reputation apparently is not high enough...all those hours playing GTA2...useless. Tell me one thing, do you think is it's also possible to add a diffuse color to the shader material? I know that the it uses env map for the color, but maybe there is a blending method to achieve that? Or a fresnel material... – SuddenHero Aug 04 '13 at 18:16
  • If you have further issues, you need to make a new post. This is for the benefit of others... Yes, anything can be done. Study the three.js examples. It's a steep learning curve. I'd suggest you first hardwire a color. Later, pass the color in. – WestLangley Aug 04 '13 at 18:24
  • http://stackoverflow.com/questions/18046248/three-js-fresnel-shader-color-changing-or-env-map-blending I've posted it here. I don't catch the part about passing the color in to the shader :/ I'm not the shaders pro...Thanks for any help – SuddenHero Aug 04 '13 at 18:37