Skip to content

An example of drawing numerous instances using Unity3D, compute shaders and Graphics.DrawMeshInstancedIndirect with Frustum & Occlusion culling and LOD'ing.

Notifications You must be signed in to change notification settings

sabriboughanmi/Indirect-Rendering-With-Compute-Shaders

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

License

Copyright (C) 2017-2018 Elvar Orn Unnthorsson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

An example of drawing numerous instances using Unity3D, compute shaders and Graphics.DrawMeshInstancedIndirect with Frustum & Occlusion culling and LOD'ing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 92.6%
  • ShaderLab 5.5%
  • HLSL 1.9%