Curl Noise Slides
Curl Noise Slides
Noise
Peter
Werner
Overview
• Take
a
look
at
end
results
• Cover
some
background
stuff
• Look
at
2D
case
• Some
more
background
stuff
• Look
at
3D
case
• General
computaBon
consideraBons
Curl
Noise
• Move
a
bunch
of
parBcles
around
• Used
for
smoke,
fire,
fluid
effects
• RelaBvely
inexpensive
to
calculate
• Especially
compared
to
other
methods
of
fluid
simulaBon
• Also
just
generally
looks
kinda
cool
ObjecBves
• Aim
is
to
understand
what
the
curl
operator
does
• Can
go
off
and
read
other
peoples
papers/
code
• Not
a
mathemaBcally
rigourous
talk
• Interludes
Bme
for
quesBons
Background
• Curl
is
a
mathemaBcal
operator
like
+,
-‐,
etc
• Its
input
is
a
vector
field
• Its
output
is
a
divergence
free
vector
field
• Measure
of
rotaBonal
force
• In
our
case
the
input
will
be
Perlin
Noise
• We
will
use
the
output
to
move
parBcles
around
• A
divergence
free
vector
field
will
stop
our
parBcles
smooshing
together
too
much
Perlin
Noise
• Used
whenever
you
want
something
that
varies
but
not
completely
randomly
• Takes
x/y/z
locaBons
• Gives
values
from
[0,
1]
or
[-‐1,
1]
• Low
frequency
noise
varies
from
high
values
to
low
values
slowly
• High
frequency
noise
varies
quickly
• Common
to
sum
layers
of
noise
at
different
frequencies
Perlin
Noise
Low
frequency
High
frequency
Sums
of
frequencies
Vector
Field
• We
use
Perlin
noise
as
our
vector
field
• For
a
parBcle
at
a
certain
(x,
y)
posiBon
• Evaluate
the
noise
funcBon
at
(x,
y)
to
get
a
value
n
• Make
our
velocity
vector
v
=
(n,
n)
• Next
parBcle
posiBon
=
(x,
y)
+
(n,
n)
Perlin
noise
vector
field
Curl
of
same
field
Curl
in
2D
• PotenBal
Field
(perlin
noise)
ψ = (ψ1, ψ2 , ψ3 )
• Instead:
F = (x, y, z)
• In
2D:
F = (x, y)
• Some
point
P = ( x1, y1 )
# ∂x ∂y &
• Curl:
v(x, y) = 1
% ,− ( 1
$ ∂y ∂x '
• v(x,
y)
is
the
output
of
the
curl
operator.
• It
has
a
vector
value,
so
x,y
in
2D,
x,y,z
in
3D
• The
derivaBve
terms
are
rates
of
change.
Curl
in
2D
• Don’t
worry,
no
calculus
is
required
∂x1
• What
does
this
term
∂y
really
mean?
• We
want
the
rate
of
change
in
x
• At
a
given
point
x1
• On
the
y
axis/relaBve
to
y
• i.e.
how
much
the
x1
value
would
change
as
the
y
values
change
around
it
• Just
a
regular
number
as
its
value
Curl
in
2D
∂y1
• Similarly
for
∂x
• How
much
do
y
values
change
around
some
point
y1
…
• As
the
values
of
x
change?
• What’s
the
rate
of
change
in
y
relaBve
to
x?
• How
much
does
y
change
as
x
changes?
• Gradient
=
derivaBve
=
rate
of
change
CompuBng
the
Curl
• Step
1:
Calculate
the
gradients
• Step
2:
Jigger
the
values
round
to
fit
curl
definiBon
# ∂x ∂y &
• e.g.
Curl
definiBon
v(x, y) 1
= 1
% ,− (
$ ∂y ∂x '
•
Step
1:
a =
∂x
1
∂y
, b =1∂y
∂x
•
Step
2:
v(x, y) = (a, −b)
# ∂x ∂y &
v(x, y) = % 1 , − 1 (
$ ∂y ∂x '
Finite
Difference
Gradient
• But
how
to
compute
the
gradients?
• Can
be
done
using
calculus
using
simplex
noise
• Much
easier
way
is
to
approximate
the
rate
of
change
using
a
method
called
finite
differences.
• Super
easy,
uses
primary
school
math
Finite
Differences
• We
have
a
mystery
funcBon
we
want
to
approximate
a
derivaBve
for
Finite
Differences
• Have
some
2D
data
with
x
and
y
values
• Want
to
approximate
the
rate
of
change
of
y
as
x
changes
(i.e.
dx
)
at
say
x
=
5
dy
dy
• We
know
its
derivaBve
dx
= 2x
•
Step
1:
1 1
a =
∂x
∂y
, b =
∂y
∂x
•
Step
2:
v(x, y) = (a, −b)
# ∂x ∂y &
v(x, y) = % 1 , − 1 (
$ ∂y ∂x '
CompuBng
the
Curl
ofVec2f
ComputeCurl(float
x,
float
y)
{
float
eps
=
1.0;
float
n1,
n2,
a,
b;
n1
=
noise(x,
y
+
eps);
∂x1
a=
n2
=
noise(x,
y
-‐
eps);
∂y
a
=
(n1
-‐
n2)/(2
*
eps);
n1
=
noise(x
+
eps,
y);
∂y1
n2
=
noise(x
-‐
eps,
y);
b=
∂x
b
=
(n1
-‐
n2)/(2
*
eps);
ofVec2f
curl
=
ofVec2f(a,
-‐b);
# ∂x ∂y &
v(x, y) = % 1 , − 1 (
return
curl;
$ ∂y ∂x '
}
Recap
• Perlin
Noise
• Vector
Fields
• Curl
in
2D
• CompuBng
gradients
• CompuBng
curl
in
2D
MathemaBcal
Fact
• cosine
can
be
used
to
approximate
the
normal
distribuBon
1+ cos ( x )
f ( x) = , x ∈ ( −π , π )
2π
Curl
in
3D
" δψ3 δψ 2 δψ1 δψ3 δψ 2 δψ1 %
• Bridson:
v ( x, y, z ) = $
# δy
− , − , −
δz δz δ x δ x δ y &
'
• NoBce
δ y − δ z 1
Δx 1
=
δz δ y
• And
Δz
=
δδ
yx
−
δδ
xy
all
happening
in
the
x/y
plane
1 1