#ifndef __MATH_INC #define __MATH_INC #define PI 3.14159265358979f #define RCP_PI (1.0f / PI) #define TAU (2.0f * PI) #define SQRT_3 1.73205081f float sin_noise_3d(float3 uvw) { return sin(uvw[0]) * sin(uvw[1]) * sin(uvw[2]); } float sin_noise_3d_fbm(float3 uvw, uint octaves, float k, float strength) { float result = 0; float factor = 1.0f; for (uint i = 0; i < octaves; i++) { result += sin_noise_3d(uvw) * factor * strength; uvw *= k; factor /= k; } return result; } // Wrap a dot product. Assume it's already clamped. // At k=0, you get standard lambertian shading. // At k=0.5, you get half-lambertian shading. // At k=1.0, you get flat shading. // k must be on [0, 1]. // Energy preserving, within some small bound. float wrapDotProduct(float XoY, float k) { float lambertian = XoY; float half_lambertian = pow(max(1e-4, (XoY + 0.5f) / (1.0f + 0.5f)), 2); float flat = RCP_PI; if (k < 0.5) { return lerp(lambertian, half_lambertian, k * 2.0f); } else { return lerp(half_lambertian, flat, k * 2.0f - 1.0f); } } #endif // __MATH_INC