/* * grass_surface.sl -- surface shader to puts grass with bump mapping on a patch */ surface grass_surface (float urepeat = 1.0, vrepeat = 1.0, Ka = .7, Kd = .4, Ks = 0.08, roughness = 0.1, Km = 0.8; color specularcolor = 1; string texturename = "grass.tif") { float size = 1.8, magnitude = 0.0, i; point Nf; color cs; Nf = faceforward(normalize(N), I); Oi = 1.0; for(i=0; i<6.0; i+= 1.0){ magnitude += (.5 - noise(P * size)) / size; size *= 2.0; } /* Apply the background texture */ cs = color texture(texturename, u*urepeat, v*vrepeat); cs = cs * (float texture(texturename [3], u*urepeat, v*vrepeat)); /** Bump mapping **/ cs = cs * (1-magnitude*Km); Ci = cs * (Ka*ambient() + Kd*diffuse(Nf)) + Ks*specularcolor*specular(Nf, normalize(-I), roughness); }