Shader

Shader.SetGlobalVector(int nameID, Vector4 value)` Sets a global vector proper. Shader will use the global property if it is not defined in Properties block. example: `_LightDirection` in `ShadowCasterPass.hlsl

ZTest Always sets NO depth testing. The geometry is drawn regardless of distance.

Texels vs. Pixels

Texels are the elements of a texture. While pixel is the element of an image. When we zoom in a 3D model, we may see 1 texel presented by many pixels. Or we can zoom out, 1 pixel represents over 1 texel. Or in a sharp angle regarding the viewer, the texels may become so small that the pattern is lost in the image.

Depth

DeclareDepthTexture.hlsl provides two functions: SampleSceneDepth and LoadSceneDepth. There difference between them is: Sample use UV to sample the texture, apply addressing modes(clamp, wrap, …) and add filters(bilinear, trilinear, aniso). Load use texel coordinate in the range [0, textureWidth - 1] and [0, textureheight - 1]. It is good to use when the texture’s size is the same as the screen.

Difference between texture.Load() and texture.Sample() methods in DirectX?

OnWillRenderObject()

This is an event function called for each camera if the object is visible and not a UI element. It’s called during the culling process before rendering each culled object.

Camera.current will be set to the camera that will render the object.

Field of View

The field of view of the camera is degrees. Unity camera’s FOV is vertical, while horizontal is depends on the viewport’s aspect ratio. To calculate the height of the viewport, we first convert FOV to radian, and divided it by 2. Then we can use tangent and the distance between the camera and the far plane to calculate the half height.

var h = Mathf.Tan(Camera.main.fieldOfView * Mathf.Deg2Rad * 0.5f) * distance * 2f

Quad vs. Plane

Plane is a flat square with 10 units (200 triangles) of edge in the XZ plane. Quad is also a flat square but only has two triangles in the XY plane. They are usually interchangeable but simpler geometry can be displayed by Quad.

Depth Texture

In URP, any opaque objects (render queue < 2500) will be written in the depth texture. Built-in requires a ShadowCaster pass.