Driving shader properties on instances

Driving shader properties on instances

jonah.friedman
Community Manager Community Manager
2,640 Views
12 Replies
Message 1 of 13

Driving shader properties on instances

jonah.friedman
Community Manager
Community Manager

I was asked in another place how to drive shader parameters on instances, in the context of how the following image which was produced. 

 

color.JPG

I'm re-asking the question to myself to post the answer publicly. Please feel free to use the thread for discussion as well. 

Jonah Friedman
Bifrost Product Manager
Accepted solutions (1)
2,641 Views
12 Replies
Replies (12)
Message 2 of 13

jonah.friedman
Community Manager
Community Manager
Accepted solution

basic_user_data_1.png

  • In the shader I use AiUserDataColor to get any data I want from the instances. This data can come from the point cloud as shown here - but can also come from user data on the instanced geometry.
  • This shader is applied to the sphere that we're instancing. The "assign material" just removes materials from the grid I'm using as my point cloud.
  • In the graph I am taking the positions of the points and rescaling them to a zero-one range. You can modify these values in the graph with random data or anything else.

 

Here is something slightly closer to the car example, this time I generate random values per point, generate the color gradients as before, and mix them together. That's the attached zip you'll find both these scene files. 

 

basic_user_data_2.png

 

In the case of the Jaguar, this is instanced using render archive instancing but the process is the same. I have a lookdev scene that looks like this:

carpaint_shader.png

That shader reads point_color to set car paint color, and if that data is not available uses the yellow color. I export the car as an Arnold .ass render archive (Arnold: Export Standin). 

 

cars_grid.png

Then I instance that using render_archive_instance with a cube preview, and set colors. The shader inside the render archive picks them up.

 

Jonah Friedman
Bifrost Product Manager
Message 3 of 13

Christoph_Schaedl
Mentor
Mentor

First try with your scene does work great!

Thanks a lot Johna. I managed to layer the color ontop of a grayscale texture for my grass.

layer_point_color.JPG

 

But now i want to use "handpainted" vertexColors to get green colors onto my grass. 

How do i sample the vertexcolors from the plane?

 

 

Here is the scene.

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 4 of 13

Christoph_Schaedl
Mentor
Mentor

I thought i could get the vertexcolor with a "get_geo" node. But it wont work.

 

cmap.JPG

 

 

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 5 of 13

mjcg91
Collaborator
Collaborator

First, you are setting the wrong data type on that get_geo_property, the type on that node should be array<Math::float4>, not a single float3.

Second, you don't even need to use a get_geo_property node. You need to sample you color map property, from your points, using geometry queries, in this case get_closest_locations. Here's a tutorial Paul Smith made the other day:  https://vimeo.com/454418121

One's you've sampled your color map, you can save the result as a geo property on your points, and pass this to the renderer using the method explained by Jonah.

Maxime Jeanmougin - Technical Artist
https://maximejeanmougin.com

Join the Bifrost Addicts community on Discord:
https://discord.gg/bifrost-addicts
0 Likes
Message 6 of 13

Christoph_Schaedl
Mentor
Mentor

hmm... i tried both. Changing the type and the method from Paul today in the morning.

I give it a second go. Thanks now i know it has to work.

----------------------------------------------------------------
https://linktr.ee/cg_oglu
Message 7 of 13

Christoph_Schaedl
Mentor
Mentor

It does work and im able to paint during rendering!!

 

https://youtu.be/4sx_SBXX48A

----------------------------------------------------------------
https://linktr.ee/cg_oglu
Message 8 of 13

Christoph_Schaedl
Mentor
Mentor

Maxime what is the advantage of sampling the color instead of using the get_geo node?

 

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 9 of 13

mjcg91
Collaborator
Collaborator

It's not a question of advantages. In your case it worked because you scattered instances using the mesh's point_position. so the instance's points indices and the vertex color indices lines up.

If you scatter points on anything else other than your mesh's point_position, you setup will break. That's why you need to use geometry queries sample the closest color, and use the returned values to set your instances's color.


Maxime Jeanmougin - Technical Artist
https://maximejeanmougin.com

Join the Bifrost Addicts community on Discord:
https://discord.gg/bifrost-addicts
Message 10 of 13

dangermouse82
Contributor
Contributor
Hi everyone,
I have just been trying this out myself but I'm having issues getting it working and I'm wondering if it is perhaps my low knowledge of Arnold. I feel like I have replicated the steps, created a shader, plugged in an aiUserDataColor given it the attribute name I have set via the set_geo_property node but my render is just coming out white. I know the colour data is there because I have visualized it in the viewport by adding a color attribute to the particles as well.
I guess I'm wondering if there is an extra Arnold step I'm missing? Looking through the documentation it seems normally you need to add a specific parameter to the shape node of the mesh you want the userdata to affect. I had assumed that doing the set_geo_property we were kind of already doing this per point. Is there a simple step in missing?

Thanks
James
0 Likes
Message 11 of 13

Christoph_Schaedl
Mentor
Mentor

Are you on the latest Arnold version. 

Have you tried the sample scenes from Jonah? 

----------------------------------------------------------------
https://linktr.ee/cg_oglu
0 Likes
Message 12 of 13

dangermouse82
Contributor
Contributor

Yes to both 🙂

The only thing I hadn't done was add an assign_material node at the beginning of the graph as I thought this was just to make the plane not render. I removed that in Jonah's scene though and the colours disapeared as well so perhaps you have to add this to have an empty material to start with?

Either way I added this to my graph this morning and now its working! I'll post something later today of a new compound I've been playing around with 🙂

 

Thanks for replying

James

0 Likes
Message 13 of 13

niroumand.reza
Contributor
Contributor

Hi, is it possible to drive Arnold operators per instance to create more variation?

0 Likes