• Create Account

### #ActualNik02

Posted 07 August 2012 - 05:09 AM

In general, gradient ramps are implemented by simply interpolating between colors, given a scalar parameter. This is very easy in shaders.

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.

### #2Nik02

Posted 07 August 2012 - 05:04 AM

In general, gradient ramps are implemented by simply interpolating between colors, given a scalar parameter. This is very easy in shaders.

Think of a color ramp as a spline, where the control points represent colors instead of positions.

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.

### #1Nik02

Posted 07 August 2012 - 04:55 AM

In general, gradient ramps are implemented by simply interpolating between colors, given a scalar parameter.

Think of a color ramp as a spline, where the control points represent colors instead of positions.

PARTNERS