Procedural Drawing
This commit is contained in:
@ -5,7 +5,15 @@ public class GPUGraph : MonoBehaviour
|
||||
[SerializeField]
|
||||
ComputeShader computeShader = default;
|
||||
|
||||
[SerializeField, Range(10, 200)]
|
||||
[SerializeField]
|
||||
Material material = default;
|
||||
|
||||
[SerializeField]
|
||||
Mesh mesh = default;
|
||||
|
||||
const int maxResolution = 1000;
|
||||
|
||||
[SerializeField, Range(10, maxResolution)]
|
||||
int resolution = 10;
|
||||
|
||||
[SerializeField]
|
||||
@ -37,7 +45,7 @@ public class GPUGraph : MonoBehaviour
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
positionsBuffer = new ComputeBuffer(resolution * resolution, 3 * 4);
|
||||
positionsBuffer = new ComputeBuffer(maxResolution * maxResolution, 3 * 4);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
@ -86,5 +94,10 @@ public class GPUGraph : MonoBehaviour
|
||||
|
||||
var groups = Mathf.CeilToInt(resolution / 8f);
|
||||
computeShader.Dispatch(0, groups, groups, 1);
|
||||
|
||||
material.SetBuffer(positionsId, positionsBuffer);
|
||||
material.SetFloat(stepId, step);
|
||||
var bounds = new Bounds(Vector3.zero, Vector3.one * (2f + 2f / resolution));
|
||||
Graphics.DrawMeshInstancedProcedural(mesh, 0, material, bounds, resolution * resolution);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user