Skip to content

Commit

Permalink
Add Safe Sqrt (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
marat569 authored Oct 15, 2024
1 parent 738f6d3 commit b6f0e9e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/shaders/math.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ POWSAFE_FUNCTION_GENERATOR(float3);
POWSAFE_FUNCTION_GENERATOR(float4);
#undef POWSAFE_FUNCTION_GENERATOR

#define SQRTSAFE_FUNCTION_GENERATOR(struct) \
struct SqrtSafe(struct x) { \
return Sign(x) * sqrt(abs(x)); \
}

SQRTSAFE_FUNCTION_GENERATOR(float);
SQRTSAFE_FUNCTION_GENERATOR(float2);
SQRTSAFE_FUNCTION_GENERATOR(float3);
SQRTSAFE_FUNCTION_GENERATOR(float4);
#undef SQRTSAFE_FUNCTION_GENERATOR

float Average(float3 color) {
return (color.x + color.y + color.z) / 3.f;
}
Expand Down

0 comments on commit b6f0e9e

Please sign in to comment.