displacement secondd( float Height = 0.2, // displacement height Ks = 0.5, // specular coefficient Kd = 0.5, // diffuse coefficient Ka = .1, // ambient coefficient roughness = 0.1; // specular roughness color SpecularColor = color( 1, 1, 1 ) // specular color ) { float RAMP = 0.2; // over how much of the width to ramp up float TheHeight = 0.; // how much displacement to apply float up = 2. * u; float vp = v; float WIDTH = 0.10; float numinu = floor( up / WIDTH ); float numinv = floor( vp / WIDTH ); if( mod( numinu+numinv, 2. ) == 0. ) { float umin = numinu*WIDTH; float umax = umin+WIDTH; float vmin = numinv*WIDTH; float vmax = vmin+WIDTH; float distu = min( up-umin, umax-up ); float distv = min( vp-vmin, vmax-vp ); float dist = min( distu, distv )/WIDTH; float t = smoothstep( 0., RAMP, dist ); // 0. if dist <= 0., 1. if dist >= RAMP TheHeight = t*Height; // apply the blending } #define BUMP_MAPPING if( TheHeight != 0. ) { #ifdef BUMP_MAPPING N = calculatenormal( P + normalize(N) * TheHeight ); #else P = P + normalize(N) * TheHeight; N = calculatenormal(P); #endif } }