Three.js: Setting lights: true on THREE.PointsMaterial breaks

Created on 2 Jan 2017  路  19Comments  路  Source: mrdoob/three.js

(* This section is for bug reports and feature requests only. This is NOT a help site. Do not ask help questions here. If you need help, please use stackoverflow. *)

Description of the problem
var starsMaterialx = new THREE.PointsMaterial( { color: 0xFFFFFF, size: 5, lights: true } );
returns
Uncaught TypeError: Cannot set property 'value' of undefined
    at t (three.min.js:136)
while
var starsMaterialx = new THREE.PointsMaterial( { color: 0xFFFFFF, size: 5 } );
and
var starsMaterialx = new THREE.PointsMaterial( { color: 0xFFFFFF, size: 5, lights: false } );
works fine.
Three.js version
  • [ ] Dev
  • [x] r82
  • [ ] ...
Browser
  • [x] All of them
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Internet Explorer
OS
  • [x] All of them
  • [ ] Windows
  • [ ] Linux
  • [ ] Android
  • [ ] IOS
Hardware Requirements (graphics card, VR Device, ...)

iMac (Retina 5K, 27-inch, Late 2014)
AMD Radeon R9 M295X 4096 MB

All 19 comments

Setting lights: true on MeshBasicMaterial, MeshDepthMaterial, and likely other materials, also throws errors.

I wonder if Material should really have a lights property...

I don't think MeshBasicMaterial or MeshDepthMaterial were intended to react to lights. Mesh{Phong,Lambert}Material does that already. However, a points system that could react to lights could make some really pretty scenes. It was also stated that lights is a legitimate property of PointsMaterial in the docs.

I don't think MeshBasicMaterial or MeshDepthMaterial were intended to react to lights.

Right. But they have a lights property that a user should not alter.

@mrdoob usually has a clever design solution to situations such as this. : ) Maybe it should be Material._lights.

I too encountered this problem when setting lights:true for PointsMaterial. The property can be set to true, but then it breaks. It may be related to the light property (there is no ambientLightColor for PointsMaterial?):
three.min.js:139 Uncaught TypeError: Cannot set property 'value' of undefined:
k.ambientLightColor.value=aa.ambient

Any update on this?

I think using Object.AssignProperty is a better solution than fake private variables like _lights - that way the property can be made actually unchangeable, and a warning can be shown if desired when someone tries to change it.

Are there any materials for which this property can be changed?

I think the point here isn't setting the property. I can set the "lights" of PointsMaterial to true, but then the code breaks when renderer.render(scene,camera):

                   if ( material.lights ) {

            // wire up the material to this renderer's lighting state
                             uniforms.ambientLightColor.value = _lights.ambient; // this line breaks
            ...
        }

Full traceback:
three.js:21195 Uncaught TypeError: Cannot set property 'value' of undefined
initMaterial @ three.js:21195
setProgram @ three.js:21291
WebGLRenderer.renderBufferDirect @ three.js:20270
renderObjects @ three.js:21061
WebGLRenderer.render @ three.js:20798

Are there any materials for which this property can be changed?

There are no materials for which we need to support changing it.

In the case of ShaderMaterial, I think the same goes for these:

this.fog = false; // set to use scene fog
this.lights = false; // set to use scene lights
this.clipping = false; // set to use user-defined clipping planes

this.skinning = false; // set to use skinning attribute streams
this.morphTargets = false; // set to use morph targets
this.morphNormals = false; // set to use morph normals

this.extensions = {
    derivatives: false, // set to use derivatives
    fragDepth: false, // set to use fragment depth values
    drawBuffers: false, // set to use draw buffers
    shaderTextureLOD: false // set to use shader texture LOD
};
this.fog = false; // set to use scene fog
this.lights = false; // set to use scene lights
this.clipping = false; // set to use user-defined clipping planes

Well... In the case of fog, I can see the case of having a background sphere unaffected by fog. I guess scene.background solves that though.

So yeah... I think I'm in favour of removing these.

I think a point system should be able to react to lights.

I don't. Points do not have vertex normals.

particle lighting may be computed just by distance from light source (according to intensity, decay, distance parameters of the light sources), it makes sense.

particle lighting may be computed just by distance from light source (according to intensity, decay, distance parameters of the light sources), it makes sense.

Yeah, that could be nice.

Interesting! We should think how to name it...
PointsMaterial would become PointsBasicMaterial and we would need Points???Material?

Solved via #17570

Sorry I haven't followed up the .lights property discussion but with #17570 PointsMaterial + light works like https://github.com/mrdoob/three.js/issues/10491#issuecomment-329491923 now? Or just no error tho no light effect to points?

The .lights property caused some confusion in the user base since sometimes it was not considered as read-only. So we removed it from all materials except ShaderMaterial where it is still important.

Thanks. From the code there, PointsMaterial doesn't seem to work with light yet (does it?). I'll open PointsMaterial + light feature request issue because this issue has been closed.

Yeah, I think that's better for clarity reasons 馃憤

Was this page helpful?
0 / 5 - 0 ratings