billr@truevision.com (Bill Romanowski) (06/14/91)
--- RenderMan "terra" shader and example --- I've been asked for this by a few persons so I thought I'd put it on the net... This is the .sl source for the "terra" planet shader and it's companion displacement shader "terrabump". I've also included a .rib file for an example of how it's used. /* * terra(): a terrforming earth-like shader * (terra's displacement companion is "terrabump") * this is a mutation of pixar's blue marble shader * * - no restrictions on use * bill romanowski * truevision inc. */ surface terra( float Ks = .01, Kd = .4, Ka = .1, roughness = .6, txtscale = 1; /* water to land mass ratio */ color specularcolor = 1) { point PP; /* scaled point in shader space */ float csp; /* color spline parameter */ point Nf; /* forward-facing normal */ point V; /* for specular() */ float pixelsize, twice, scale, weight, turbulence; /* Obtain a forward-facing normal for lighting calculations. */ Nf = faceforward( normalize(N), I); V = normalize(-I); PP = transform("shader", P) * txtscale; pixelsize = sqrt(area(PP)); twice = 2 * pixelsize; turbulence = 0; for (scale = 1; scale > twice; scale /= 2) turbulence += scale * noise(PP/scale); /* Gradual fade out of highest-frequency component near limit */ if (scale > pixelsize) { weight = (scale / pixelsize) - 1; weight = clamp(weight, 0, 1); turbulence += weight * scale * noise(PP/scale); } csp = clamp(4 * turbulence - 3, 0, 1); Ci = color spline(csp, color (.9 ,.9 ,.95), color (.87 ,.87 ,.9), color (.75294 ,.92941 ,.92157), color (.27000 ,.28824 ,.18000 ), /* forest */ color (.40000 ,.29500 ,.25000 ), /* mid */ color (.44000 ,.41010 ,.28100 ), /* land */ color (.35000 ,.30000 ,.28000), color (.30000 ,.35000 ,.26000), color (.25000 ,.40000 ,.23000), color (.20000 ,.42500 ,.21000), color (.40000 ,.35000 ,.16000), /* shore */ color (0.02000, 0.02400, 0.40000), /* water */ color (1., 0., 0.28) /* unused */ ); /* Multiply this color by the diffusely reflected light. */ Ci *= Ka*ambient() + Kd*diffuse(Nf); /* Adjust for opacity. */ Oi = Os; Ci = Ci * Oi; /* Add in specular highlights. */ Ci += specularcolor * Ks * specular(Nf,V,roughness); } /* the end */ /* * terrabump: a terrforming earth-like shader * displacement shader companion to terra shader * * ( remember to set "txtscale" to the same value in * the terra shader so the mountains line up ) * * this is a mutation of pixar's blue marble shader * * - no restrictions on use * bill romanowski * truevision inc. */ displacement terrabump( float depth = 1, txtscale = 1;) /* amount to scale mountains */ { point PP; /* scaled point in shader space */ float csp; /* color spline parameter */ point Nf; /* forward-facing normal */ point V; /* for specular() */ point P2; float pixelsize, twice, scale, weight, turbulence; /* Obtain a forward-facing normal for lighting calculations. */ Nf = faceforward( normalize(N), I); V = normalize(-I); PP = transform("shader", P) * txtscale; pixelsize = sqrt(area(PP)); twice = 2 * pixelsize; turbulence = 0; for (scale = 1; scale > twice; scale /= 2) turbulence += scale * noise(PP/scale); if (scale > pixelsize) { weight = (scale / pixelsize) - 1; weight = clamp(weight, 0, 1); turbulence += weight * scale * noise(PP/scale); } P2 = P + ((clamp(4 * turbulence - 3, -1, 1))*depth); N = calculatenormal(P2); } /* the end */ -----------------------------------------------------------------
bcorrie@csr.UVic.CA (Brian Corrie) (06/14/91)
billr@truevision.com (Bill Romanowski) writes: >--- RenderMan "terra" shader and example --- >I've been asked for this by a few persons so I thought I'd >put it on the net... >This is the .sl source for the "terra" planet shader and >it's companion displacement shader "terrabump". I've also >included a .rib file for an example of how it's used. Great, I can't wait to try it out. I knew we would be passing these around some day soon. Now if only I could come up with something original to contribute 8-( B -- Brian Corrie (bcorrie@csr.uvic.ca) Under the most rigorously controlled conditions of pressure, temperature, volume, humidity and other variables, the organism will do as it damn well pleases. Sounds like some of the code I have written...... 8-)