File: dented.sl

package info (click to toggle)
vtk9 9.3.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 267,116 kB
  • sloc: cpp: 2,195,914; ansic: 285,452; python: 104,858; sh: 4,061; yacc: 4,035; java: 3,977; xml: 2,771; perl: 2,189; lex: 1,762; objc: 153; makefile: 150; javascript: 90; tcl: 59
file content (25 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* Listing 16.16  Displacement shader to dent a surface*/
/*
 * dented(): Create a worn surface.
 */
displacement
dented (float   Km      = 1.0 )
{
        float   size      = 1.0,
                magnitude = 0.0,
                i;
        point P2;
        normal Ndiff;

        P2 = transform("shader", P);
        for (i = 0; i < 6.0; i += 1.0) {
                /* Calculate a simple fractal 1/f noise function */
                magnitude += abs(.5 - noise(P2 * size)) / size;
                size *= 2.0;
        }
        Ndiff = normalize(N) - normalize(Ng);
        P2 = P - normalize(N) * (magnitude * magnitude * magnitude) * Km;

        /* correct the normal */
        N = normalize(calculatenormal (P2)) + Ndiff;
}