While it seems to be possible to assign a unique reflection texture to different materials, would it also be possible to do that on a mesh basis? Ideally id love to be able to define groups of meshes using a different environment/reflection texture.
Looking at the documentation there doesnāt seem to be a intuitive way to do this, my first thought would be to duplicate the materials based on their group (predefined collection of meshes) and assign a different reflection texture. However this quickly leads to overhead, since changes to the initial (source) material are not being reflected to the duplicated materials - this seems messy.
Ive added a simple playground which illustrates the shortcomings of this exact approach (cloning materials, changes not being propagated) and my expected functionality (at the bottom of the code, theres a boolean to toggle the expected example usage id like to have - which obviously doesnāt work as expected).
Iām not all too sure about the ārobustā way but I can tell you how I am doing it.
First, I create clones of my env (texture) with a new source for the texture.
Then, I assign either env to my materials. Simple enough, to answer your question, and with the exception of IBL that works at scene level, env can only be defined at material level, not with mesh.
Now, this is my trick, for assigning the env depending on mesh (not on material) I use the mesh.id.
I assign a different id (or part of id as an identifier for the env) i.e. mesh.id = ā1_col_env1ā (where 1 is the mesh number identifier, ācolā means itās a colliding mesh, āenv1ā means it uses environment #1).
Then I can look for all meshes.id that includes āenv1ā, do anything with their material including changing to a different material, env/reflection texture.
Edit: As for your question/logic in the PG saying (quote)
// ideally we want to use the same material and change its cubemap on a mesh basis,
// so we set all meshes to the same material1 first
// then we change the cubemaps, ideally this should be on a mesh basis
I donāt think thereās currently a way. I sort of remember discussions around this but as far as I remember it seemed pretty difficult to achieve. Of course, I could have missed something so best would be to wait for the expert answer (once he returns from his holidays ) @sebavan
// ideally we want to use the same material and change its cubemap on a mesh basis,
// so we set all meshes to the same material1 first
// then we change the cubemaps, ideally this should be on a mesh basis
You should not do that.
Instead, you should create as many materials as necessary, so that each mesh gets the right environment map through its material.
I assumed as much, was just wondering if there was a way of doing this without cloning and using āreferencesā to materials. Iāll probably proceed to implement it like both of you suggested.
I donāt think there is. I believe evgeni would have known about it. I remembered some discussion for something similar so I wanted to ask but Iām pretty sure now this is not on the list as of today. But the cloning of materials and textures works fairly well. I didnāt notice an enormeous impact on performance using a few dozens of these (with 3 different env) thatās what I have currently in my scene.