Clamping (graphics)

In computer graphics, clamping is the process of limiting a position to an area. Unlike wrapping, clamping merely moves the point to the nearest available value.

To put clamping into perspective, pseudocode for clamping is as follows:

Pseudocode (clamping):

function clamp(x, min, max):
    if (x < min) then
        x = min
    else if (x > max) then
        x = max
    return x

Uses

In general, clamping is used to restrict a value to a given range. For example, in OpenGL the glClearColor function takes four GLfloat values which are then 'clamped' to the range .[1]

Y = clamp(X, 1, 5)
XY
X < 11
11
1.51.5
22
33
44
55
X > 55

One of the many uses of clamping in computer graphics is the placing of a detail inside a polygon—for example, a bullet hole on a wall. It can also be used with wrapping to create a variety of effects.

gollark: "Am not here" is an odd name, but okay.
gollark: ~~technically it's reverse engineering *and* maybe cheating~~
gollark: `/lineage/[code of egg]` used to work on cave eggs.
gollark: (This is what I think of the raffle, actually)
gollark: Even better, apply this to 1 in 100 people, because random means fair!

References

  1. "OpenGL 4 Reference Pages". www.khronos.org. Retrieved 2018-10-31.


This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.