Skip to content

Commit

Permalink
make Box and RoundBox distance functions signed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hecomi committed Feb 16, 2019
1 parent 61f0245 commit df2962d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Assets/uRaymarching/Shaders/Include/Primitives.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ inline float Sphere(float3 pos, float radius)

inline float RoundBox(float3 pos, float3 size, float round)
{
return length(max(abs(pos) - size, 0.0)) - round;
float3 d = abs(pos) - size;
return length(max(abs(pos) - size, 0.0)) - round
+ min(max(d.x, max(d.y, d.z)), 0.0);
}

inline float Box(float3 pos, float3 size)
{
// complete box (round = 0.0) cannot provide high-precision normals.
return RoundBox(pos, size, 0.0001);
float3 d = abs(pos) - size;
return length(max(abs(pos) - size, 0.0))
+ min(max(d.x, max(d.y, d.z)), 0.0);
}

inline float Torus(float3 pos, float2 radius)
Expand Down

0 comments on commit df2962d

Please sign in to comment.