yum-archive/SoggyShaders
Old Unity shaders.
git clone https://git.yummers.dev/yum-archive/SoggyShaders
273a3ab
master
1#ifndef __POI_INC 2#define __POI_INC 3 4/* 5MIT License 6 7Copyright (c) 2018 King Arthur 8 9Permission is hereby granted, free of charge, to any person obtaining a copy 10of this software and associated documentation files (the "Software"), to deal 11in the Software without restriction, including without limitation the rights 12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13copies of the Software, and to permit persons to whom the Software is 14furnished to do so, subject to the following conditions: 15 16The above copyright notice and this permission notice shall be included in all 17copies or substantial portions of the Software. 18 19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25SOFTWARE. 26*/ 27 28static const float Epsilon = 1e-10; 29float3 RGBtoHCV(in float3 RGB) 30{ 31 // Based on work by Sam Hocevar and Emil Persson 32 float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0 / 3.0) : float4(RGB.gb, 0.0, -1.0 / 3.0); 33 float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx); 34 float C = Q.x - min(Q.w, Q.y); 35 float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z); 36 return float3(H, C, Q.x); 37} 38 39float3 RGBtoHSV(in float3 RGB) 40{ 41 float3 HCV = RGBtoHCV(RGB); 42 float S = HCV.y / (HCV.z + Epsilon); 43 return float3(HCV.x, S, HCV.z); 44} 45 46float3 HUEtoRGB(in float H) 47{ 48 float R = abs(H * 6 - 3) - 1; 49 float G = 2 - abs(H * 6 - 2); 50 float B = 2 - abs(H * 6 - 4); 51 return saturate(float3(R, G, B)); 52} 53 54float3 HSVtoRGB(in float3 HSV) 55{ 56 float3 RGB = HUEtoRGB(HSV.x); 57 return ((RGB - 1) * HSV.y + 1) * HSV.z; 58} 59 60#endif // __POI_INC