Render Texture
OnRenderImage
is an event function called after a Camera has finished rendering. It allows us to modify the Camera’s final image. Built-in: calls it on the same GameObject as an enabled Camera component. SRP: use ScriptableRenderPass
instead.
GetTemporary and ReleaseTemporary
GetTemporary will return a RT for temporary calculations. Release it using ReleaseTemporary as soon as we’re done with it. Unity keeps an internal RT pool, so calling GetTemporary might return a created one if the size and the format are the same. Temporary RT are destroyed when they are not used for a couple of frames. It’s best for performance to get and release for each blit when we are doing a series of post-processing “blits”. It’s mostly beneficial for mobile and multi-GPU systems. GetTemporary internally do a DiscardContents call which helps to avoid restoring the previous RT content.
Kawase Blur and Dual Blur
Kawase Blur Source: https://www.gdcvault.com/play/1022665/Frame-Buffer-Postprocessing-Effects-in
PPT: https://ppt-online.org/755333
Kawase Blur was originally a bloom filter, but it became a type of blur method now. The result was not not bad compared to Gaussian Blur. The idea is to sample the four corners and ping pong Blit in iterations. Dual Kawase Blur improved the calculation by sampling down and up in the same number of iterations.
CBuffer
“UnityPerMaterial CBuffer inconsistent inside a SubShader”
In SRP Batcher, UnityPerMaterial data is persistent in GPU memory, so there are not tons of different layouts to update in GPU memory. Every pass should have the same CBuffer size.
Depth
Unity Thread:
https://forum.unity.com/threads/what-is-eye-space-in-unity-shaders-nb-its-not-view-space.797775/
https://forum.unity.com/threads/decodedepthnormal-linear01depth-lineareyedepth-explanations.608452/
-
Depth value stored in the buffer when rendering with a perspective projection matrix is a non-linear value in [0.0, 1.0]. 1.0 is far plane and 0.0 is near plane. Reversed Z will reverse the value too. 0.5 is not halfway but close to the camera.
-
_CameraDepthTexture is the screen size texture storing the depth value for opaque objects (render queue < 2500) only.
-
LinearEyeDepth
and
Linear01Depth
convert the non-linear depth value to linear.
LineaEyeDepth
converts the value into view space depth. 0.0 becomes the far plane, 1.0 becomes the near plane. 1 is a surface that is 1 unit from the camera’s pivot along the camera’s z axis.Linear01Depth
mostly just makes 0.5 is the halfway.
-
In built-in pipeline, _CameraDepthNormalsTexture is a RGBA32 texture. It contains depth and normal values. x and y value represents the normal; z and w represent depth. (16 bits and 16 bits)
It worth to note that sampling _CameraDepthTexture
is like sampling a regular texture. If I used it on a cube, the six sides will have a depth texture each. LineaEyeDepth(positionWS, viewMatrix)
calculates the depth values by the vertex in the wposition.
Universal Render pipeline only supports normal and depth separately.
Render Texture has depth format. The precision value depends on the platform, however. For example, OpenGL uses the native depth component (24 or 16 bits), while the Direct3D9 uses 32 bit floating format.