Pate
05-28-2003, 05:03 AM
Hi!
I have a need for a Depth Of Field effect in my animation project, and since I have reflective and transparent objects in the scene I need to use a better DOF than the inbuilt C4D one. Luckily, mdme_sadie has created an XPresso setup that seemed to be just what I needed. However, after some testing I noticed that this setup is not perfectly suited for animation, so I decided to see if I can use mdme_sadie's ideas and create a similar system but geared towards animation. Here is the result, in case anyone else has a need for this.
First of, many thanks to mdme_sadie for the original innovation!
The problems I noticed in his setup are:
- If the camera moves around the scene, the rotation of the pivot object does not follow the movement properly.
- The setup requires 100% Scene Motion Blur strength, which might not be optimal for other aspects of the animation.
This COFFEE setup attempts to address these problems.
---------------- THE COFFEE EXPRESSION START ------------------
main(doc,op)
{
var radius = 0.2; /* Radius of the camera blur movement */
var strength = 0.25; /* Scene Motion Blur strenght (0.25 = 25%) */
var time = doc->GetTime()->GetSecond() * doc->GetFps();
time = (time+0.0001 - int(time+0.0001))/strength;
var rotation = time * PI2 * 7;
radius = radius*(1.0 - time);
var position = vector(sin(rotation)*radius, cos(rotation)*radius, 0);
// println(position);
op->SetPosition( position );
}
---------------- THE COFFEE EXPRESSION END ------------------
See the attached image to see where to put this expression in the scene.
Okay, so how does this work?
The first two lines set up a couple of variables, "radius" sets the radius of the camera rotation (experimentation is required for optimum values), and "strength" tells the Scene Motion Blur strength in the current render settings.
The next two lines take the absolute time of the (sub)frame, and convert it to range 0.0 <= X < 1.0.
Next, we calculate the "rotation" angle, which will rotate the camera 7 full circles over the subframes, and we make the "radius" start with the largest value and spiral towards the centre.
Then we just simply set the camera position using simple trigonometry. This will work if both the camera and the camera's parent have a Target expression pointing to the same object, which will be the focus point. The expression evaluation order should be:
1. parent's Target expression
2. This COFFEE expression of the camera
3. Target expression of the camera
This should be all there is to it, you can freely animate the Target object and the camera's parent object.
I guess I should eventually create a "tips & tricks" section on my web pages...
Pate
I have a need for a Depth Of Field effect in my animation project, and since I have reflective and transparent objects in the scene I need to use a better DOF than the inbuilt C4D one. Luckily, mdme_sadie has created an XPresso setup that seemed to be just what I needed. However, after some testing I noticed that this setup is not perfectly suited for animation, so I decided to see if I can use mdme_sadie's ideas and create a similar system but geared towards animation. Here is the result, in case anyone else has a need for this.
First of, many thanks to mdme_sadie for the original innovation!
The problems I noticed in his setup are:
- If the camera moves around the scene, the rotation of the pivot object does not follow the movement properly.
- The setup requires 100% Scene Motion Blur strength, which might not be optimal for other aspects of the animation.
This COFFEE setup attempts to address these problems.
---------------- THE COFFEE EXPRESSION START ------------------
main(doc,op)
{
var radius = 0.2; /* Radius of the camera blur movement */
var strength = 0.25; /* Scene Motion Blur strenght (0.25 = 25%) */
var time = doc->GetTime()->GetSecond() * doc->GetFps();
time = (time+0.0001 - int(time+0.0001))/strength;
var rotation = time * PI2 * 7;
radius = radius*(1.0 - time);
var position = vector(sin(rotation)*radius, cos(rotation)*radius, 0);
// println(position);
op->SetPosition( position );
}
---------------- THE COFFEE EXPRESSION END ------------------
See the attached image to see where to put this expression in the scene.
Okay, so how does this work?
The first two lines set up a couple of variables, "radius" sets the radius of the camera rotation (experimentation is required for optimum values), and "strength" tells the Scene Motion Blur strength in the current render settings.
The next two lines take the absolute time of the (sub)frame, and convert it to range 0.0 <= X < 1.0.
Next, we calculate the "rotation" angle, which will rotate the camera 7 full circles over the subframes, and we make the "radius" start with the largest value and spiral towards the centre.
Then we just simply set the camera position using simple trigonometry. This will work if both the camera and the camera's parent have a Target expression pointing to the same object, which will be the focus point. The expression evaluation order should be:
1. parent's Target expression
2. This COFFEE expression of the camera
3. Target expression of the camera
This should be all there is to it, you can freely animate the Target object and the camera's parent object.
I guess I should eventually create a "tips & tricks" section on my web pages...
Pate
