常用函数
color
mix(color C0, color Cl, float f)
{
return (l-f)*C0 + f*Cl;
}
-----------------------------------------------------------------
float
step(float a, float x)
{
return (float) (x >= a);
}
----------------------------------------------------------------
#define PULSE(a,b,x) (step((a),(x)) - step((b),(x)))
----------------------------------------------------------------
float
clamp(float x, float a, float b)
{
return (x < a ? a: (x > b ? b : x));
}
min(x, b) ≡ clamp(x, x, b)
max(x, a) ≡ clamp(x, a, x)
clamp(x, a, b) ≡ min(max(x, a), b)
------------------------------------------------------------------
float
min(float a, float b)
{
return (a < b ? a : b);
}
float
max(float a, float b)
{
return (a < b ? b : a);
}
--------------------------------------------------------------
float
abs(float x)
{
return (x < 0 ? -x : x);
}
------------------------------------------------------------
float
smoothstep(float a, float b, float x)
{
if (x < a)
return 0;
if (x >= b)
return 1;
x = (x - a)/(b - a);
return (x*x * (3 - 2*x));
}
----------------------------------------------------------------
------------------------------------------------------------
float
mod(float a, float b)
{
int n = (int)(a/b);
a -= n*b;
if (a < 0)
a += b;
return a;
}
float xf, xi;
xf = a/b;
xi = floor(xf);
xf -= xi;
-----------------------------------------------------------------
#define FLOOR(x) ((int)(x) - ((x) < 0 && (x) != (int)(x)))
#define CEIL(x) ((int)(x) + ((x) > 0 && (x) != (int)(x)))
mix(color C0, color Cl, float f)
{
return (l-f)*C0 + f*Cl;
}
-----------------------------------------------------------------
float
step(float a, float x)
{
return (float) (x >= a);
}
![]() |
----------------------------------------------------------------
#define PULSE(a,b,x) (step((a),(x)) - step((b),(x)))
![]() |
![]() |
----------------------------------------------------------------
float
clamp(float x, float a, float b)
{
return (x < a ? a: (x > b ? b : x));
}
![]() |
min(x, b) ≡ clamp(x, x, b)
max(x, a) ≡ clamp(x, a, x)
clamp(x, a, b) ≡ min(max(x, a), b)
------------------------------------------------------------------
float
min(float a, float b)
{
return (a < b ? a : b);
}
float
max(float a, float b)
{
return (a < b ? b : a);
}
--------------------------------------------------------------
float
abs(float x)
{
return (x < 0 ? -x : x);
}
![]() |
------------------------------------------------------------
float
smoothstep(float a, float b, float x)
{
if (x < a)
return 0;
if (x >= b)
return 1;
x = (x - a)/(b - a);
return (x*x * (3 - 2*x));
}
![]() |
----------------------------------------------------------------
![]() |
------------------------------------------------------------
float
mod(float a, float b)
{
int n = (int)(a/b);
a -= n*b;
if (a < 0)
a += b;
return a;
}
float xf, xi;
xf = a/b;
xi = floor(xf);
xf -= xi;
![]() |
-----------------------------------------------------------------
#define FLOOR(x) ((int)(x) - ((x) < 0 && (x) != (int)(x)))
#define CEIL(x) ((int)(x) + ((x) > 0 && (x) != (int)(x)))