Ok, first one was a warmup - for the next one I wanted to test wether it is possible to port one of these BI procedural texture plugins to OSL:
http://www-users.cs.umn.edu/~mein/blender/plugins/texture.html
Turns out it works pretty well and the result is way less complicated, as you can see with this basic pie texture:
#include "stdosl.h"
color pie(point p, int Divides, float Angle)
{
float angle_new;
angle_new = atan2(p[0],p[1]) + Angle*3.1415926/180.0;
return color(0.5 - 0.5*sin(angle_new * Divides - 0.5));
}
shader node_magic_texture(
int Divides = 2,
float Angle = 5.0,
point Vector = P,
output color Color = color(0.0, 0.0, 0.0))
{
Color = pie(Vector, Divides, Angle);
}
Stripped the GPL-Block of the code, copyright of the original version goes to Robert Wenzlaff.
Edit: I also wrote a version where you can set the colors of the stripes, but I think it’s not very usefull since you can easily set the colors with a colorramp node which also lets you adjust the hardness and thickness of the stripes with a very fine-grained control:
#include "stdosl.h"
color pie(point p, int Divides, float Angle)
{
float angle_new;
angle_new = atan2(p[0],p[1]) + Angle*3.1415926/180.0;
return color(0.5 - 0.5*sin(angle_new * Divides - 0.5));
}
shader node_magic_texture(
color Color1 = color(0),
color Color2 = color(1),
int Divides = 2,
float Angle = 5.0,
point Vector = P,
output color Color = color(0.0, 0.0, 0.0))
{
Color = mix(Color1, Color2, pie(Vector, Divides, Angle));
}