这段代码我已经不太记得是从哪抄的了,惭愧;
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float k1 = step(c.b, c.g);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), k1);
float k2 = step(p.x, c.r);
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), k2);
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
?
时间: 2024-10-08 00:13:33