CrazyEngine / Unity_Indirect-Rendering-With-Compute-Shaders

GPU-Driven in Unity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unity_Indirect-Rendering-With-Compute-Shaders

GPU-Driven demo in Unity Fork from https://github.com/ellioman/Indirect-Rendering-With-Compute-Shaders, the version of witch is 4 May 2019. The project is perfect for GPU-Driven testing, but it is a pity that maintenance stopped long time ago. Respect to the author ellioman.

The following contents are from the original.

Indirect Rendering With Compute Shaders

An example of rendering numerous instances in Unity3D using Compute shaders for culling and LOD'ing and Graphics.DrawMeshInstancedIndirect to draw.

Generative

Generative

Features

  • Tested on Metal (Mac) and D3D11.
  • Quasirandom squences to place the instances
  • Draw things using Graphics.DrawMeshInstancedIndirect
  • GPU Sorting with Bitonic sorting
  • Compute shader: Frustum and shadow caster culling
  • Compute shader: Occlusion culling with HierarchicalZBuffer
  • Compute shader: Detail (Screen Size) Culling
  • Compute shader: LOD objects using the distance from camera to object
  • Simple shadow mode: Only use one shadow mesh for each instance type to lower setpass calls

Project Setup

  • "_Example.cs" script on the "Example" game object:
    • Creates the instance data and sends it to the Indirect Renderer class.
  • "IndirectRenderer.cs" on the "MainCamera" game object:
    • Is the main class in the project. It initializes all the buffers and compute shaders and then dispatches the compute shaders and draws the objects when Unity calls the PreCull() function.
  • "HiZBuffer.cs" script on the "OccluderCamera" game object:
    • Creates a hierarchial Z-Buffer texture that contains the depth texture and shadow map which are used when doing frustum and occlusion culling

TODO

  • Add reprojection of last frame’s depth to the Hi-Z (See "GPU-Driven Rendering Pipelines" below)
  • Improve the instance sorting:
    • On my Macbook pro (mid 2014) sorting takes approx 50% of the GPU time
    • The GPU sorting must support instance numbers that are not in the non power of two
    • Find a better performant approach for the CPU Sorting
  • Create the Hi-Z Texture with compute shaders
  • Try out Raster Occlusion instead of Hi-Z (See "NVidia Siggraph 2014" & "Github - nvpro-samples" below)

Resources

The Unreasonable Effectiveness of Quasirandom Sequences

Kostas Anagnostou - GPU Driven Rendering Experiments

Kostas Anagnostou - Experiments in GPU-based occlusion culling

Kostas Anagnostou - Experiments in GPU-based occlusion culling part 2

Ulrich Haar & Sebastian Aaltonen - GPU-Driven Rendering Pipelines

Sakib Saikia - Going Indirect on UE3

RasterGrid - Hierarchical-Z map based occlusion culling

StackOverflow - Hierachical Z-Buffering for occlusion culling

Daniel E - Hierarchical Z-Buffer Occlusion Culling with multiple samples

bazhenovc - GPU Driven Occlusion Culling in Life is Feudal

NVIDIA - Siggraph 2014 - Scene Rendering Techniques

Github - nvpro-samples/gl_occlusion_culling

GPU Gems 2 - Hardware Occlusion Queries Made Useful

ARM Developer Center - hiz_cull.cs

L. Spiro - Tightly Culling Shadow Casters for Directional Lights (Part 1)

L. Spiro - Tightly Culling Shadow Casters for Directional Lights (Part 2)

nonoptimalrobot - Shadow Volume Culling

Stephen Hill and Daniel Collin - Practical, Dynamic Visibility for Games

zeuxcg.org - View frustum culling optimization - Representation matters

About

GPU-Driven in Unity


Languages

Language:C# 92.7%Language:ShaderLab 5.4%Language:HLSL 1.9%