ThomagicRenderer/readme.md

137 lines
4.9 KiB
Markdown

# 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:
```sh
https://github.com/yourusername/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:
```hlsl
#pragma multi_compile_instancing
#pragma instancing_options procedural:setupThoMagic
```
Ensure that `ThoMagicRendererInclude.cginc` is included after the URP include files:
```hlsl
#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 "ThoMagicRenderer/Shaders/Include/ThoMagicRendererInclude.cginc"
```
Modify your shader structs and functions:
```hlsl
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:
```hlsl
#pragma multi_compile_instancing
#pragma instancing_options procedural:setupThoMagic
```
Ensure `ThoMagicRendererInclude.cginc` is included after the HDRP include files:
```hlsl
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "ThoMagicRenderer/Shaders/Include/ThoMagicRendererInclude.cginc"
```
Modify your shader structs and functions:
```hlsl
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](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 [GitHub Issues](https://github.com/yourusername/ThoMagicRenderer/issues).