summaryrefslogtreecommitdiffstats
path: root/math.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-10-07 23:33:35 -0700
committeryum <yum.food.vr@gmail.com>2024-10-07 23:33:35 -0700
commitbcadf1d091efe76e7a1b2393f87f7e24128b723b (patch)
treeb5a37c88686f15f08845d597f223473511917a34 /math.cginc
parente51760ab5e6d698b26b60e1811e7afce62be55d0 (diff)
Add fog gimmick
Diffstat (limited to 'math.cginc')
-rw-r--r--math.cginc24
1 files changed, 24 insertions, 0 deletions
diff --git a/math.cginc b/math.cginc
index c2903c8..46e19e1 100644
--- a/math.cginc
+++ b/math.cginc
@@ -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