Procedural Drawing

This commit is contained in:
2021-01-31 14:03:48 +08:00
parent a64346ee62
commit 2f409b3606
12 changed files with 419 additions and 24 deletions

View File

@ -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);
}
}