CG programming for non-programmers, lesson 24

Sometimes values only make sense within a certain range. For example, in an election it doesn’t make sense, when talking about voters, to speak of fewer than zero percent, or more than one hundred percent.

Similarly, when we mix two things, it often doesn’t make sense to talk about a mix parameter of less than zero, or greater than one.

For such reasons, it is often useful to clamp a value to some useful range. In lesson 24 we introduce the clamp(value,lo,hi) function, which makes sure that value can’t be lower than lo or higher than hi.

In this case, we are applying the clamp function to control the gradation in fog thickness from the top to the bottom of our image. We want to have lighter fog at the top of the image, and heavier fog at the bottom.

But we still want to mix in a sensible quantity of fog. And in this case, “sensible” means the mixing parameter needs to be between 0.0 and 1.0.

You can see this lesson by CLICKING HERE.

Leave a Reply