three.js icon indicating copy to clipboard operation
three.js copied to clipboard

HemisphereLight direction uniform

Open sunag opened this issue 3 years ago • 6 comments

We are using a HemisphereLight.position property to define a direction to HemisphereLight normals, but that doesn't seem entirely appropriate to me, since it's an angle, and angle is .rotation/.euler.

I think that we could use .getWorldDirection() instead of .position?

Can I start like this on WebGPU?

WebGL Code: https://github.com/mrdoob/three.js/blob/8db7a598ed6e71538e286e5c56c02cc5823157dc/src/renderers/webgl/WebGLLights.js#L530-L532

sunag avatar Apr 12 '22 15:04 sunag

Yes, using the position property to define the orientation of the HemisphereLight is unusual.

If a change is desired, I think the most logical API would be to use the .up property instead, but I am not sure it is worth changing.

WestLangley avatar Apr 12 '22 17:04 WestLangley

This line is redundant.

uniforms.direction.normalize(); 

WestLangley avatar Apr 12 '22 17:04 WestLangley

Related #16555.

Mugen87 avatar Apr 13 '22 09:04 Mugen87

It seems users find it confusing that HemisphereLight does not react when changing its rotation properties. On the other hand, #16555 pointed out that ambient and hemisphere lights are in fact simplified light probes which do not have a rotation by definition.

BabylonJS uses a separate direction vector for the definition of a hemispheric light. It seems using Object3D.up could be indeed a proper alternative.

Mugen87 avatar Apr 13 '22 09:04 Mugen87

so you find using hemi.position weird, but directional light is fine lol

makc avatar Apr 14 '22 18:04 makc

It was previously discussed to remove the target property and orient directional and spot lights as you would expect. There is an existing PR but I've lately implemented this feature by myself to better understand the change: https://github.com/Mugen87/three.js/commit/a2a8005d18012f90929060ddd9d5b288c4e6da60

Unfortunately, such a change will noticeably impact user code. You can easily see this at the number of examples that break which the PR.

Mugen87 avatar Apr 15 '22 08:04 Mugen87