Understanding Ramps And Gradients

It doesn’t take long to get to grips with understanding what a Ramp represents within a shader, and here’s a walkthrough to help.

 

The Values A Ramp Contains :

The intensity at each point in the Ramp defines a value between 0 and 1 in the shader, and acts as a variable to control the value of a certain effect, such as transparency (an easy to visualise example). Black represents a value of 0, and white a value of 1 (or, technically in the case of these shaders, red represents a value of 1, since only the red colour information is used).

Note that many shaders allow you to set minimum and maximum ranges. In the case of a transparency shader, for example, this means that black represents whatever minimum opacity you set in the shader, and white whatever maximum opacity you set (otherwise, you’d need to have Ramps that varied from “pretty dark but obviously not black” grey to “very light, almost but not quite white” grey!).

So, the Ramp defines the rise and fall of a value between a minimum and maximum  value.

The values can rise and fall as often as required, and not necessarily from the maximum to the minimum each time, to allow for any type of desired effect.

 

How The Ramp Is Accessed :

The position read from by the shader varies with some attribute, such as with distance, or with angle of view.

To take the distance example, the left edge of the Ramp represents surfaces that are nearer to the camera, and the right edge represents those that are further away. In the case of distance, the shader will let you specify a near and far distance (anything at or before the near distance is the left edge of the Ramp, anything at or beyond the far distance is the right edge of the Ramp).

For an angle of view based shader, the left hand edge represents steep angles (those surfaces pointing almost at right angles to the direction of view), and the right hand edge represents shallow angles (those surfaces pointing straight back at the direction of view) - ie, for a sphere, the left edge of the Ramp sets the transparency at the edge of the sphere, and the right edge sets the transparency at the centre.

 

The Values A Gradient Contains :

This is an easy one - a Gradient for these shaders contains colour information, just as you see it! Gradients are used to control how colour varies with a certain parameter.

 

How A Gradient Is Accessed :

The shaders read from a Gradient in much the same way they read from a Ramp, moving from left to right as a parameter, such as distance of angle of view, changes. The slightly complicating factor is that often it is a Ramp that controls how the Gradient is accessed!

To take an angle of view example, a shader may read from a Ramp based on the angle between the surface and direction of view. This returns a value of 0 or 1, that will vary with angle as defined by the Ramp itself, and this value in turn is used to read from a Gradient, with 0 (black in the Ramp) being the left hand edge of the Gradient, and 1 (white in the Ramp) being the right hand edge of the Gradient.

This approach allows for great flexibility, with the Gradient defining which colours are used, and the Ramp defining how those colours are “moved through”, allowing complete freedom in the number and location of transition points, and complete freedom in the fades between those transition points (or as much freedom as your art package gives you in creating colour fades, Gradient fills, etc!).

Introduction to Ramps and Gradients

Understanding Ramps and Gradients

TG Pack 3 Index