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 configurado para ejecutarse en varios puntos durante la renderización de cámara.
Por ejemplo, usted puede renderizar algunos objetos adicionales al 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.
Ver CommandBuffer scripting class y CameraEvent enum para más detalles.
Command buffers can also be used as a replacement for, or in conjunction with image effects.
Sample project demonstrating some of the techniques possible with command buffers: RenderingCommandBuffers.zip.
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 usted puede hacer más cosas personalizadas (en este caso, volver borroso).
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 y lo agrega al buffer de iluminación.
Esta escena muestra una implementación básica de “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 Nosotros modificamos las texturas G-buffer.
Each decal is implemented as a box here, and affects any geometry inside the box volumen.