संदर्भ clearDepth()

clearDepth()

Clears the depth buffer in WebGL mode.

clearDepth() clears information about how far objects are from the camera in 3D space. This information is stored in an object called the depth buffer. Clearing the depth buffer ensures new objects aren't drawn behind old ones. Doing so can be useful for feedback effects in which the previous frame serves as the background for the current frame.

The parameter, depth, is optional. If a number is passed, as in clearDepth(0.5), it determines the range of objects to clear from the depth buffer. 0 doesn't clear any depth information, 0.5 clears depth information halfway between the near and far clipping planes, and 1 clears depth information all the way to the far clipping plane. By default, depth is 1.

Note: clearDepth() can only be used in WebGL mode.

उदाहरण

let previous;
let current;

function setup() {
createCanvas(100, 100, WEBGL);

// Create the p5.Framebuffer objects.
previous = createFramebuffer({ format: FLOAT });
current = createFramebuffer({ format: FLOAT });

describe(
'A multicolor box drifts from side to side on a white background. It leaves a trail that fades over time.'
);
}

function draw() {
// Swap the previous p5.Framebuffer and the
// current one so it can be used as a texture.
[previous, current] = [current, previous];

// Start drawing to the current p5.Framebuffer.
current.begin();

// Paint the background.
background(255);

// Draw the previous p5.Framebuffer.

सिंटैक्स

clearDepth([depth])

पैरामीटर्स

depth
Number:

amount of the depth buffer to clear between 0 (none) and 1 (far clipping plane). Defaults to 1.

Notice any errors or typos? Please let us know. Please feel free to edit src/core/rendering.js and open a pull request!

संबंधित संदर्भ

Complete your gift to make an impact