This is the 14th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Recommended reading

  • CSDN home page
  • GitHub open source address
  • Unity3D plug-in sharing
  • Jane’s address book
  • My personal blog
  • QQ group: 1040082875

One, foreword

No matter how basic, simple knowledge, as long as not, is difficult. Clear Flags: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender: OnImageRender Each camera must clear the ColorBuffer and z-buffer in the RenderBuffer at the start of the draw. This option controls what is cleared and what is cleared.

The differences between different Clear Flags Settings are shown below:(The camera draws a blue cube)

Sky box: Clears the color buffer and depth buffer, and sets the color buffer to the color of the skybox.

(All “colorbuffers” outside the cube are filled by the skybox)

Solid Color: Clears the color buffer and depth buffer, and sets the color buffer to a fixed color.(All “colorbuffers” outside the cube are filled with the selected color)

The above two options are the easiest to understand. They simply clear the color and depth data in the buffer, so if there are multiple cameras in the scene, and the last camera is set to one of the above ClearFlags, then, heh, the previous camera drawing results will not be displayed directly (because they are cleared).

Depth Only: Keep the color buffer and clear only the depth buffer.(Two cameras draw one after the other)(Only depth buffer drawing is cleared)

It is easy to see that since the blue camera shot the blue cube and then drew it without clearing the color buffer, the color buffer was filled by the result of the red camera shot: SolidColor + red cube before the blue camera was drawn, so the blue cube was only drawn on top of that. Moreover, because the depth buffer is cleared, the blue cube will always draw all the space regardless of whether the space is blocked by the red legislative body, so the wrong occlusion effect is produced.

Don’t Clear: Hair is not removed.(Unscrubbed drawing – left depth buffer)

As above, the color buffer is retained along with the depth buffer, so that the blue camera will be influenced by the depth value of the red cube when drawing, thus obtaining the correct occlusion effect.

By the way, if there is only one camera, and the camera is set to “DepthOnly” or “Don’t clear”, that is, not to clear the color buffer, when you drag an object, this will happen:(No shadow foot should be shot like this)

OnRenderImage So what does OnRenderImage have to do with ClearFlags for this camera? It doesn’t really matter.

What does this function usually do? This function is overridden for the purpose of post-screen effects such as full screen blur.

How is this function used and when to call it? First, the script that contains this function must be attached to a camera; Second, once the function is rewritten, it happens on the night that the camera updates the render to the current RenderBuffer after it has rendered all of its renderings.

The approximate trigger time is as follows:Note that if you override this function, there must be an operation that passes the buffer to dest, calling graphics.blit (rt, dest). If you didn’t do that, you could imagine that after this camera, the RenderBuffer would be completely dark.

However: the total blackness is simply because the correct ColorBuffer is not set to the ColorBuffer section of the current RenderBuffer. The depth buffer is still unaffected.

The following scenarios will hopefully clarify the issue: The testing environment1. The spatial position relationship between the two cubes: red occludes blue. 2. The blue camera only takes the blue cube, and the red camera only takes the red cube. 3. Camera render order: red → blue4. The render result of the blue camera is filled with the Image at the lower left corner of the screen, and the render result of the red camera is filled with the second Image at the lower left corner of the screen.

Case oneDepth Only for the blue camera, Solid Color = sky blue for the red camera.Case twoSolid Color = blue for blue camera, Solid Color = sky blue for red cameraThird caseBlue camera Solid Color = Strong pink, red camera Depth OnlyRed camera frame 1After the first frameFourth caseDon’t Clear blue camera, red camera Solid Color + empty OnImageRender functionThe red camera does not pass the color buffer to the DSTThe red camera doesn’t generate anythingBlue is affected by the depth value of the red cube

Analysis of theSummary: as long as the heart read the color buffer and depth buffer, pinch refers to the calculation of almost.