Skip to content

Commit

Permalink
Merge pull request #141 from bryndsey/main
Browse files Browse the repository at this point in the history
  • Loading branch information
patriciogonzalezvivo authored Jun 24, 2024
2 parents e7dac33 + 28bda78 commit b708d44
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion sdf/opSubtraction.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ float opSubtraction( float d1, float d2, float k ) {

vec4 opSubtraction( vec4 d1, vec4 d2, float k ) {
float h = clamp( 0.5 - 0.5*(d2.a+d1.a)/k, 0.0, 1.0 );
return mix( d2, -d1, h ) + k*h*(1.0-h);
vec4 result = mix( d2, -d1, h );
result.a += k*h*(1.0-h);
return result;
}

#endif
4 changes: 3 additions & 1 deletion sdf/opUnion.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ inline __host__ __device__ float opUnion( float d1, float d2, float k ) {

inline __host__ __device__ float4 opUnion( float4 d1, float4 d2, float k ) {
float h = clamp( 0.5f + 0.5f * (d2.w - d1.w)/k, 0.0f, 1.0f );
return mix( d2, d1, h ) - k * h * (1.0f-h);
float4 result = mix( d2, d1, h );
result.w -= k * h * (1.0f-h);
return result;
}

#endif
4 changes: 3 additions & 1 deletion sdf/opUnion.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ float opUnion( float d1, float d2, float k ) {

vec4 opUnion( vec4 d1, vec4 d2, float k ) {
float h = saturate( 0.5 + 0.5*(d2.a - d1.a)/k );
return mix( d2, d1, h ) - k*h*(1.0-h);
vec4 result = mix(d2, d1, h);
result.a -= k * h * (1.0 - h);
return result;
}

#endif
4 changes: 3 additions & 1 deletion sdf/opUnion.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ float opUnion( float d1, float d2, float k ) {

float4 opUnion( float4 d1, float4 d2, float k ) {
float h = saturate( 0.5 + 0.5*(d2.a - d1.a)/k );
return lerp( d2, d1, h ) - k*h*(1.0-h);
float4 result = lerp( d2, d1, h );
result.a -= k*h*(1.0-h);
return result;
}

#endif

0 comments on commit b708d44

Please sign in to comment.