diff options
| author | yum <yum.food.vr@gmail.com> | 2024-10-07 23:33:35 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-10-07 23:33:35 -0700 |
| commit | bcadf1d091efe76e7a1b2393f87f7e24128b723b (patch) | |
| tree | b5a37c88686f15f08845d597f223473511917a34 /math.cginc | |
| parent | e51760ab5e6d698b26b60e1811e7afce62be55d0 (diff) | |
Add fog gimmick
Diffstat (limited to 'math.cginc')
| -rw-r--r-- | math.cginc | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -197,5 +197,29 @@ float median(float3 x) return median(x.x, x.y, x.z); } +// Yoinked from here +// https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection.html +bool solveQuadratic(float a, float b, float c, out float x0, out float x1) +{ + float discriminant = b * b - 4 * a * c; + if (discriminant < 0) { + return false; + } else if (discriminant == 0) { + x0 = -0.5 * b / a; + x1 = x0; + } else { + float q = (b > 0) ? + -0.5 * (b + sqrt(discriminant)) : + -0.5 * (b - sqrt(discriminant)); + x0 = q/a; + x1 = c/q; + } + float tmp_min = min(x0, x1); + float tmp_max = max(x0, x1); + x0 = tmp_min; + x1 = tmp_max; + return true; +} + #endif // __MATH_INC |
