效果展示
功能
选择一个图层,使用脚本。会基于当前图层,分离RGB,变成3个图层
知识点
- 撤销组
- 图层选择
- 图层复制
- 图层重命名
- 混合模式
- 图层添加属性
- 更改属性
源代码
/*
AR_AddChromaticAberration
Author: Arttu Rautio (aturtur)
Website: http://aturtur.com/
Name-US: AR_AddChromaticAberration
Description-US: Creates Chromatic aberration setup from selected comp item. Selected item should be a pre-comp or a layer that does not have any effects.
github: https://github.com/aturtur/after-effects-scripts/blob/master/
Written for Adobe After Effects CC 2019 (Version 16.0.1 Build 48)
*/
//@target aftereffects
// 这个函数没用到 不知道干嘛的
function rangeMap(value, minInput, maxInput, minOutput, maxOutput) {
var remapped = (value - minInput) * (maxOutput - minOutput) / (maxInput - minInput) + minOutput
return remapped
}
function ChromaticAberration() {
// 创建撤销组
app.beginUndoGroup("AR_AddChromaticAberration");
// 选择一个图层
var comp = app.project.activeItem;
var selectedLayer = comp.selectedLayers[0];
// 复制2个图层
var red = selectedLayer;
var blue = selectedLayer.duplicate();
var green = selectedLayer.duplicate();
// 重命名为红绿蓝
red.name = "Red";
green.name = "Green";
blue.name = "Blue";
// 设置后2层的混合模式
green.blendingMode = BlendingMode.ADD;
blue.blendingMode = BlendingMode.ADD;
// 分别为R/G/B图层添加属性
var rchan = red.Effects.addProperty("Set Channels");
rchan.property("Set Red To Source 1’s").setValue(1); // 设置 red channel 为'Red'
rchan.property("Set Green To Source 2’s").setValue(10); // 设置 green channel 为 'Off'
rchan.property("Set Blue To Source 3’s").setValue(10); // 设置 blue channel 为 'Off'
var gchan = green.Effects.addProperty("Set Channels");
gchan.property("Set Red To Source 1’s").setValue(10); // 设置 red channel 为 'Off'
gchan.property("Set Green To Source 2’s").setValue(2); // 设置 green channel 为 'Green'
gchan.property("Set Blue To Source 3’s").setValue(10); // 设置 blue channel 为 'Off'
var bchan = blue.Effects.addProperty("Set Channels");
bchan.property("Set Red To Source 1’s").setValue(10); // 设置 red channel 为 'Off'
bchan.property("Set Green To Source 2’s").setValue(10); // 设置 green channel 为 'Off'
bchan.property("Set Blue To Source 3’s").setValue(3); // 设置 blue channel 为 'Blue'
// 获取图层原始缩放
var baseScale = selectedLayer.property("Transform").property("Scale").value;
blue.property("Transform").property("Scale").setValue([baseScale[0]*0.997,baseScale[1]*0.997]); // 降低蓝色图层缩放
red.property("Transform").property("Scale").setValue([baseScale[0]*1.002,baseScale[1]*1.002]); // 提高红色色图层缩放
app.endUndoGroup(); // End undo group
}
ChromaticAberration(); // Run the function