PDA

View Full Version : PP opacity past locator


blizzaga
01-17-2012, 06:59 PM
Hi, looking for a bit of help with a small expression.
So i have particles moving past a locator and want them to fade, starting when they pass the locator. Here is what i have so far:

vector $pos = nParticleShape1.position; if ($pos.z < faderLocator.translateZ){nParticleShape1.opacityPP = 1 - linstep(0,400,frame);}


But when they pass the locator the particles fade at the same time (past the locator, not before) instead of gradually the further away from the locator they get.
(i have pictures if that bit was a bit unclear)

Any help anyone could give would be great.

Thanks

haggi
01-17-2012, 09:21 PM
Well, lets say you play your animation, and a particle passes the locator at frame 200, then linstep will give you a immediatly a value of 0.5, particles will pop.

vector $pos = nParticleShape1.position;
if ($pos.z < faderLocator.translateZ)
{
nParticleShape1.opacityPP = 1 - linstep(0,400,frame);
}

If you want to use a smooth transition, you need someting to start at the closest position. I prefer a new perParticle attribute like passFrame.

vector $pos = nParticleShape1.position;
if ($pos.z < faderLocator.translateZ)
passFrame = frame;
else
passFrame = 0;

Then you can set your timerange:

opacityPP = 1.0 - linstep(0, 400, frame - passFrame);

Or you can use the distance:

float $dist = $pos.z - faderLocator.translateZ;
opacityPP = 1.0 - linstep(0, 100, $dist);

procanic
01-17-2012, 09:35 PM
this is because your expression fades the particles opacity from 1 to 0 between frame 0 and 400. the expression you're after is probably this:

vector $pos = position;
vector $locPos = <<faderLocator.tx,faderLocator.ty,faderLocator.tz>>;
float $dist = mag($pos-$locPos);
float $maxDist = 50;
opacityPP = linstep(0,$maxDist,$dist);

with this expression your particles will start to fade out as soon as their distance from the locator is less than 50 and will become more opaque again when their distance increases.
adjust the $maxDist for your needs or replace it with a custom float attribute, so you dont have to use the expression editor for adjusting the value. also consider using a smoothstep instead - depending on what effect you're after ...

EDIT: oh, haggi was a lil faster - well, two are better than one ;) - cheers & good night :)

blizzaga
01-18-2012, 01:52 PM
Thanks both for your help. I tried both methods.
The first (Haggi):
vector $pos = nParticleShape1.position;
if($pos.z < faderLocator.translateZ)
nParticleShape1.passFrame = frame;
else
nParticleShape1.passFrame = 0;
float $dist = $pos.z - faderLocator.translateZ;
nParticleShape1.opacityPP = 1.0 - linstep(0,100,$dist)
(just checking its right heh!)
Unfortunatley didn't effect the opacity:
http://img268.imageshack.us/img268/7870/14154583.jpg
(Maybe i am doing something wrong?)

The second (procanic):
kind of worked - the particles did become opaque using max distance (set to 5 in the pic)
http://img715.imageshack.us/img715/3530/79253872.jpg
I have added some annotations to try and make what i am trying to do a bit clearer.
So when the particles pass the locator fading begins then the further away they get from the locator (in the Z) the more opaque they get until their opacity is 0 (over any frame length - thats not important)
Any further help would be great,
Thanks

procanic
01-18-2012, 02:17 PM
alright, now i think i get what you're after. try this as runtime & creation:


vector $pos = position;
float $locPosZ = faderLocator.tz;
float $dist = $pos.z - $locPosZ;
float $maxDist = 10;
opacityPP = 1 - linstep($locPosZ, ($locPosZ + $maxDist), ($locPosZ + $dist));

blizzaga
01-18-2012, 03:39 PM
Thanks for the reply.
no luck. the particles didnt fade with that code in runtime or creation.
I nearly got it with my original expression:
vector $pos = nParticleShape1.position; if ($pos.z < faderLocator.translateZ)

{nParticleShape1.opacityPP = 1 - linstep(0,400,frame);}


http://img16.imageshack.us/img16/4978/mytry.jpg

http://img151.imageshack.us/img151/1424/mytry2.jpg

As you can see above he issue is the particles fade all together when they pass the locator (like it was a per object expression even though it is a per particle expression). Just want them to fade individually once they pass the locator based on their Z position instead of together. so further along the Z more opaque they become.
Can't get my head around it.

procanic
01-18-2012, 04:09 PM
hmm ... the expression worked fine over here.
try this scene and see if it does what you're looking for.
replaced the $maxDist variable with a custom float attribute on the particle shape that you can use to control the fade distance ...

blizzaga
01-18-2012, 06:16 PM
thats strange, cant get it to work on mine.
Yours works though. Must be missing something. I will have an investigate and get back ot you.
Also the attribute being controlled is the fade distance, so when the particles begin to fade. Fading will always begin immidiatley as it reachesthe locator instead of distance from the locator. I was looking to control how long it takes them to fade so the stream will have a long line of a more gradual opacity instead of a short section. Hope that makes sense? What do i need to change to make it the time it takes to fade rather than the distance the fade begins?

procanic
01-19-2012, 03:17 PM
Fading will always begin immidiatley as it reachesthe locator instead of distance from the locator.
not quite ... the fading begins when particles reach the locator and increases with distance from the locator until particles reach the given max distance from the locator ... that's what you asked for in your first post (at least i understood it that way) :

So i have particles moving past a locator and want them to fade, starting when they pass the locator.
________

I was looking to control how long it takes them to fade so the stream will have a long line of a more gradual opacity instead of a short section.
the opacity changes linearly (because of the linstep function) from the locator to the given distance in z behind the locator. maybe the viewport representation is not fully accurate - try rendering a frame & check the alpha to verify the result.
if you want the particles to fade over a longer time then simply increase the distance.

What do i need to change to make it the time it takes to fade rather than the distance the fade begins?
if you want your particles to fade over time, you could use the particle age (lifespan needs to be set to lifespanPP only).
this example would start fading your particles when they're 2 seconds old and they would be fully transparent (& die) at the age of 5 seconds :

// CREATION
lifespanPP = 5;


// RUNTIME
opacityPP = 1 - linstep(2, lifespanPP, age);

this is much simpler but does not involve your locator anymore at all ...

blizzaga
01-20-2012, 11:42 AM
thanks for your reply.
I meant i want fading to always begin at the locators location, so a user can change its location and the particles conform. My fault for not explaining clearly. Sorry.
Unfortunatley because this is part of a bigger tool being developed i can not use lifespan for this expression (as it is needed later on with the tool).
So distance from locator is not important as I want particles to begin to fade the moment they pass the locator. Where in your last expression the amount of fade was always fixed, it was the distance that was the variable. What i want the expression to do is to control how much the particles fade. So fading from 1 to 0 in X amount of time(or frames).
Hope this is a bit more clear.
Thanks for helping me.

procanic
01-20-2012, 02:12 PM
i have no maya available atm so this is kinda blind flying ...

- make a custom per particle float attribute called startTimePP
- make a custom scalar float attribute called fadeTime
- set fadeTime to the desired fade time in frames
- create a custom scalar float attribute called tollerance and set it to 0.5

put this as your creation expression:

startTimePP = 99999;

and this as your runtime:

// read particle position
vector $pos = position;
// get accurate world pos of locator (even with frozen and/or parent transforms)
vector $locPos = `xform -q -ws -rp faderLocator`;
// calulate distance between particle & locator
float $dist = mag($pos - $locPos);
// IF distance between particle and locator is lower than tollerance
// AND startTimePP is still at its initial value (meaning this is the first time the particle gets close enough to the locator)
// THEN set the fading start time for this particle to the current frame
if (($dist<tollerance) && (startTimePP == 99999)) startTimePP = frame;
// fade the particle opacity from 1 to 0 over the given fade time
opacityPP = 1 - linstep(startTimePP, (startTimePP+fadetime), frame);


this should work - not only in the z axis. depending on the speed of your particles you might have to raise the tollerance.
and of course the range of your timeline should be below frame 99999 ;) ...

CGTalk Moderation
01-20-2012, 02:12 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.