178 |
|
|
179 |
\section{Tearing} |
\section{Tearing} |
180 |
|
|
181 |
Terms: tear-out, connected/scattered, envelope, spine of the envelope, |
Terms: canvas, tear-out, connected/scattered, envelope, spine of the envelope, |
182 |
``torn edge'' = ?, |
``torn edge'' = ?, |
183 |
``thickness of roughness'' = ? |
``thickness of roughness'' = ?, |
184 |
|
``border'' = ?, |
185 |
|
``section/segment of envelope'' = ?. |
186 |
|
|
187 |
In this section, we introduce the use of non-photorealistic rough, torn shapes instead |
In this section, we introduce the use of non-photorealistic rough, torn shapes instead |
188 |
of the usual rectangular, clipped and framed viewports. |
of the usual rectangular, clipped and framed viewports. |
275 |
Square root XXX refs: stroke scaling in pen drawings? |
Square root XXX refs: stroke scaling in pen drawings? |
276 |
|
|
277 |
|
|
278 |
Edge shapes: attached and sprinkled and intermediates. |
Edge shapes: connected and scattered (and intermediates). |
279 |
TOPOLOGY! |
TOPOLOGY! |
280 |
|
|
281 |
Finally, there is the question of what should happen when the viewport reaches the edge |
Finally, there is the question of what should happen when the viewport reaches the edge |
292 |
and discuss |
and discuss |
293 |
a simple algorithm for a shape with the desired properties. |
a simple algorithm for a shape with the desired properties. |
294 |
|
|
295 |
To start off, assume that we are drawing the torn edge around a given |
To start off, assume that we are drawing the torn edge inside a |
296 |
smooth parametric curve $C = (x(t), y(t))$. The thickness of the roughness of the |
given \emph{envelope}. |
297 |
edge is assumed to be small compared |
The envelope is parametrized as a mapping $E(s,t)$ to canvas coordinates |
298 |
to the curvature of $C$. |
so that $E(s,0)$ and $E(s,1)$ are along the inner and outer edges of the |
299 |
% XXX |
envelope, respectively, and the ripples are contained between these two curves. |
300 |
|
The envelope should not intersect itself. |
301 |
Locally, we can approximate the curve by a point and a normal vector. |
|
302 |
The resulting shape of the edge should be continuous w.r.t.~both the local |
An envelope can be defined with a spine $E(s,1/2)$ and a normal vector |
303 |
point and normal vector. |
$N(s)$ so that $E(s,t) = E(s,1/2) + (t-1/2) N(s)$. |
304 |
|
|
305 |
For the attached edge, we can obtain the final curve by simply shifting the original |
For the connected edge, we can obtain the final curve $C(s)$ by simply shifting |
306 |
smooth curve to its normal direction by a function which only depends on the location $(x, y)$. |
the spine of the envelope along its normal direction by a function |
307 |
|
$0\le f(p)\le 1$ which only depends on the location of the spine: |
308 |
The sprinkled case, on the other hand, can be obtained through a decision process: |
$C(s) = E(s, f(E(s,1/2)))$. |
309 |
again using a function $f(p)$ of location $p$, a given point is {\em inside} the curve, |
|
310 |
iff $f(p) < |p - n_C(p)|$, where $n_C(p)$ is the nearest point to $p$ on the curve $C$. |
The scattered case, on the other hand, can be obtained through a decision process: |
311 |
|
again using a function $f(p)$ of location $p$, |
312 |
|
a given point $E(s,t)$ is {\em inside} the tear-out, |
313 |
|
iff $f(E(s,t)) > t$. |
314 |
|
|
315 |
% XXX: the irregu_gears.jpeg issue should be addressed here, i.e., the shape |
% XXX: the irregu_gears.jpeg issue should be addressed here, i.e., the shape |
316 |
% of the torn edge should ideally not depend on normal in/out direction. |
% of the torn edge should ideally not depend on normal in/out direction. |
317 |
|
|
318 |
Although these algorithms seem different and produce different results, there is |
Although these algorithms seem different and produce different results, there is |
319 |
actually a reasonable generalization which yields to a visual explanation. |
actually a reasonable generalization which yields to a visual explanation. |
320 |
Both algorithms can be represented as a point being inside the final curve if |
Both algorithms can be seen as computing the intersection of (the volume |
321 |
$$ |
above) the surface $(p, f(p))$ and a \emph{cutting surface} $(E(s,g(t)), t)$, |
322 |
f(g(p)) < |p-n_C(p)| |
and then mapping the intersection on the envelope $E(s,t)$ |
323 |
$$ |
using the parametrization of the cutting surface. |
324 |
where $g(p) = p$ for the sprinkled case and $g(p) = n_C(p)$ |
The function $g$ (actually its inverse) defines the profile of the |
325 |
for the attached case. We can immediately define a family of intermediate forms |
cutting surface, with $g(t) = t$ for the scattered case and $g(t) = 1/2$, |
326 |
with |
i.e., a vertical surface, for the connected case. |
|
$$ |
|
|
g_\alpha(p) = \alpha p + (1-\alpha) n_C(p), |
|
|
$$ |
|
|
parametrized by $\alpha$ |
|
|
with usually $0 \le \alpha \le 1$. |
|
|
|
|
|
% \alpha = 1 corresponds to projecting the cutting plane to the paper |
|
|
% \alpha \ne 1 requires stretching the cutting plane before projection |
|
|
% with stretch factor 1 / \alpha (i.e, \infty for \alpha = 0) |
|
327 |
|
|
328 |
A suitable choice for $f$ would be |
A suitable choice for $f$ would be |
329 |
a function with noise at different frequencies, but with lower frequencies |
a function with noise at different frequencies, but with lower frequencies |
330 |
emphasized more, such as turbulence\cite{perlin-noise-intro}. |
emphasized more, such as turbulence\cite{perlin-noise-intro}. |
331 |
|
|
|
% The jagged shape is defined by a surface $(x, y, f(x,y))$, |
|
|
% where $0 \le f(x,y) \le 1$ and $(x, y, 1/2)$ is paper location. |
|
|
% The shape of an edge torn along a line is obtained by intersecting |
|
|
% the surface with a plane cutting through the tearing line. |
|
|
% The intersection is then rotated around the tearing line until |
|
|
% it is horizontal and stretched so that $z = 0$ and $z = 1$ lines |
|
|
% of the cutting plane correspond to the desired maximum positive |
|
|
% and negative displacements of the edge. |
|
|
% |
|
|
% If the cutting plane is vertical, the shape of the torn edge is attached. |
|
|
% If the angle between $z = 1/2$ plane and the cutting plane is |
|
|
% small enough, the plane will cut off maxima of the surface, |
|
|
% producing a sprinkeld shape. |
|
|
|
|
332 |
\section{Hardware-accelerated implementation} |
\section{Hardware-accelerated implementation} |
333 |
|
|
334 |
In the following, we shall concentrate on drawing one section |
In the following, we shall concentrate on drawing one section |
335 |
of the edge, in the unit square, so that $x=0$ is outside and $x=1$ |
of the envelope, in the unit square: $0\le s\le1$, $0\le t\le1$. |
336 |
is inside the tearout. The $y$ coordinate is along the edge. |
It assumed that the position $E(s,t)$ inside the section of the envelope |
337 |
|
and the function $g(t)$ depend linearly on the parameters $s$ and $t$. |
338 |
|
|
339 |
We shall concentrate on OpenGL and NVIDIA extensions (due |
We shall concentrate on OpenGL and NVIDIA extensions (due |
340 |
to their availability in the Linux environment), but |
to their availability in the Linux environment), but |
354 |
|
|
355 |
\subsection{Drawing the shape} |
\subsection{Drawing the shape} |
356 |
|
|
357 |
Recall that the torn shape is defined as the intersection |
Recall that the torn shape can be defined as the intersection |
358 |
of a surface $(x,y,f(x,y))$ and a cutting plane, rotated and |
of a surface $(p,f(p))$ and a cutting plane $E(s,g(t),t)$. |
359 |
stretched around the tearing line to match desired bounds on the paper. |
Using the same parametrization for both surfaces, a point $E(s,t)$ |
360 |
|
is inside the tear-out, iff |
361 |
Because the rotation and stretching are affine operations, |
\begin{equation} |
362 |
the $(x,y,z)$ coordinates of the cutting plane |
f(E(s,g(t))) < t. |
363 |
are affine functions of the corresponding $(x',y')$ |
\end{equation} |
364 |
paper coordinates. |
|
365 |
Thus, OpenGL can interpolate $(x,y)$ as texture coordinates |
Because $E(s,t)$ and $E(s,g(t))$ are both affine functions, |
366 |
and $1-z$ as the alpha component of the primary color |
we can draw the section as a single QUAD with object position |
367 |
of a fragment corrensponding to the paper position $(x',y')$. |
interpolated as $E(s,t)$, texture coordinates as $E(s,g(t))$, |
368 |
The fragment is inside the tearout |
and the alpha component of the primary color as $(1-t)$. |
369 |
if the corresponding point of the cutting plane falls below |
The above inequality can be written as $f(E(s,g(t))) + (1-t) < 1$. |
|
the displacement surface, i.e., if $f(x,y) < z$. |
|
|
This is equivalent to $f(x,y) + (1-z) < 1$. |
|
370 |
The left side can be computed using texture environment mode ADD |
The left side can be computed using texture environment mode ADD |
371 |
and an INTENSITY texture storing $f(x,y)$. |
and an INTENSITY texture storing $f(p)$. |
372 |
The alpha output of the texture environment can then be tested |
The alpha output of the texture environment can then be tested |
373 |
against $1$ using ALPHA\_TEST. |
against $1$ using ALPHA\_TEST to discard fragments outside |
374 |
|
the tear-out. |
375 |
|
|
376 |
|
|
377 |
[GL\_EXT\_texture\_env\_add or OpenGL 1.3 required] |
[GL\_EXT\_texture\_env\_add or OpenGL 1.3 required] |