~ubuntu-branches/ubuntu/breezy/aqsis/breezy

« back to all changes in this revision

Viewing changes to shaders/brickbump.sl

  • Committer: Bazaar Package Importer
  • Author(s): Will Newton
  • Date: 2004-12-07 20:06:49 UTC
  • Revision ID: james.westby@ubuntu.com-20041207200649-fccswkrvp4oc8lmn
Tags: upstream-0.9.3
ImportĀ upstreamĀ versionĀ 0.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * brickbump.sl -- displacement shader for bricks.
 
3
 *
 
4
 * Description:
 
5
 *   Makes displacements for a wall of bricks.  This is the companion
 
6
 *   shader to the surface "brick" shader.  The parameters work exactly
 
7
 *   the same.  Of course, you can use it with any surface shader, and
 
8
 *   in fact matte or plastic gives those nice white cinder block walls.
 
9
 *   However, if you do use it with "brick", the parameters MUST match,
 
10
 *   or your bricks will look very strange.
 
11
 * 
 
12
 * Parameters:
 
13
 *    brickwidth                Width of a brick (in st space)
 
14
 *    brickheight               Height of a brick (in st space)
 
15
 *    mortarthickness           Thickness of the mortar (in st space)
 
16
 *    rowvary                   How much does each row shift?
 
17
 *    jagged                    How much do bricks deviate from squares?
 
18
 *    pitting                   The amplitude of the "pits" on the face of
 
19
 *                                 the bricks.
 
20
 *    pockfrequency             The st frequency of the pits.
 
21
 *    groovedepth               The depth of the grooves between bricks.
 
22
 *
 
23
 * AUTHOR: written by Larry Gritz, 1992 (and subsequently modified)
 
24
 *
 
25
 * $Revision: 1.1 $     $Date: 2001/06/07 19:00:13 $
 
26
 *
 
27
 */
 
28
 
 
29
 
 
30
 
 
31
#include "noises.h"
 
32
#include "patterns.h"
 
33
 
 
34
 
 
35
 
 
36
displacement
 
37
brickbump ( float jagged = 0.006;
 
38
            float brickwidth = .25, brickheight = .08;
 
39
            float mortarthickness = .01;
 
40
            float rowvary = .25, pitting = 0.01;
 
41
            float pockfrequency = 10, groovedepth = 0.01; )
 
42
{
 
43
#define sqr(x) ((x)*(x))
 
44
    float sbrick, tbrick;
 
45
    float ss, tt;
 
46
    float fact, disp;
 
47
    uniform float BMWIDTH = (brickwidth+mortarthickness);
 
48
    uniform float BMHEIGHT = (brickheight+mortarthickness);
 
49
    uniform float MWF = (mortarthickness*0.5/BMWIDTH);
 
50
    uniform float MHF = (mortarthickness*0.5/BMHEIGHT);
 
51
 
 
52
    basictile (s, t, BMWIDTH, BMHEIGHT, 0.5, 0.2, 1, jagged,
 
53
               sbrick, tbrick, ss, tt);
 
54
 
 
55
    fact = 1;
 
56
    disp = 0;
 
57
    if (tt < MHF) {
 
58
        /* We're in the top horizontal groove */
 
59
        disp = groovedepth * (sqr((tt)/MHF) - 1);
 
60
    }
 
61
    else if (tt > (1.0-MHF)) {
 
62
      /* Bottom horizontal groove */
 
63
        disp = groovedepth * (sqr((1-tt)/MHF) - 1);
 
64
    }
 
65
    if (ss < MWF) {
 
66
        disp = min (disp, 0.85 * groovedepth * (sqr(ss/MWF) - 1));
 
67
    }
 
68
    else if (ss > (1.0-MWF)) {
 
69
        disp = min (disp, 0.85 * groovedepth * (sqr((1-ss)/MWF) - 1));
 
70
    }
 
71
 
 
72
    fact = smoothstep (0, 1.3*MHF, tt) - smoothstep (1.0-1.3*MHF, 1, tt);
 
73
    fact *= (smoothstep (0, 1.3*MWF, ss) - smoothstep (1.0-1.3*MWF, 1, ss));
 
74
    fact = pitting * (0.75 * fact + 0.25);
 
75
    disp -= fact * pow(noise ((ss+sbrick)*pockfrequency/BMHEIGHT,
 
76
                              (tt+tbrick)*pockfrequency/BMWIDTH), 0.25);
 
77
 
 
78
    P += disp * normalize(N);
 
79
    N = calculatenormal (P);
 
80
}