Think of a color ramp as a spline, where the control points represent colors instead of positions. The spline algorithms are literally the exact same ones in either case.
The simplest possible ramp is one that contains two control points (colors) that are used in linear interpolation:
// simple example float4 red = float4(1,0,0,1); float4 blue= float4(0,0,1,1); float parameter = normal.y * 0.5f + 0.5f; // map normal's y direction to 0...1 for use as interpolation parameter float4 finalcolor = lerp(red, blue, parameter); // when normal points down, red is used more; conversely, up means more blue // lerp is defined as v1*(1-param) + v2*param where v1 and v2 are the original values to interpolate between
You can extend this basic idea to introduce more colors in the ramp.