Animacion 3D
Animacion 3D
Animacion 3D
This guide is an introduction to some of the parameters within deforum that can be
controlled and altered using math expressions and functions. It aims to assist intermediate
and advanced users of animation scheduling, by providing examples and descriptions of
use cases. MATH functions are not mandatory in the functionality of deforum’s
parameters, and only serve as a dynamic tool to better enhance manipulation of values
during an animation.
The specific tool documentation that has been added to Deforum V05 can be found here:
NumExpr 2.0 User Guide — numexpr 2.6.3.dev0 documentation
1.)
Parameters that can be altered using MATH:
In deforum, any parameter that accepts a string format of instructions (type = `string`) can
be altered using a math expression, a schedule, or a combination of both. These
parameters are typically denoted with 0:(0) where the preceding number is the frame, and
the parentheses number is the value to be enforced during the designated frame. In the
example of 0:(0), the render will reference frame0 and assign 0.0 as its value indefinitely
unless instructed otherwise.
Parameters that are controlled by strings are as follows: angle, zoom,
translations_xyz, rotations_3D_xyz, perspective_flips_theta,phi,gamma,fv , noise_schdule,
strength_schedule, and contrast_schdule.
Scheduled values will “tween” linearly between two instructional elements in a
string. In the example of 0:(-2), 100:(4) The render will start at frame0 with a value of -2
and rise up over time, increasing its value to 4 by the time it reaches frame100. During
frame50 of that render, we would observe a value of 1.0 being enforced, since the
midpoint between frame0 and frame100 falls on the line drawn between the two values at
1.0
When using math expressions however, the “tweening” follows an approximation of
values within elements of the string in such a way that a curve is drawn between values.
Consider the following example: 0:(sin(t)), 100:(4) The function at frame 0 in this case is a
sine wave, where “t” represents the frame number. The value at frame 0 will start to
calculate the sin(t) to produce its initial value, and quickly fluctuate causing peaks and
valleys, while it slowly climbs to a constant value of 4 by frame100. We can observe an
effect of the sine wave starting at full strength, and finally losing all amplitude 100 frames
later - a “ripple” effect.
If a math expression is used as the sole element of a string, it will indefinitely
calculate and produce its value for as long as it is defined, without interruption. If at any
point, a parameter falls out of the range of acceptable values, the render will adhere to the
next available calculation of that function. (ex. A value approaches infinity, asymptotic or
undefined) This can sometimes be a desired effect if a “pulsing” or “sawtooth” function is to
be achieved.
2.)
How MATH expressions affect the animation:
Many combinations and complex functions can be expressed during an animation
schedule to achieve patterns and motion that would otherwise take extremely long strings
of manual information to achieve. Consider a sine function, where previously, we would
have to enter in each frame’s respective value to simulate a waving pattern. The longer
our animation, the more frame instructions we’d have to manually enter. Now, with MATH
functions, we can populate a never-ending list of instructions simply contained in one
expression. The method that we use is to reference the variable “t”. When we use that
variable in our math statements, a calculation is performed such that “t” = the current
frame number. Since the frame number steadily increases in increments of +1, we can
now define an “x axis”. With that aspect in place, we can use “t” to alter the value across
the “y axis” in sequence. A frames (time) progresses forward, the MATHs performed on “t”
will allow us to control what values are to be enforced at that exact snapshot in time. In the
default notebook of deforumV05, the “translation_x” schedule is defined as:
0:(10*sin(2*3.14*t/10)) We can see “t” along with a sine wave (sin) being performed. This
will cause the image to translate left and right over time. We will examine in more detail
how this function works.
3.)
Anatomy of a simple MATH expression:
We saw the expression 0:(10*sin(2*3.14*t/10)) being used in the default notebook of
deforumV05. Let’s observe how it is “driving” our parameter. When we use the most
simple of math expressions 0:(t) we define the value at any frame to be equal to its frame
number. However, this value will soon rise off into unusable values above any
recommended range within the animation parameters. At frame0, we start at 0, by frame1,
we’re at 1, and by frame 200, we’re at 200 - so on and so forth. So a method of
“containing” this value must be expressed somehow, as to prevent the number from flying
off into infinity. The 2 best methods are sine/cosine functions as well as modulus functions
(more info on modulus later).
So, in our example, we can see a “sin( )” being used. If we were to take the sine of
our frame number, or “sin(t)”, we’d generate a wave shape. The value would swing up and
down quickly as each frame was calculated.
While this does keep our value from ever increasing - it is not enough to control our
parameter in a realistic way. A simple sine wave is too fast, shallow and rapid. So our
example includes more expressions being performed. We see that a familiar value 3.14 is
multiplied by “t”. This causes the period of our sine wave to fall on integers (approximately)
at its wavelength. More specifically, this wavelength is 2. So our example goes further to
multiply that variable by 2 also. When we take the sin(2*3.14*t) , we yield a wave that has
a period of 1 and an amplitude of 1 (it peaks and valleys between -1 and 1). All that is left
is to add math that will control how high the value should bounce(amplitude), and how
often(frequency). So our example finally multiplies the whole expression by 10, and also
divides “t” by 10. This results in a wave that will alternate between +10 and -10 and repeat
every 10 frames. → cont on next page
->cont.
But what if we wanted even MORE control. We notice our example suffers the
property of always passing through 0 as its baseline - but what if we wanted the baseline
to start at -3? We just need to take the whole expression, and subtract 3 from it, and our
new baseline is established. 0:(10*sin(2*3.14*t/10)-3) Now our wave bounces between 7
and -13, keeping its amplitude and frequency intact. More functionality can be added as
we build our expression, including exponents, cosine properties, and negative amplitudes.
4.)
Advanced Expression to drive your parameters
When constructing a complex schedule of effects during your animation, more control and
special techniques will yield a better dynamic result. Let’s examine a specific use case.
The artist wants to use a constant value of 0.8 as their strength schedule. However, they
wish they could have more detail appear in their animation. A value of 0.45 is great for
adding new enriched content to a scene, but it causes very little coherency. The artist
decides that they should only introduce the value of 0.45 periodically about every 25
frames, yet keep it 0.8 for most of the sequence. How should the artist express this using
MATHs?
Let’s observe the following solution, then discuss.
0:(-0.35*(cos(3.141*t/25)**100)+0.8)
A massively powerful function, with a simple elegance to it. Our artist uses this function in
their example to achieve the desired result. At frame 0 and all frames after, a value is
being calculated. In this expression we’re selecting a cosine function (cos) to allow our
wave to have small periodic dips instead of peaks. The double asterisk acts as an
exponent function and brings the cosine to the 100th power, tightening the dips into small
indents along the timeline. The addition of +0.8 sets the baseline at 0.8 which the artist
agreed was desirable for the animation, and starts the function with -0.35 knowing that it
will dip below the established baseline from 0.8 down to 0.45 as expected. An
approximation of pi is being used again (3.141) to align the frames to integers, and t is
being divided by 25 to enforce the dip to occur only at frames that are multiples of 25. Our
artist has achieved the schedule using one expression that will be calculated for the
duration of the animation frames.
Remember that expressions can be changed along the schedule to “tween” along the
frames.
0:(10*sin(2*3.14*t/10)), 50:(20*sin(4*3.14*t/40)), 100:(cos(t/10)) is an acceptable format.
Another useful tool is the modulus function. Represented by “%” is typically used to
calculate the remainder of a function. In deforum, we use modulus to affect “t” frame count
as a repeating limiter. Consider the following syntax:
translate_3D_z: 0:(0.375*(t%5)+15)
If “t” is the frame count, it would increase indefinitely, however in our example, we’ve set
the modulus to 5. This means as the frame rises (01,2,3,4,5,6,7,8… etc) the value of “t”
will repeat a sequence of 0,1,2,3,4,5,0,1,2,3,4,5,0,1… etc, without ever increasing over 5.
This graphically produces a sawtooth wave. In order to bend the “blades” of the sawtooth
to stretch over time, we multiply by 0.375. This acts as the slope of each line. A multiplier
of 1 would yield a 45° line. Higher multipliers will increase the frequency even further, while
numbers closer to 0 will lay the line near flat. Since we’re controlling the Z translate in 3D
mode, we want our baseline to be at 15, hence our addition of it at the end of the syntax.
The overall effect of this parameter causes our animation to consistently zoom forward, yet
with pulses, similar to the perspective of nodding your head to music while riding in a car.
Many more clever approaches can be used to create elaborate functions and animations,
as well as just simplifying the instruction of long frame counts. There are tools that exist
such as graphing calculators to better help envision what a function would look like
linearly. This can be simulated by the format of y = x instead of deforum’s 0: (t) where “y” is
the frame, and “x” is t
This calculator can be used to solve similar functions, yet some syntax may vary.
Desmos | Graphing Calculator
We encourage the users to share their experiences with formulas and expressions, since
there will be endless discoveries with how MATHs can work in unique applications.
WHAT IS IT?
Deforum Stable Diffusion (Design Forum) builds upon Stability
AI’s Stable Diffusion Model and add’s a lot of additional functionality
not seen in the default notebook by Stability. Since Stability AI (blog
post) has released this model for free and commercial usages a lot
of amazing new notebooks have come out that push this technology
further.
Deforum Stable Diffusion (DSD) as of this writing has additional
features such as animation in the form of 2D and 3D, Video Init, and
a few other masking options.
The image above was created with DSD using just the text prompt:
“ultra detailed portrait Burning Man festival in the Black Rock Desert,
steampunk burning man artwork, night time with fractal clouds,
volumetric lighting, cinematic portrait”
“The model itself builds upon the work of the team at CompVis and
Runway in their widely used latent diffusion model combined with
insights from the conditional diffusion models by our lead
generative AI developer Katherine Crowson, Dall-E 2 by Open
AI, Imagen by Google Brain and many others. We are delighted that
AI media generation is a cooperative field and hope it can continue
this way to bring the gift of creativity to all.
IMPORTANT
GETTING STARTED
Launch the Google Colab Notebook here.
Deforum Stable Diffusion (DSD) (currently version 0.4) is
intimidating and inscrutable at first. Just take it in small steps and
you’ll make progress.
DSD does not come with the stable diffusion model ready to
download and you will have to do this process manually.
**This may change from time to time so please look at the notebook
on how to properly get the model.
When you launch the DSD notebook in Colab, it’s already set up with
defaults that will generate a lighthouse image like the one above.
Before changing any of the settings, you should just run
all (Runtime\Run all) to confirm everything’s working. Colab will
prompt you to authorize connecting to your google drive, and you
should approve this for DSD to work properly.
QUICK START
After the initial setup, you can start creating your own
images! There are many options, but if you want to just type
phrases and use the default settings to generate images:
Deforum Stable Diffusion Prompts
• Initialize the DSD environment with run all, as described just
above. Interrupt the execution.
• Scroll to the bottom of the notebook to the Prompts section
near the very bottom of the notebook. Take careful note of the
syntax of the example that’s already there. Replace the
sentences with your own text prompt.
• Remember prompts are for single images and you can do one
after the other and animation_prompts are for animation mode
which we will get into later.
• Click the run button for the prompts cell. This will update the
text prompt for the next run.
• Click the run button next to ‘Do the Run!’
• Watch the magic happen and it try to build images based upon
your prompts.
New to v0.5 are prompt weights and the ability to use a prompt from
a model checkpoint. These are the examples taken from the
notebook.
In DSD, prompts are set at the very bottom of the notebook. Prompts
can be a few words, a long sentence, or a few sentences. Writing
prompts is an art in and of itself that won’t be covered here, but the
DSD prompts section has some examples including the formatting
required.
THOUGHT PROCESS
For still frame image output, numbers are not to be placed in front of
the prompt, since no “schedule” is expected during a batch of
images.
The above prompts will produce and display a forest image and a
separate image of a woman, as the outputs.
eggs:`cos(6.28*t/10)`, bacon:`-cos(6.28*t/10)`
You can go back and forth with stuff in just one line of text!
https://user-images.githubusercontent.com/14872007/193699307-
dc0994ff-fe9e-4e27-bc67-e6c190dcea0b.gif
SETUP
As stated before the notebook requires an Nvidia GPU to run and
also that you have downloaded the current stable diffusion model
and put it in the proper folder that your notebook references.
SETUP ENVIRONMENT:
PYTHON DEFINITIONS:
ANIMATION
Until this point, all of the settings have been related to creating still
images. DSD also has several animation systems that allow you to
make an animated sequence of stable diffusion images. The frames
in the animation system are created using all of the same settings
described above, so practice making still images will help your
animated images as well.
ANIMATION_MODE
PERSPECTIVE 2D FLIPPING
https://user-images.githubusercontent.com/14872007/190828601-
43dd60d0-2619-455b-8ba6-87840751b818.gif
ANIMATION SETTINGS
MOTION PARAMATERS
COHERENCE
Example:
3D DEPTH WARPING
https://user-images.githubusercontent.com/14872007/193702526-
be62d3c8-de3d-4f0f-89fe-cd9db851e5f2.gif
https://user-images.githubusercontent.com/14872007/193700941-
d0674cc6-f5f0-4597-8ecf-7ffef5cdd21c.gif
FYI: video input does not work with cadence. It ignores your cadence
values.
INTERPOLATION
• interpolate_key_frames, selects whether to ignore prompt
schedule or _x_frames.
• interpolate_x_frames, the number of frames to transition thru
between prompts
when interpolate_key_frames = true, then the numbers in front of the
animation prompts will dynamically guide the images based on their
value. If set to false, will ignore the prompt numbers and
force interpolate_x_frames value regardless of prompt number
RESUME ANIMATION
• resume_from_timestring, instructs the run to start from a
specified point
• resume_timestring, the required timestamp to reference when
resuming
Currently only available in 2D & 3D mode, the timestamp is saved as
the settings .txt file name as well as images produced during your
previous run. The format follows:
yyyymmddhhmmss – a timestamp of when the run was started to
diffuse.
ANGLE:
ZOOM:
TRANSLATION_X, TRANSLATION_Y
In 2D mode
3D ANIMATION SETTINGS
Recall that in 3D animation mode, there is a virtual 3d space create d
from the prior animation frame, and a virtual camera is moved
through that space.
ROTATION_3D_X:
ROTATION_3D_Y:
ROTATION_3D_Z:
In 3D Mode ONLY
RUN SETTINGS
After your prompt and settings are ready, visit the Do the Run! code
cell near the bottom of the notebook, edit the settings, then run it.
DSD will start the process, and store the finished images in your
batch folder.
LOAD SETTINGS
Users may now select an “override” function that will bypass all
instructions from the notebook settings, and instead run from a
settings.txt file previously saved by the user. This function is reverse
compatible to v04. This feature does not auto-populate settings into
your notebook, however it directly runs the instructions found within
the .txt file.
Resolution of 512×832
Stable Diffusion Double Head
Let us know what works well for you.
SAMPLING SETTINGS:
Considering that during one frame, a model will attempt to reach its
prompt by the final step in that frame. By adding more steps, the
frame is sliced into smaller increments as the model approaches
completion. Higher steps will add more defining features to an
output at the cost of time. Lower values will cause the model to rush
towards its goal, providing vague attempts at your prompt. Beyond a
certain value, if the model has achieved its prompt, further steps will
have very little impact on final output, yet time will still be a wasted
resource. Some prompts also require fewer steps to achieve a
desirable acceptable output.
Your first frame will, however, yield all of the steps – as the formula
will be in effect afterwards.
PROMPT SETTINGS
BATCH SETTINGS:
Settings Details:
INIT SETTINGS:
You can use your own custom images to help guide the model to try
to mimic more of the look and feel from the image you want.
Examples to come showing off the init images, init videos and mask
features!
MISCELLANEOUS
I want to run DSD on my super powerful home PC with the wicked
smart graphics card.
RESOURCES
Here are some useful links:
DEFORUM STABLE DIFFUSION NOTEBOOK
https://colab.research.google.com/github/deforum/stable-
diffusion/blob/main/Deforum_Stable_Diffusion.ipynb
DISCORD
MODIFIERS
• CFG Studies
• Sampler Studies
• Sampler / Step Count Comparison with timing info
• Stylistic Lighting Studies
• Math Guide for Animation Settings
ARTIST STUDIES