A gpu driven renderer for Unity 2022.3 srp
 
 
Go to file
Thomas Woischnig fae7d257ab upm update16 2025-02-06 21:56:45 +01:00
Runtime upm update11 2025-02-06 21:14:27 +01:00
CHANGELOG.md upm update13 2025-02-06 21:49:54 +01:00
CHANGELOG.md.meta upm update13 2025-02-06 21:49:54 +01:00
LICENSE.md upm update14 2025-02-06 21:54:52 +01:00
LICENSE.md.meta upm update14 2025-02-06 21:54:52 +01:00
Runtime.meta folder structure 2 2025-02-06 20:12:56 +01:00
package.json first commit 2025-02-06 19:41:47 +01:00
package.json.meta first commit 2025-02-06 19:41:47 +01:00
readme.md upm update16 2025-02-06 21:56:45 +01:00
readme.md.meta folder structure 2 2025-02-06 20:12:56 +01:00

readme.md

ThoMagicRenderer

Overview

ThoMagicRenderer is a GPU-driven rendering system designed for efficiently managing and rendering large numbers of objects with minimal performance impact. Leveraging advanced GPU Instancing techniques, it enables developers to integrate and optimize massive amounts of assets, such as trees, grass, rocks, and other prefabs, without the need for deep expertise in Compute Shaders and GPU infrastructure.

Features

  • Efficient GPU Instancing: Uses Indirect GPU Instancing to handle large numbers of objects efficiently.
  • User-Friendly Integration: No need to master Compute Shaders; provides simple tools for easy setup.
  • Supports Various Assets: Works seamlessly with Unity terrain details, trees, and prefabs.
  • Advanced Culling System: Optimized frustum and occlusion culling for better performance.
  • LOD Management: Automatically adjusts Level of Detail (LOD) settings for optimal rendering.
  • Custom Rendering Parameters: Fine-tune rendering settings to fit project needs.
  • Compute Shader Acceleration: Utilizes Unity's RenderMeshIndirect method and Compute Shaders for peak efficiency.

Installation

ThoMagicRenderer is available as a Unity Package Manager (UPM) package.

  1. Open Unity (2022.3 or later) with a project using a Scriptable Render Pipeline (SRP).
  2. Open Edit > Project Settings > Package Manager and add a scoped registry if required.
  3. Add the package via Git URL:
      https://git.incobyte.de/public/ThomagicRenderer.git
    
  4. Wait for Unity to download and install the package.
  5. Follow the usage guide to set up your scene.

Usage

Shader Graph

To use ThoMagicRenderer in Shader Graph:

  1. Add the ThoMagic Instanced Position subgraph.
  2. Connect it to the Position output.
  3. If you are already using the Unity Position node, replace it with ThoMagic Instanced Position.

HLSL Shaders

URP Shaders

For all passes, include the following pragma directives:

#pragma multi_compile_instancing
#pragma instancing_options procedural:SetupThoMagicRenderer

Ensure that ThoMagicRendererInclude.cginc is included after the URP include files:

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
#include "Packages/com.incobyte.thomagicrenderer/Runtime/Resources/ThoMagicRenderer.cginc"

Modify your shader structs and functions:

struct VertexInput
{
    ...
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct VertexOutput
{
    ...
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

VertexOutput vert(VertexInput v)
{
    VertexOutput o;
    UNITY_SETUP_INSTANCE_ID(v);
    ...
    return o;
}

half4 frag(VertexOutput IN)
{
    UNITY_SETUP_INSTANCE_ID(IN);
    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
    ...
    return o;
}

HDRP Shaders

HDRP shaders follow the same pattern as URP shaders. Include the necessary directives:

#pragma multi_compile_instancing
#pragma instancing_options procedural:SetupThoMagicRenderer

Ensure ThoMagicRendererInclude.cginc is included after the HDRP include files:

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.incobyte.thomagicrenderer/Runtime/Resources/ThoMagicRenderer.cginc"

Modify your shader structs and functions:

struct AttributesMesh
{
    ...
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct PackedVaryingsMeshToPS
{
    ...
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

PackedVaryingsMeshToPS vert(AttributesMesh inputMesh)
{
    PackedVaryingsMeshToPS output;
    UNITY_SETUP_INSTANCE_ID(inputMesh);
    UNITY_TRANSFER_INSTANCE_ID(inputMesh, output);
    ...
    return output;
}

void Frag(PackedVaryingsMeshToPS packedInput, OUTPUT_GBUFFER(outGBuffer) #ifdef _DEPTHOFFSET_ON, out float outputDepth : SV_Depth #endif)
{
    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
    UNITY_SETUP_INSTANCE_ID(packedInput);
    ...
}

Requirements

  • Unity 2022.3+ (or later)
  • Compatible GPU supporting Compute Shaders
  • Scriptable Render Pipeline (SRP)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Pull requests are welcome! If you have any improvements or bug fixes, feel free to contribute.

Contact

For questions or support, please reach out via Issues.