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:age
particle:lifetime
particle:location
particle:size
particle:velocity
particle:angular_velocity
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
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
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.