summaryrefslogtreecommitdiffstats
path: root/poi.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2024-04-22 16:02:38 -0700
committeryum <yum.food.vr@gmail.com>2024-04-22 16:02:38 -0700
commitdcb15c0d7425f2b3ede070cd97ac8f1bd8386df1 (patch)
treee17e5b620e0784226b6d24acce43c8bbcee22f1f /poi.cginc
Initial commit
Code bomb. Put tooner in version control.
Diffstat (limited to 'poi.cginc')
-rw-r--r--poi.cginc60
1 files changed, 60 insertions, 0 deletions
diff --git a/poi.cginc b/poi.cginc
new file mode 100644
index 0000000..5e31a42
--- /dev/null
+++ b/poi.cginc
@@ -0,0 +1,60 @@
+#ifndef __POI_INC
+#define __POI_INC
+
+/*
+MIT License
+
+Copyright (c) 2018 King Arthur
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+static const float Epsilon = 1e-10;
+float3 RGBtoHCV(in float3 RGB)
+{
+ // Based on work by Sam Hocevar and Emil Persson
+ float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0 / 3.0) : float4(RGB.gb, 0.0, -1.0 / 3.0);
+ float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx);
+ float C = Q.x - min(Q.w, Q.y);
+ float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
+ return float3(H, C, Q.x);
+}
+
+float3 RGBtoHSV(in float3 RGB)
+{
+ float3 HCV = RGBtoHCV(RGB);
+ float S = HCV.y / (HCV.z + Epsilon);
+ return float3(HCV.x, S, HCV.z);
+}
+
+float3 HUEtoRGB(in float H)
+{
+ float R = abs(H * 6 - 3) - 1;
+ float G = 2 - abs(H * 6 - 2);
+ float B = 2 - abs(H * 6 - 4);
+ return saturate(float3(R, G, B));
+}
+
+float3 HSVtoRGB(in float3 HSV)
+{
+ float3 RGB = HUEtoRGB(HSV.x);
+ return ((RGB - 1) * HSV.y + 1) * HSV.z;
+}
+
+#endif // __POI_INC