Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (80 sloc) 1.61 KB
shader diamondplate(
point Pos = P,
float Scale = 2,
int Diamonds = 4,
float Margin = 0.1,
output float Bool = 0,
output int Fac = 0,
output float Disp = 0,
output normal Normal =
normal(0,0,1)
){
point p = Pos * Scale;
int xi = (int)floor(p[0]);
int yi = (int)floor(p[1]);
float x = abs(fmod(p[0],1.0));
float y = abs(fmod(p[1],1.0));
int flipxy=0;
float flipx=1, flipy=1;
if( (xi%2)^(yi%2) ){
float t = x;
x = y;
y = t;
flipxy=1;
}
if( (x < Margin)
||(x > 1-Margin)
|| (y < Margin)
|| (y > 1-Margin) )
{
Fac = 0; // do nothing
}else{
x -= Margin;
if(y>0.5){
y=1-y;
flipy = -1;
}
y -= Margin;
float w =
(1-2*Margin)/Diamonds;
x = mod(x,w)/w;
if(x>0.5){
x=1-x;
flipx = -1;
}
float topx=0.15;
float topy=0.5;
float topy2=0.55;
float botx=0.5;
float boty=0;
float a=(boty-topy)
/(botx-topx);
if(x>=topx){
float uppery =
(x-topx)*a+topy2;
float lowery = (
x-topx)*a+topy;
if(y > lowery){
if(y > uppery){
Fac = 1;
Disp= 1.0;
}else{
Fac = 2;
Disp= (y-lowery)
/(uppery - lowery);
if(flipxy){
Normal=normalize(
vector(-flipy,
flipx/a,
1));
}else{
Normal=normalize(
vector(flipx/a,
-flipy,
1));
}
}
}
}
}
}
You can’t perform that action at this time.