Friday, 13 June 2014

Passing ageNormalized to Arnold

Passing the ageNormalized attribute from Maya particles to an Arnold shader is extremely useful and extremely not documented in Solid Angle's user guides. I will show two ways to do it - one is my own recipe, and one of from Pedro Gomez from the MtoA list.

Here is the problem:


I would like to pass my particle's ageNormalized to a shader, rather than age.

As you may be able to see from the screenshot, passing age sort of works, but not quite. Some of the oldest particles have reached the end of the colour ramp and wrapped around to the beginning of the ramp again.

If I try just typing in ageNormalized into the Export Attributes, it does not work at all, Arnold just reads the first value of the ramp and applies that value to every particle.

Is there a smart workaround for this? Can I put age/lifespanPP somewhere in the shader? But where? And talking of export attributes, can I put more than one attribue in there (eg age, lifespanPP, velocityPP)? 







First is my method: 

1. Add a new Dynamic Per-Particle Attribute, userScalar1PP, say.

2. Adding the runtime expression:

nParticleShape1.userScalar1PP=nParticleShape1.age/nParticleShape1.lifespanPP;


3. Put userScalar1PP into the Export Attributes

4. Connect the particle sampler to the shader ramps, but use the UserScalar1PP attribute instead of age.






Second is Pedro's way - more correct and elegant:

Export both the age and lifespanPP and catch those in two aiUserDataFloat nodes. Then use a Multiply/Divide node and divide the age/lifespanPP. Then pipe that into your shader. This is a much better as it does not require an expensive runtime expression to be cached.



Here is the shader: one ramp for Colour and one for Opacity.




And the answer is yes, you can export any number of attributes, so long as they are seperated by a space in the Export Attribues box.







A sample scene is available in Maya 2014 MA format

2 comments:

  1. Hi! This tutorial is awesome but I seem to be missing a step. My particles always render as white. Any idea? I followed Pedro's steps.

    Thank you!

    ReplyDelete
  2. Works very good, thanks for the trick!!

    ReplyDelete