Isotropix Forums

Is it possible to access scattered instances color data?

Clarisse Scripting related topics

Re: Is it possible to access scattered instances color data?

Unread postby anemoff » Tue Oct 29, 2019 5:48 pm

Hi Jeremy,

Sorry for the late response.

GeometryParticleContainer is indeed a Geometry and it does have a GeometryPointCloud for its points. However, it doesn't have a supporting geometry ('GeometryPointCloud.has_support()'). It is also the case for a GeometryPointArray, for example.
The shader helper 'evaluate_support_material' needs a GeometryPointCloud with a supporting geometry to evaluate the material against the support. Otherwise, it does nothing and that's why you get only 0 values.

On the other hand, a GeometryPointCloud, which requires a supporting geometry to generate its points, can be used with 'evaluate_support_material'. It works too with a GeometryPolysphere or GeometryPolygrid, or any "mesh" geometry with a topology, for example.

If you check the documentation for 'evaluate_support_material', you can see that it returns false if there is no support. Or if the sizes of 'colors' and 'opacities' don't match with the point count.
You should check the return value to know if material evaluation succeeded.

In fact, our tutorial doesn't check it either. It should be like this on lines 14-18:

python code

# evaluating material on each point of the point cloud
if ix.api.ShaderHelpers.evaluate_support_material(ptc, material, material_colors, material_opacities):
#output the resulting colors and opacities to the Log window
for i in range(count) :
print("Point " + str(i) + ": \nCi = " + str(material_colors[i]) + "\nOi = " + str(material_opacities[i]))
else:
print('evaluate_support_material failed.')


I have an idea of a workaround, but it would be useful to know a bit more about your workflow and what you want to achieve.

My guess is that you want to bake a GeometryPointCloud, that has a supporting geometry, into a GeometryParticleContainer. And then you want to evaluate a material on your baked GeometryParticleContainer. And finally, export the particle container to Alembic, or maybe use it directly in Clarisse. Because of the support problem, you need to evaluate the material on the GeometryPointCloud.

You could, in a single script:
1. evaluate the support material using the source GeometryPointCloud and store the colors in an array of GMathVec3d values;
2. bake the GeometryPointCloud into a GeometryParticleContainer (check the sources from the shelf script "scatterer/bake_scatterer.py");
3. add a vec3d property on the baked GeometryParticleContainer;
4. write the color values into the newly created property.

Then you should be able to get back the baked support color, from the baked GeometryParticleContainer, using a TextureExtractProperty and the property name.

Let me know if you need more details.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 203
Joined: Wed Jan 13, 2016 10:10 am

Re: Is it possible to access scattered instances color data?

Unread postby jboissinot » Fri Nov 01, 2019 8:40 pm

Hi Anthony,

Thanks for the info and the clarification regarding this. What I meant is that everything works fine if we want to get the color data of instances that are scattered from a point cloud. But sometimes, artists would rather use particle containers for designing a set dress, or even a mix of both. So, what we were trying to achieve is actually to be able to get the color data of instances that are scattered from a particle container. For example, if we want to override the material of a scatterer that is linked to a particle container with an instance color shader so that we can add color variations in its instances, just as we could do with a point cloud, and be able to get their color data values as well.

That's why I was asking but it seems to be a limitation from your explanation unless you would see a workaround that will allow do it with particle containers?

Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Is it possible to access scattered instances color data?

Unread postby nguiard » Mon Nov 04, 2019 3:38 pm

Hi Jeremy,

Sorry but I'm not sure to understand clearly what you are trying to achieve.
Do you want to bake the shading of a material evaluated on a particule container?
Or do you just want to evaluate a texture on a point cloud to add variation over instances?

jboissinot wrote:For example, if we want to override the material of a scatterer that is linked to a particle container with an instance color shader so that we can add color variations in its instances, just as we could do with a point cloud, and be able to get their color data values as well.

Could you precise how you would control the color variation in this case?
Would it be a texture that is evaluated on the point cloud? Or do you have a color property attached to your point cloud?

Thanks
Nicolas Guiard
Isotropix
Head of R&D
User avatar
nguiard
 
Posts: 361
Joined: Fri Jan 25, 2013 11:33 pm

Re: Is it possible to access scattered instances color data?

Unread postby jboissinot » Mon Nov 04, 2019 8:26 pm

Hi Nicolas,

The idea is to add variation over instances and get the color of each instance that we then bake in a point cloud attribute.

To do so, we first create an instance color shader with a procedural shader or texture map that we apply in the override material attribute of the scatterer so that all instances use this shader. This works fine as we do see the instance color variation in the viewport and for both point clouds and particle containers.

Then, as we want to export this color variation to other applications, we use a custom bake tool that bakes all instances in a particle container and set some specific attributes such as instance matrix, source asset, and the instance color as well. Again, this works fine with point clouds but not with particle containers as the get_data() method returns a value of 0 when we evaluate the material on a scatterer that is linked to a particle container as this is part of the limitation we've discussed in this topic.

Therefore, the question was about investigating why we can't evaluate the material of a particle container while the result does work in Clarisse.

Hoping this would help better understand our needs, let me know if it's not though.

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Is it possible to access scattered instances color data?

Unread postby nguiard » Tue Nov 05, 2019 2:59 pm

Hi Jeremy,

Thanks for the detailed explanation, it's much clearer now.

However, how is working your custom baking tool?
I suspect that you are getting the support point cloud of the scatterer in order to call ShaderHelpers::evaluate_support_material() or ShaderHelpers::evaluate_support_texture() on it, right?

If it is the case, it's normal that it's not working for particle containers because they don't have support geometry and these functions are evaluating the material/texture on the geometry that was used as support to generate the point cloud.
It is actually working in the viewport because the material is evaluated on the instances and not on the support of the point cloud.
And if the textures evaluated through instance color nodes are using spatial projection (like planar for instance), then it's also normal that you're obtaining the same result when baking it because it doesn't make any difference between evaluating the texture on the point itself or on its support.

Anyway, have you tried using the ShaderHelpers::evaluate_vertices_texture() function instead? This one is actually evaluating a texture directly on the points, not on their support so it should always work.

Hope it helps.

Cheers
Nicolas Guiard
Isotropix
Head of R&D
User avatar
nguiard
 
Posts: 361
Joined: Fri Jan 25, 2013 11:33 pm

Re: Is it possible to access scattered instances color data?

Unread postby jboissinot » Tue Nov 05, 2019 10:06 pm

Hi Nicolas,

Indeed, our bake tool does get the scatterer geometry support that we use to get the instances color with the evaluate_support_material() method.

Thanks for the info regarding how the material is evaluated on the instances and not the support, and this makes senses actually. I'm not quite sure if I already tried using the evaluate_vertices_texture() method but it's worth exploring and I will let you know if this works.

That being said, this reminds me about another question I wanted to ask: do you think this method could evaluate and return the instance color of combiners that are assigned to an instance color shader? or if this will work for scaterrer instances only?

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Is it possible to access scattered instances color data?

Unread postby nguiard » Wed Nov 06, 2019 9:00 am

Hi Jeremy,

jboissinot wrote:That being said, this reminds me about another question I wanted to ask: do you think this method could evaluate and return the instance color of combiners that are assigned to an instance color shader? or if this will work for scaterrer instances only?


Yes, it should work. There's a point cloud hidden in combiners which is here for some particular cases like the instance color node.

Cheers
Nicolas Guiard
Isotropix
Head of R&D
User avatar
nguiard
 
Posts: 361
Joined: Fri Jan 25, 2013 11:33 pm

Re: Is it possible to access scattered instances color data?

Unread postby jboissinot » Wed Nov 06, 2019 5:50 pm

Ok good to know that this should be supported for combiners as well. I will definitely do further testing with this and let you know how it goes.

Thanks again,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Is it possible to access scattered instances color data?

Unread postby jboissinot » Wed Nov 13, 2019 11:45 pm

Hi,

So I was exploring evaluate_vertices_texture() but I'm a bit confused on how to get the geometry to evaluate for a scatterer that is linked to a particle container, or a combiner instance?

Since a particle container doesn't have a support geometry unlike point clouds have, how can we evaluate the color of a scatterer instance that is linked to a particle container?

My guess was to get the actual geometry of the instance and then use the evaluate_vertices_texture() from any vertex - could use the first vertex index - as all the vertices should be using the same instance color. This is my understanding of it when I'm able to see the color being evaluated on instances in the viewport. While I'm able to get the source combiner of a scatterer instance, I'm still not quite sure how and if this is actually possible to get the actual geometry of the instance?

Also, you mentioned that combiners have a hidden point cloud which can be used to evaluate the instance color but I suppose we'll actually need the instance geometry to evaluate the vertices texture?

As such, I would be curious to know if this is the proper way of doing it and will appreciate any feedback or recommendation regarding this.

Thanks,
Jeremy
jboissinot
 
Posts: 58
Joined: Tue Jan 29, 2019 10:36 pm

Re: Is it possible to access scattered instances color data?

Unread postby nguiard » Mon Nov 18, 2019 4:49 pm

Hi Jeremy,

I'm not sure to understand exactly what you are doing so here is a small project that shows a setup that I guess should correspond to what you want to do:
color_baking.project
(51.54 KiB) Not downloaded yet


On the first image, you have a particle container using a random texture to give color variation to the points.
The second image uses the same particle container but it is using an extract property to read the color from the point cloud (all black at start).
If you run the python script after selecting the particle container and the instance color texture node, it will bake the colors into the point cloud.
Then, you should have the same colors in the second image.

Let me know if it doesn't help.

Cheers
Nicolas Guiard
Isotropix
Head of R&D
User avatar
nguiard
 
Posts: 361
Joined: Fri Jan 25, 2013 11:33 pm

Previous

Return to Scripting