I am at present making an attempt to point out a galaxy and have developed a compute shader that locations/strikes “stars”.
One other vertex/fragment shader reads the buffer and at present locations some extent at every location.
I am reaching this by getting a reference to the shader, binding the identical compute buffer after which calling Graphics.DrawProceduralNow()
non-public 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 Materials(mapRenderShader);
mapMaterial.SetBuffer("starBuffer", starLocations);
//....Blah....
}
non-public void Replace() {
mapComputeShader.Dispatch(Kernel("MoveStars"), threadDimensions.x, threadDimensions.y, threadDimensions.z);
}
public void OnPostRender() {
mapMaterial.SetFloat("maxRadius", maxRadius);
mapMaterial.SetPass(0);
Graphics.DrawProceduralNow(MeshTopology.Factors, numStars, 1);
}
This works as anticipated…
Nonetheless, I want to make use of an obscenely massive variety of stars to get the visible density I am in search of.
Ideally, as a substitute of rending some extent at every location, I might render an instanced billboard with a round sprite, then considerably cut back the variety of stars.
This might additionally enable me so as to add mud clouds and related for added visible complexity.
I’ve tried swapping MeshTopology.Factors
to MeshTopology.Quads
however I’ve hit two points:
- The fragment shader solely returns one level for every buffer merchandise, so it successfully picks 4 random stars to type a quad, moderately than 4 quads per star.
- I do not see any apparent option to preserve the billboard angled in the direction of the digicam.
I might favor to maintain the prevailing knowledge construction (entry per level, moderately than entry per billboard nook) if potential, to keep away from useless duplicating different properties.
Is that this potential?