-
Notifications
You must be signed in to change notification settings - Fork 0
/
height.sl
71 lines (62 loc) · 1.91 KB
/
height.sl
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Michael Rose
// January 13th 2016
// As of January 13th, 2016, this file compiles using
// shader.exe from the non-commercial version of
// Renderman found in RenderManProServer-20.6
displacement
height(
float
Ad = 0.025, // width of each stripe
Bd = 0.10, // height of each stripe
Amp = 0,
Height = .1;
)
{
// be sure the normal points correctly (used for lighting):
varying vector Nf = faceforward( normalize( N ), I );
vector V = normalize( -I );
// determine how many squares over and up we are in right now:
float up = 2. * u; // because we are rendering a sphere
float vp = v;
float numinu = floor( up / (2*Ad) );
float numinv = floor( vp / (2*Bd) );
float uc = numinu * 2 * Ad + Ad;
float vc = numinv * 2 * Bd + Bd;
// Noise
point PP = point "shader" P;
float magnitude = 0.;
float size = 2.;
float i;
for( i = 0.; i < 7.0; i += 1.0 )
{
magnitude += ( noise(size * PP ) - 0.50 ) / size;
size *= 2.;
}
point upvp = point( up, vp, 0. ); // the point
point cntr = point( 0., 0., 0. ); // the center
vector delta = upvp-cntr; // vector from center to u',v'
float oldrad = length(delta); // result from the ellipse equation
float newrad = oldrad+Amp*magnitude;
delta = delta * newrad / oldrad;
float deltau = xcomp(delta);
float deltav = ycomp(delta);
float TheHeight = 0.;
float newnuminu = floor( deltau / (2*Ad) );
float newnuminv = floor( deltav / (2*Bd) );
float u = newnuminu * 2 * Ad + Ad;
float v = newnuminv * 2 * Bd + Bd;
float d = ((deltau-u)/Ad)*((deltau-u)/Ad)+((deltav-v)/Bd)*((deltav-v)/Bd);
//changes the height based on if the new delta falls inside the circle
if(d <= 1.)
TheHeight = (1.-d)*Height; // apply the blending
#define DISPLACEMENT_MAPPING
if( TheHeight != 0. )
{
#ifdef DISPLACEMENT_MAPPING
P = P + normalize(N) * TheHeight;
N = calculatenormal(P);
#else
N = calculatenormal( P + normalize(N) * TheHeight );
#endif
}
}