Colorize
code:HLSL
// to call:
// using ray forwarded iteration for coloring
// float4 color = colorize(pow(stepsTaken / float(MAX_RAY_STEPS), 0.6 + 0.3 * sin(_Time.y)));
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);
}
float4 colorize(float c) {
float hue = lerp(0.6, 1.15, min(c * 1.2 - 0.05, 1.0));
float sat = 1.0 - pow(c, 4.0);
float lum = c;
float3 hsv = float3(hue, sat, lum);
float3 rgb = hsv2rgb(hsv);
return float4(rgb, 1.0);
}