Git Product home page Git Product logo

indirect-rendering-with-compute-shaders's Introduction

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.

indirect-rendering-with-compute-shaders's People

Contributors

ellioman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

indirect-rendering-with-compute-shaders's Issues

general inquiry about hiZ buffer

Hello Ellioman,
I am using this project as a foundation to do something similar in HDRP, while also adding support for amplify shader editor and shadergraph. While I have it working in hdrp with shadergraph and ASE, I have a few questions about how you have things setup.

  1. do you think it would be possible to use HDRPs depth buffer instead of the hiz buffer you are using?
  2. what is the purpose behind sampling the hiz buffer so many times?

WOW!

That is all I have to say

instance amounts that arent a power of 2

Hello,
I am creating a version of this that works by "painting" instances much like unitys terrain system, but for HDRP. when im dealing with instance numbers that != 2^n, where n >=11, my instances are flickering in and out of existence and acts very glitchy in general. what is the cause of this, and whats the best way of going about fixing it?

All LODs Render Before LOD Ranges

LOD1 And LOD2 are always present, and are just 'hiding' inside the next highest up LOD. Noticed the issue when attempting to swap meshes out from the sphere.

Occlusion culling working ?

Hi there,

Very interested in this, is it supposed to work or is it a work in progress ?
I have tried this project on Unity 2017.3f but the occlusion culling does not seem to do anything except when the object is out of the camera view, which I don't think is what it's supposed to.

Thanks

Number of instances > 65536 = no rendering

Hi,

This is a great project, thanks for sharing it. Quick question:

On an AMD RX 480 everything works fine until I crank the number of instances up past 65536 (using the drop down menu in Example.cs inspector). If I do this, it starts to render (a few spheres show when I hit play) and then no instances appear in the following frames.

Is this an issue you're aware of or come across?

Simple Shadows working?

Hi,
This is an exciting project. I'm trying it out to render detail meshes on other meshes (transferred from a terrain).
The 'Enable Simple Shadows' option seems to have no effect in the sample scene.
I've tried disabling the scene view.
I'm using Unity 2018.2.18f1.
Thanks.

It is not compatible with URP

Error when building apk in Unity 2020.3, while build successfully but show nothing when changing to URP. It should be the shader's problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.