{"action":"created","issue":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/14121","repository_url":"https://api.github.com/repos/mrdoob/three.js","labels_url":"https://api.github.com/repos/mrdoob/three.js/issues/14121/labels{/name}","comments_url":"https://api.github.com/repos/mrdoob/three.js/issues/14121/comments","events_url":"https://api.github.com/repos/mrdoob/three.js/issues/14121/events","html_url":"https://github.com/mrdoob/three.js/issues/14121","id":325721720,"node_id":"MDU6SXNzdWUzMjU3MjE3MjA=","number":14121,"title":"WebGLLights state and its hashing produce unintended material reinitialization","user":{"login":"Usnul","id":5939063,"node_id":"MDQ6VXNlcjU5MzkwNjM=","avatar_url":"https://avatars0.githubusercontent.com/u/5939063?v=4","gravatar_id":"","url":"https://api.github.com/users/Usnul","html_url":"https://github.com/Usnul","followers_url":"https://api.github.com/users/Usnul/followers","following_url":"https://api.github.com/users/Usnul/following{/other_user}","gists_url":"https://api.github.com/users/Usnul/gists{/gist_id}","starred_url":"https://api.github.com/users/Usnul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Usnul/subscriptions","organizations_url":"https://api.github.com/users/Usnul/orgs","repos_url":"https://api.github.com/users/Usnul/repos","events_url":"https://api.github.com/users/Usnul/events{/privacy}","received_events_url":"https://api.github.com/users/Usnul/received_events","type":"User","site_admin":false},"labels":[{"id":175827,"node_id":"MDU6TGFiZWwxNzU4Mjc=","url":"https://api.github.com/repos/mrdoob/three.js/labels/Suggestion","name":"Suggestion","color":"ffffcf","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-05-23T14:05:09Z","updated_at":"2018-07-15T20:34:00Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"`WebGLLights` is used to store lighting state.\r\n`WebGLLights.hash` property is used to determine whether or not a material needs to be re-built.\r\n\r\nhttps://github.com/mrdoob/three.js/blob/bd63a6cc8dd7fe11b530410fab9f67a9de359be8/src/renderers/WebGLRenderer.js#L1479-L1482\r\n\r\n\r\nThe way `hash` is built, it includes unique reference to `WebGLLights` instance:\r\nhttps://github.com/mrdoob/three.js/blob/efeb95f10790ab4755171584139d5344177f2713/src/renderers/webgl/WebGLLights.js#L319\r\n\r\nconstructor:\r\nhttps://github.com/mrdoob/three.js/blob/efeb95f10790ab4755171584139d5344177f2713/src/renderers/webgl/WebGLLights.js#L103-L111\r\n\r\nthis means that if you have 2 instances of `WebGLLights` and they are identical, except for `id` - you will end up rebuilding materials as you switch between these instances - inefficient.\r\n\r\nAnother problem with the current approach is that it is probabilistic, it's possible that `hash` remains the same even though lighting has changed.\r\n\r\nI propose following:\r\n* remove `id` from `hash` calculation\r\n* use a fast hashing function to compute 64bit hash(javascript `number` is IEEE 64-bit Float) instead of using a string\r\n* pass more than just number of lights into the `hash` (as long as that makes sense).\r\n"},"comment":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/comments/405116393","html_url":"https://github.com/mrdoob/three.js/issues/14121#issuecomment-405116393","issue_url":"https://api.github.com/repos/mrdoob/three.js/issues/14121","id":405116393,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTExNjM5Mw==","user":{"login":"WestLangley","id":1000017,"node_id":"MDQ6VXNlcjEwMDAwMTc=","avatar_url":"https://avatars2.githubusercontent.com/u/1000017?v=4","gravatar_id":"","url":"https://api.github.com/users/WestLangley","html_url":"https://github.com/WestLangley","followers_url":"https://api.github.com/users/WestLangley/followers","following_url":"https://api.github.com/users/WestLangley/following{/other_user}","gists_url":"https://api.github.com/users/WestLangley/gists{/gist_id}","starred_url":"https://api.github.com/users/WestLangley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WestLangley/subscriptions","organizations_url":"https://api.github.com/users/WestLangley/orgs","repos_url":"https://api.github.com/users/WestLangley/repos","events_url":"https://api.github.com/users/WestLangley/events{/privacy}","received_events_url":"https://api.github.com/users/WestLangley/received_events","type":"User","site_admin":false},"created_at":"2018-07-15T20:33:59Z","updated_at":"2018-07-15T20:33:59Z","author_association":"COLLABORATOR","body":">or indeed having two scenes that use the same materials and lighting setup.\r\n\r\nThis is the use case in #14477.\r\n\r\nIn that case, the work-around is to clone the material, and not share it:\r\n```javascript\r\nvar mesh1 = new THREE.Mesh( geometry, material );\r\nscene1.add( mesh1 );\r\n\r\nvar mesh2 = new THREE.Mesh( geometry, material.clone() );\r\nscene2.add( mesh2 );\r\n```\r\n\r\nThis is either a limitation or a bug. If we consider this a limitation, we should document both the limitation and the work-around somewhere.\r\n\r\nI'm thinking it would be preferable to consider this a bug.\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"WestLangley"}}