Light position expression freeze

Scripting for After Effects

Light position expression freeze

Postby star+circle on 08/24/2015, 4:29 am

I have a strange expression-related bug with light position I can't wrap my wits around.

My idea is to create some lights (for particular) that travel randomly along one 3D axis at a time, creating a look similar to the Bourne identity titles.

I have this code that works well on a null position, but if I copy it to the light position or even parent a light to a null that has this expression, After Effects freezes on me. I don't understand why.

(Warning: Copying this into light position, if you have a particular layer, will likely freeze your After Effects. Also, this script is not very useful for comps longer than about 30 seconds, as rendering keeps slowing down.)

spd = how fast to move
freq = about how many times per second direction is changed
dir = direction (0=x, 1=y, 2=z)
sign = negative or positive direction

Code: Select all
spd = thisComp.layer("control").effect("speed")("Slider");
freq = thisComp.layer("control").effect("frequency")("Slider");
seedRandom(index+thisComp.layer("control").effect("randomseed")("Slider"), true);
pos_x=transform.position[0];
pos_y=transform.position[1];
pos_z=transform.position[2];
sign = 1;
dir = 0;
frame = thisComp.frameDuration;
for(i=0; i<=time; i+=frame){
if(random()<1/freq){
dir = Math.floor(random(3));
sign = 1-2*Math.floor(random(2));
}
if (dir==0){
pos_x+=sign*spd;
}
if (dir==1){
pos_y+=sign*spd;
}
if (dir==2){
pos_z+=sign*spd;
}
}
pos = [pos_x, pos_y, pos_z];
pos
Last edited by star+circle on 08/24/2015, 4:56 am, edited 1 time in total.
star+circle
 
Posts: 781
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Light position expression freeze

Postby star+circle on 08/24/2015, 4:48 am

Okay, so it is not a problem with the expression and lights. It becomes a problem when I add Particular. That's when it freezes.

I can attach the expression to a null and connect Particular emitter position to it just fine. The problem is, I will need as many copies of Particular as there are nulls if I do it that way, so I would like to use lights with one instance of Particular.

I suspect it has something to do with the For loop, which works fine in itself but seems to throw Particular for a(n endless) loop if attached to a light.
Attachments
light position expression.aep
Light traveling along random 3D axis
(78.41 KiB) Downloaded 278 times
star+circle
 
Posts: 781
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Light position expression freeze

Postby star+circle on 11/9/2015, 8:46 am

Returning to this project after some months, the only solution I could work out was to use Expressions to Keyframes for the null positions and link the lights to them.

I can only assume Particular forces the expressions to be evaluated for all frames, which in this case would have taken hours.

The moral of the story: Don't use expressions that evaluate every preceding frame for lights or nulls that you want to attach particular to.
star+circle
 
Posts: 781
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Light position expression freeze

Postby star+circle on 11/9/2015, 9:25 am

Now that I got it working, here's how it looks:

https://youtu.be/dgKqpaX0sho
star+circle
 
Posts: 781
Joined: 12/6/2014, 3:07 pm
Location: Finland

Re: Light position expression freeze

Postby Gerry Clark on 12/17/2015, 8:10 am

Well, you did a lot of talking to yourself there. It was worth it. Great effect.
Gerry Clark
 
Posts: 148
Joined: 07/3/2009, 6:31 am

Re: Light position expression freeze

Postby greyfin on 01/4/2016, 11:39 pm

Great effect! Didnt know AE could do such!
greyfin
 
Posts: 23
Joined: 03/9/2015, 11:22 am
System Specs: Build: Element x64 2.2.1 (2125)

OS: Microsoft Windows 10 Home Single Language 64-bit 10.0.10240

CPU: Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
RAM: 32720MB

GPU Vendor: NVIDIA Corporation
GPU: GeForce GTX 980M/PCIe/SSE2
GPU Driver: 10.18.13.5900
GPU RAM: 8192MB
GPU Code: 0

CL0: GeForce GTX 980M (100.0%) (GL Interop)

Re: Light position expression freeze

Postby star+circle on 01/5/2016, 3:38 am

Thanks! You can do quite a variety of unusual things with expressions and Particular.

I'm working on some simulations that have Particular in central role, and where I need to control each emitter (light) individually with expressions, which is how I ran into this issue.

On further experimentation, it seems that the problem with expressions/lights/particular lies in the complexity of the expressions, i.e. how many frames it needs to calculate. It works fine with an expression that calculates the average of ten frames, but not with this expression that calculates all frames from the beginning of the comp.

Since nulls and lights work fine with the same expressions before attaching Particular, I would suspect Particular runs into memory issues with more complex expressions. ||-<
star+circle
 
Posts: 781
Joined: 12/6/2014, 3:07 pm
Location: Finland


Return to After Effects Expressions