Files
integration/Shaders/RainbowColors.ush

51 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

#pragma once
static const int RainbowColorsSize = 16;
static const float3 RainbowColors[RainbowColorsSize] = {
float3(1.00, 0.05, 0.05), // 0 red
float3(0.45, 0.00, 0.00), // 1 dark red
float3(1.00, 0.20, 0.00), // 2 orange
float3(0.20, 0.05, 0.01), // 3 dark orange (brown)
float3(1.00, 1.00, 0.00), // 4 yellow
float3(0.35, 0.45, 0.00), // 5 olive
float3(0.00, 1.00, 0.00), // 6 green
float3(0.00, 0.30, 0.00), // 7 dark green
float3(0.00, 1.00, 1.00), // 10 cyan
float3(0.00, 0.40, 0.40), // 11 dark cyan
float3(0.00, 0.00, 1.00), // 8 blue
float3(0.00, 0.00, 0.25), // 9 dark blue
float3(0.25, 0.00, 1.00), // 12 purple
float3(0.10, 0.00, 0.25), // 13 dark purple
float3(1.00, 0.05, 1.00), // 14 pink
float3(0.45, 0.00, 0.25) // 15 dark pink
};
// Given a color index, find the associated color.
// If NColors is 8 or less, skips the "dark" colors.
// If NColors is 4 or less, skips 3 out of 4 colors.
//
float3 RainbowColorLookup(int coloridx, int ncolors)
{
if (ncolors <= 8) coloridx *= 2;
if (ncolors <= 4) coloridx *= 2;
float3 color = float3(1,1,1);
if (coloridx < RainbowColorsSize) color = RainbowColors[coloridx];
return color;
}
// Create a striped rainbow pattern. The pattern has ncolors
// color bands, separated by thin white lines. Using the mask,
// which is a bitmask, you can turn any band to black.
//
float3 MaskedRainbowPattern(float texcoord, int ncolors, int mask)
{
float bandPos = texcoord * ncolors;
int coloridx = (int)floor(fmod(bandPos, ncolors));
float3 color = RainbowColorLookup(coloridx, ncolors);
if (mask & (1 << coloridx)) color = float3(0, 0, 0);
float edge = frac(bandPos);
if ((edge <= 0.1) || (edge >= 0.9)) color = float3(1, 1, 1);
return color;
}