2
* brickbump.sl -- displacement shader for bricks.
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.
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
20
* pockfrequency The st frequency of the pits.
21
* groovedepth The depth of the grooves between bricks.
23
* AUTHOR: written by Larry Gritz, 1992 (and subsequently modified)
25
* $Revision: 1.1 $ $Date: 2001/06/07 19:00:13 $
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; )
43
#define sqr(x) ((x)*(x))
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);
52
basictile (s, t, BMWIDTH, BMHEIGHT, 0.5, 0.2, 1, jagged,
53
sbrick, tbrick, ss, tt);
58
/* We're in the top horizontal groove */
59
disp = groovedepth * (sqr((tt)/MHF) - 1);
61
else if (tt > (1.0-MHF)) {
62
/* Bottom horizontal groove */
63
disp = groovedepth * (sqr((1-tt)/MHF) - 1);
66
disp = min (disp, 0.85 * groovedepth * (sqr(ss/MWF) - 1));
68
else if (ss > (1.0-MWF)) {
69
disp = min (disp, 0.85 * groovedepth * (sqr((1-ss)/MWF) - 1));
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);
78
P += disp * normalize(N);
79
N = calculatenormal (P);