Legacy Documentation: Version 5.2
Compute Shaders
Sparse Textures

Graphics Command Buffers

It is possible to extend Unity’s rendering pipeline with so called “command buffers”. A command buffer holds list of rendering commands (“set render target, draw mesh, …”), and can be set to execute at various points during camera rendering.

For example, you could render some additional objects into deferred shading G-buffer after all regular objects are done.

A high-level overview of how cameras render scene in Unity is shown below. At each point marked with a green dot, you can add command buffers to execute your commands.

See CommandBuffer scripting class and CameraEvent enum for more details.

Example Code

Sample project demonstrating some of the techniques possible with command buffers: RenderingCommandBuffers.zip.

Blurry Refractions

This scene shows a “blurry refraction” technique.

After opaque objects and skybox is rendered, current image is copied into a temporary render target, blurred and set up a global shader property. Shader on the glass object then samples that blurred image, with UV coordinates offset based on a normal map to simulate refraction.

This is similar to what shader GrabPass does does, except you can do more custom things (in this case, blurring).

Custom Area Lights in Deferred Shading

This scene shows an implementation of “custom deferred lights”: sphere-shaped lights, and tube-shaped lights.

After regular deferred shading light pass is done, a sphere is drawn for each custom light, with a shader that computes illumination and adds it to the lighting buffer.

Decals in Deferred Shading

This scene shows a basic implementation of “deferred decals”.

The idea is: after G-buffer is done, draw each “shape” of the decal (a box) and modify the G-buffer contents. This is very similar to how lights are done in deferred shading, except instead of accumulating the lighting we modify the G-buffer textures.

Each decal is implemented as a box here, and affects any geometry inside the box volume.

Compute Shaders
Sparse Textures
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961