I'm currently trying to show a galaxy and have developed a compute shader that places/moves "stars".
Another vertex/fragment shader reads the buffer and currently places a point at each location.
I'm achieving this by getting a reference to the shader, binding the same compute buffer and then calling Graphics.DrawProceduralNow()
private void InitialiseShaders() {
int itemSize = Marshal.SizeOf(typeof(MapShaderStarDetail));
starLocations = new ComputeBuffer(
numStars,
itemSize);
//....Blah....
mapComputeShader.SetBuffer(Kernel("BuildStars"), "starBuffer", starLocations);
Shader.SetGlobalBuffer(Shader.PropertyToID("starBuffer"), starLocations);
mapMaterial = new Material(mapRenderShader);
mapMaterial.SetBuffer("starBuffer", starLocations);
//....Blah....
}
private void Update() {
mapComputeShader.Dispatch(Kernel("MoveStars"), threadDimensions.x, threadDimensions.y, threadDimensions.z);
}
public void OnPostRender() {
mapMaterial.SetFloat("maxRadius", maxRadius);
mapMaterial.SetPass(0);
Graphics.DrawProceduralNow(MeshTopology.Points, numStars, 1);
}
This works as expected...
However, I need to use an obscenely large number of stars to get the visual density I'm looking for.
Ideally, instead of rending a point at each location, I'd render an instanced billboard with a circular sprite, then significantly reduce the number of stars.
This would also allow me to add dust clouds and similar for added visual complexity.
I've tried swapping MeshTopology.Points
to MeshTopology.Quads
but I've hit two issues:
- The fragment shader only returns one point for each buffer item, so it effectively picks 4 random stars to form a quad, rather than 4 quads per star.
- I don't see any obvious way to keep the billboard angled towards the camera.
I'd prefer to keep the existing data structure (entry per point, rather than entry per billboard corner) if possible, to avoid needless duplicating other properties.
Is this possible?