Shaders


spin_stars - A shader for traveling, spinning stars

 
/* shader spin_stars - dsward@webnation.com
 * based on Steve May's Renderman notes at http://www.cgrg.ohio-state.edu/~smay/RManNotes
 * and _Texturing and Modeling, A Procedural Approach_ by Darwyn Peachey, et al, ISBN 0-12-228760-6
*/
 
#define blend(a,b,x) ((a) * (1 - (x)) + (b) * (x))
#define snoise(x)    (noise(x) * 2 - 1)
#define whichtile(x,freq) (floor((x) * (freq)))
#define repeat(x,freq)    (mod((x) * (freq), 1.0))
#define pulse(a,b,fuzz,x) (smoothstep((a)-(fuzz),(a),(x)) - \
			   smoothstep((b)-(fuzz),(b),(x)))
#define udn(x,lo,hi) (smoothstep(.25, .75, noise(x)) * ((hi) - (lo)) + (lo))
 
surface
spin_stars
(
	float s_cells = 10;
	float t_cells = 10;
	float offset = 0;
	float spin = 0;
	float r_min = 0.24;
	float r_max = 0.56;
     float star_points = 5;
	float fuzz = 0.02;
)
{
	color surface_color = color(0, 0, 0);
	color surface_opac = color(0, 0, 0);
     float ss, tt, angle, r, a;
	float in_out = 0;
     float cell_s;
     point p0, p1;
     point d0, d1;
     float star_angle;
     color star_color;
	float star_rotation;
	float noi;
	float star_level;
	float star_r, star_g, star_b, colornoise, mix_ratio;
 
     cell_s = whichtile(s, s_cells);
 
	noi = noise(cell_s * s_cells + 0.5, cell_s * t_cells + 0.5);	
	star_level = mod(t + udn(noi * 357, 0, 1) + offset, 1);	
 
	ss = repeat(s, s_cells) - 0.5;
	tt = star_level * t_cells - 0.5;
 
	colornoise = noise(cell_s * 1234 + 0.5);
	star_r = udn(colornoise * 123, 0, 1);
	star_g = udn(colornoise * 234, 0, 1);
	star_b = udn(colornoise * 345, 0, 1);
	while ((star_r + star_g + star_b) < 1.5)
	{
		star_r = star_r * 2 + 0.1;
		star_g = star_g * 2 + 0.1;
		star_b = star_b * 2 + 0.1;
	}
	star_color = color(star_r, star_g, star_b);
	
	star_angle = 2 * PI / star_points;
	star_rotation = snoise(cell_s + 0.5) + spin + PI;
		
     p0 = r_max * (cos(0), sin(0), 0);
     p1 = r_min * (cos(star_angle / 2), sin(star_angle / 2), 0);
     d0 = p1 - p0;
	
	angle = atan(ss, tt) + star_rotation;
	r = sqrt(ss * ss + tt * tt);
	a = mod(angle, star_angle) / star_angle;
	if (a >= 0.5) a = 1 - a;	
	d1 = r * (cos(a), sin(a), 0) - p0;
	in_out += smoothstep(0, fuzz, zcomp(d0 ^ d1));
	
	mix_ratio = smoothstep(0.5, 0.65, in_out);
     surface_color = mix(surface_color, star_color, mix_ratio);
     surface_opac = surface_opac + mix_ratio;
		
     Oi = surface_opac;
     Ci = surface_color;
}

HOME

NEW

LINKS

GALLERY

ARTICLES

PLUG-INS

RENDERMAN

Switch to Frame View




Copyright © 1997 by WebNation
All trademarks are the property of their respective holders