https://github.com/cau777/compute-shader-helper
Simple class to speed up working with compute shaders in Unity
https://github.com/cau777/compute-shader-helper
compute-shader compute-shaders unity
Last synced: about 2 months ago
JSON representation
Simple class to speed up working with compute shaders in Unity
- Host: GitHub
- URL: https://github.com/cau777/compute-shader-helper
- Owner: cau777
- License: mit
- Created: 2021-04-27T13:47:01.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-27T14:15:44.000Z (about 5 years ago)
- Last Synced: 2025-03-24T17:21:22.469Z (over 1 year ago)
- Topics: compute-shader, compute-shaders, unity
- Language: C#
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Compute-Shader-Helper
Simple class to speed up working with compute shaders in Unity
## How to Use
1. Create ComputeHelper object
`ComputeHelper helper = new ComputeHelper(myComputeShader, kernelIndex);`
2. Set properties in the ComputeShader object
`myComputeShader.SetInt("Count", 3);`
3. Create Buffers using the ComputeHelper object. There are 3 types of buffers:
* Write buffer: **writes** the contents of the array to the Buffer in the shader
`CreateWriteBuffer(string name, int size, int stride, Array reference)`
`helper.CreateWriteBuffer("Inputs", inputs.Length, sizeof(float), inputs);`
* Read buffer: **reads** the contents of the Buffer and stores them into the array after the shader is dispached
`CreateReadWriteBuffer(string name, int size, int stride, Array reference)`
`helper.CreateReadBuffer("Outputs", outputs.Length, sizeof(float), outputs);`
* Read/Write buffer: **writes** the contents of the array to the Buffer in the shader and **reads** the contents of the Buffer and stores them into the array after the shader is dispached
`CreateReadWriteBuffer(string name, int size, int stride, Array reference)`
`helper.CreateReadWriteBuffer("ThingToBeModified", thingsToBeModified.Length, sizeof(float), thingsToBeModified);`
4. Run the Shader, specifying the **total** thread count for x, y, z
`RunShader(int x, int y, int z)`
`helper.RunShader(500, 1, 1); // The shader will run 500 times`
After this command, the program retrieves data from the buffers, stores them into the arrays and releases all ComputeBuffers