diff --git a/math/scale2d.glsl b/math/scale2d.glsl new file mode 100644 index 00000000..aecaf4c7 --- /dev/null +++ b/math/scale2d.glsl @@ -0,0 +1,14 @@ +/* +original_author: Patricio Gonzalez Vivo +description: returns a 2x2 scale matrix +use: scale2d( radians) +*/ + +#ifndef FNC_SCALE4D +mat2 scale2d(float _scale) { + return mat2( + _scale, 0.0, + 0.0, _scale, + ); +} +#endif \ No newline at end of file diff --git a/math/scale3d.glsl b/math/scale3d.glsl new file mode 100644 index 00000000..daa94b4d --- /dev/null +++ b/math/scale3d.glsl @@ -0,0 +1,15 @@ +/* +original_author: Patricio Gonzalez Vivo +description: returns a 3x3 scale matrix +use: scale3d( radians) +*/ + +#ifndef FNC_SCALE4D +mat3 scale3d(float _scale) { + return mat3( + _scale, 0.0, 0.0, + 0.0, _scale, 0.0, + 0.0, 0.0, _scale, + ); +} +#endif \ No newline at end of file diff --git a/sdf.glsl b/sdf.glsl index db21193b..60346a1a 100644 --- a/sdf.glsl +++ b/sdf.glsl @@ -36,7 +36,7 @@ // Operations #include "sdf/opOnion.glsl" -#include "sdf/opRepite.glsl" +#include "sdf/opRepeat.glsl" #include "sdf/opRevolve.glsl" #include "sdf/opRound.glsl" #include "sdf/opSubtraction.glsl" diff --git a/sdf.hlsl b/sdf.hlsl index 10b1d394..53729671 100644 --- a/sdf.hlsl +++ b/sdf.hlsl @@ -34,7 +34,7 @@ // Operations #include "sdf/opOnion.hlsl" -#include "sdf/opRepite.hlsl" +#include "sdf/opRepeat.hlsl" #include "sdf/opRevolve.hlsl" #include "sdf/opRound.hlsl" #include "sdf/opSubtraction.hlsl" diff --git a/sdf/opRepeat.glsl b/sdf/opRepeat.glsl new file mode 100644 index 00000000..803429a8 --- /dev/null +++ b/sdf/opRepeat.glsl @@ -0,0 +1,27 @@ +/* +original_author: Inigo Quiles +description: repeat operation for 2D/3D SDFs +use: opElongate( in p, in h ) +*/ + +#ifndef FNC_OPREPEAT +#define FNC_OPREPEAT + +vec2 opRepeat( in vec2 p, in float s ) { + return mod(p+s*0.5,s)-s*0.5; +} + +vec3 opRepeat( in vec3 p, in vec3 c ) { + return mod(p+0.5*c,c)-0.5*c; +} + +vec2 opRepeat( in vec2 p, in vec2 lima, in vec2 limb, in float s ) { + return p-s*clamp(floor(p/s),lima,limb); +} + +vec3 opRepeat( in vec3 p, in vec3 lima, in vec3 limb, in float s ) { + return p-s*clamp(floor(p/s),lima,limb); +} + +#endif + diff --git a/sdf/opRepite.hlsl b/sdf/opRepeat.hlsl similarity index 58% rename from sdf/opRepite.hlsl rename to sdf/opRepeat.hlsl index 7ee37459..8c22c7e6 100644 --- a/sdf/opRepite.hlsl +++ b/sdf/opRepeat.hlsl @@ -6,22 +6,22 @@ description: repite operation of one 2D SDFs use: opElongate( in p, in h ) */ -#ifndef FNC_OPREPITE -#define FNC_OPREPITE +#ifndef FNC_OPREPEAT +#define FNC_OPREPEAT -float2 opRepite( in float2 p, in float s ) { +float2 opRepeat( in float2 p, in float s ) { return mod(p+s*0.5,s)-s*0.5; } -float3 opRepite( in float3 p, in float3 c ) { +float3 opRepeat( in float3 p, in float3 c ) { return mod(p+0.5*c,c)-0.5*c; } -float2 opRepite( in float2 p, in float2 lima, in float2 limb, in float s ) { +float2 opRepeat( in float2 p, in float2 lima, in float2 limb, in float s ) { return p-s*clamp(floor(p/s), lima, limb); } -float3 opRepite( in float3 p, in float3 lima, in float3 limb, in float s ) { +float3 opRepeat( in float3 p, in float3 lima, in float3 limb, in float s ) { return p-s*clamp(floor(p/s), lima, limb); } diff --git a/sdf/opRepite.glsl b/sdf/opRepite.glsl deleted file mode 100644 index 4b3e04b5..00000000 --- a/sdf/opRepite.glsl +++ /dev/null @@ -1,27 +0,0 @@ -/* -original_author: Inigo Quiles -description: repite operation of one 2D SDFs -use: opElongate( in p, in h ) -*/ - -#ifndef FNC_OPREPITE -#define FNC_OPREPITE - -vec2 opRepite( in vec2 p, in float s ) { - return mod(p+s*0.5,s)-s*0.5; -} - -vec3 opRepite( in vec3 p, in vec3 c ) { - return mod(p+0.5*c,c)-0.5*c; -} - -vec2 opRepite( in vec2 p, in vec2 lima, in vec2 limb, in float s ) { - return p-s*clamp(floor(p/s),lima,limb); -} - -vec3 opRepite( in vec3 p, in vec3 lima, in vec3 limb, in float s ) { - return p-s*clamp(floor(p/s),lima,limb); -} - -#endif -