Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
salival
Topic Author
Posts: 1
Joined: Mon May 09, 2011 4:53 am

Fade a layer in and out based on its start and end points.

Fri Nov 04, 2011 6:30 am

This expression fades the layer's opacity based on its start and end points.

The duration of the fade can be set individually for the fade in and fade out, either in seconds or frames.
It respects the initial value of the opacity. If you had set the opacity of the layer to 50% it will fade from 0% to 50%.

Apply the following expression controls to the layer you want to fade:
- Checkbox: "Time in frames"
- Checkbox: "Fade in"
- Checkbox: "Fade out"
- Slider: "Fade in time"
- Slider: "Fade out time"

Add the following expression to the same layer's opacity.

framerate = 1/thisComp.frameDuration; // framerate
target = value;

if (effect("Time in frames")("Checkbox")==true){
   //Time in frames is checked
   fadeInTime =effect("Fade in time")("Slider")/framerate;
   fadeOutTime = effect("Fade out time")("Slider")/framerate;
}else{
   //Time in frames is unchecked
   fadeInTime =effect("Fade in time")("Slider");
   fadeOutTime = effect("Fade out time")("Slider");
}


if (effect("Fade in")("Checkbox")==true && effect("Fade out")("Checkbox")==false){
   //if only Fade in is checked
   Math.min(linear(time,inPoint,inPoint + fadeInTime,0,target),target);
}else if(effect("Fade in")("Checkbox")==false && effect("Fade out")("Checkbox")==true){
   //if only Fade out is checked
   Math.min(target,linear(time,outPoint - fadeOutTime,outPoint,target,0));
}else{
   //if both fade in and fade out checkboxes are either checked or unchecked
   if ( fadeInTime == 0 ){
      Math.min(target,linear(time,outPoint - fadeOutTime,outPoint,target,0));
   }else{
      Math.min(linear(time,inPoint,inPoint + fadeInTime,0,target),linear(time,outPoint - fadeOutTime,outPoint,target,0));
   }
}


edit: fixed the issue where the layer would disappear when fade in time was set to 0 and either both or none of the fade in/fade out checkboxes were ticked.
Attachments
autofade_around_in_out.zip
Zipped preset
(1.9 KiB) Downloaded 520 times

Who is online

Users browsing this forum: No registered users and 1 guest