question

Zeno Pelgrims avatar image
Zeno Pelgrims asked ·

nParticles per-point attribute access in shader

Hi, I'm trying access particle data from within an OSL shader. For example, I would like to store some vector attribute per-point and query that at shading time.

Is this possible? Pretty new to working with particles in OSL and can't find much info about it.

I'm finding following info in blender's osl implementation, is there an equivalent in arnold's implementation?

particle:index
Particle instance number.
particle:age
Particle age in frames.
particle:lifetime
Total lifespan of particle in frames.
particle:location
Location of the particle.
particle:size
Size of the particle.
particle:velocity
Velocity of the particle.
particle:angular_velocity
Angular velocity of the particle.



Edit: it seems I can read some per-particle attributes using getattribute("worldPosition", ...). All I have to do is export them in the nParticle shape node under Export Attributes. I can't seem to get this to work for "worldBirthPosition" though. Any ideas?

Thanks, Zeno

shadingosl
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Mads Drøschler avatar image
Mads Drøschler answered ·

in MAX:

getattribute


paID = int value you can shuffle around as you like, birth index. Can be used to populate vertex number in array or whatever.
paLife = Life of the particle
mtlID = material ID
uv_0 = mapping channel 0 ( a vector ) <- here we can generate all above ids and a ton more.

Position vector exit the particle event to a UVW channel and extract the channel to initiate controller for shader.
- Velocity the same, exit to an unused 3 component vector channel again and catch eg. uv_0 if that is where you store the vector.
- Magnitude velocity just take square root of a^2+b^2+c^2

- I guess size can go on a float too, but it all depends if you can exit a stream to a uv_x because that makes things super simple.

So, there are 2 main routes to go, direct attribute calls with getattribute, or signing data streams to mapping channels and catch with an osl shader.

Signing data streams is by far most flexible as you can totally set the rules up for what kind of radio stream you want to inject into the initial shader that catches the signal.

So I hope your particle generator, or something you can wrap around the particle generator, can generate data streams directly to Vertex channel data sets, or whatever its called in your app. Then things become super trivial to manage.

Here I put a particles on each vertex in the particle generator, extract paID int and feed to an OSL digital display number shader, I assign pr particle. So that the number display actually displays the vertex on the quad plane beneath it in correct sequence.
I add in +1 since index starts at 0 in line 12.

You will notice I set the Digit output to zero and that just enabled the counting of digits and feeds that to the display shader automaticly. its just a trigger.

And here is the pr. particle location ID in world space ported from the particle generator, to uv_0 channel which is caught by a shader chain and printed to the closure output -> back to particles to give them a solid color based on location, color is vector, so we can now process the vector data in OSL like normal 3 component vector handling.
I use Arnold data node, but the same apples for the OSL code used.


gg.png (133.7 KiB)
ff.png (152.3 KiB)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Aaron Ross avatar image
Aaron Ross answered ·

Hey @Zeno Pelgrims -- sorry to hijack your question, but I couldn't find any other way to contact you. Is there any way to use the existing POTA lens shader in 3ds Max? I set the arnold plugin path and can access other custom shaders in that folder, but not POTA. Thanks

1 comment Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

send me an email instead please: zenopelgrims at gmail dot com

0 Likes 0 · ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.