View Full Version : how to script a fade out
flore33 08-17-2009, 04:42 PM I have some news papers falling which I have simulating with ncloth. I would like to be able to control their opacity so that at a certain distance from the camera they start to fade out.
I don't really know how to do this.
Could someone give me some advice of how to achieve this?
Thanks
|
|
RuthW
08-17-2009, 09:22 PM
Hi flore33
I would prefer to build a node network to achieve what you ask for, but if you want to do it with an expression then you could writ it like this:
//*********************************************
//Give Name of current camera
//Get cameraPosition
vector $camPosV = `xform -q -ws -t camera1`;
//Give Name of clothmesch
vector $spherePosV = `xform -q -ws -t pSphere1`;
// PosCamera minus PosMesh
vector $lenghtV = abs( $camPosV - $spherePosV);
// Lengh of Vector
float $lenghF = mag($lenghtV);
//Change Expression like this: linstep "your startFade", "your endFade"
float $oppacety = `linstep 18 25 $lenghF`;
// revers
float $oppacetyNeu = ($oppacety*(-1)+1);
// set the transparenty attribute of the shader: "your Shader.transparency. ..."
lambert1.transparencyR = $oppacety;
lambert1.transparencyG = $oppacety;
lambert1.transparencyB = $oppacety;
//*********************************************
Cheers,
Ruth
flore33
08-17-2009, 09:45 PM
I am trying to learn more how to script so thank you very much for your help.
RuthW
08-17-2009, 10:42 PM
Hi flore33
I did not consider that the transform of your clothmesh will not move so better calculate the boundingBox:
//Give Name of clothmesch
float $spherePosFArry[] = `xform -q -ws -bb pSphere1`;
vector $bbmin = <<$spherePosFArry[0],$spherePosFArry[1], $spherePosFArry[2]>>;
vector $bbmax = <<$spherePosFArry[3],$spherePosFArry[4], $spherePosFArry[5]>>;
vector $spherePosV = `hermite $bbmax $bbmin <<0, 0, 0>> <<0, 0, 0>> 0.5`;
instate.
Cheers,
R
flore33
08-17-2009, 10:45 PM
Hi RuthW
Thank you so much
CGTalk Moderation
08-17-2009, 10:45 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.