Merge eureka/aetheria-gravity-stardust-bounds (closing verdicts cut-stardust-bounds.s1, cut-stardust-bounds.s2)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
fdecde02d0
4 changed files with 120 additions and 29 deletions
|
|
@ -34,7 +34,6 @@ public class Stardust : MonoBehaviour
|
|||
public Texture Heightmap;
|
||||
public Texture2D ParticleColors;
|
||||
//public Transform TargetTransform;
|
||||
public Camera GravityCamera;
|
||||
|
||||
private const int GROUP_SIZE = 128;
|
||||
private int _updateParticlesKernel;
|
||||
|
|
@ -57,6 +56,11 @@ public class Stardust : MonoBehaviour
|
|||
private ComputeBuffer _quadPoints;
|
||||
private const int QUAD_STRIDE = 12;
|
||||
|
||||
// The dust is drawn by a command buffer on TargetCamera: a camera replays its buffers at their event and never culls them,
|
||||
// so the draw needs no bounds and no extent can fall short of how deep the field is.
|
||||
private CommandBuffer _draw;
|
||||
private const CameraEvent DrawEvent = CameraEvent.BeforeForwardAlpha;
|
||||
|
||||
#endregion
|
||||
|
||||
#region setup
|
||||
|
|
@ -91,6 +95,33 @@ public class Stardust : MonoBehaviour
|
|||
new Vector3(-.5f, -.5f),
|
||||
new Vector3(-.5f, .5f)
|
||||
});
|
||||
|
||||
//The buffers never change after this, so the material is bound once
|
||||
ParticleMaterial.SetBuffer("particles", _particlesBuffer);
|
||||
ParticleMaterial.SetBuffer("quadPoints", _quadPoints);
|
||||
|
||||
//Start may run again (the scene harness calls it by hand): drop the previous draw before building the next
|
||||
DetachDraw();
|
||||
_draw?.Release();
|
||||
_draw = new CommandBuffer { name = "Stardust" };
|
||||
_draw.DrawProcedural(Matrix4x4.identity, ParticleMaterial, 0, MeshTopology.Triangles, 6, Span * Span);
|
||||
AttachDraw();
|
||||
}
|
||||
|
||||
void OnEnable() => AttachDraw();
|
||||
|
||||
void OnDisable() => DetachDraw();
|
||||
|
||||
void AttachDraw()
|
||||
{
|
||||
if (_draw != null && TargetCamera != null)
|
||||
TargetCamera.AddCommandBuffer(DrawEvent, _draw);
|
||||
}
|
||||
|
||||
void DetachDraw()
|
||||
{
|
||||
if (_draw != null && TargetCamera != null)
|
||||
TargetCamera.RemoveCommandBuffer(DrawEvent, _draw);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
@ -104,7 +135,6 @@ public class Stardust : MonoBehaviour
|
|||
// Particle lifetimes cycle on the flow clock (zone time), so the dust stops with the sim like everything the flow moves.
|
||||
ParticleCalculation.SetFloat("phase", FlowField.Cycle(VolumeSampling.FlowClock, Period));
|
||||
|
||||
var pos = GravityCamera.transform.position;
|
||||
ParticleCalculation.SetFloat("period", Period);
|
||||
ParticleCalculation.SetFloat("spacing", Spacing);
|
||||
ParticleCalculation.SetFloat("ceilingHeight", Ceiling);
|
||||
|
|
@ -121,38 +151,17 @@ public class Stardust : MonoBehaviour
|
|||
//Dispatch, launch threads on GPU
|
||||
int numberOfGroups = Mathf.CeilToInt((float)Span * Span / GROUP_SIZE);
|
||||
ParticleCalculation.Dispatch(_updateParticlesKernel, numberOfGroups, 1, 1);
|
||||
|
||||
ParticleMaterial.SetBuffer("particles", _particlesBuffer);
|
||||
ParticleMaterial.SetBuffer("quadPoints", _quadPoints);
|
||||
Graphics.DrawProcedural(ParticleMaterial, new Bounds(pos, new Vector3(Spacing * Span, 2048, Spacing * Span)), MeshTopology.Triangles, 6, Span * Span, TargetCamera, null, ShadowCastingMode.Off, false, 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region rendering
|
||||
// void OnRenderObject()
|
||||
// {
|
||||
// if (Camera.current == TargetCamera || Camera.current.name == "SceneCamera")
|
||||
// {
|
||||
// //Bind resources to material
|
||||
// ParticleMaterial.SetBuffer("particles", _particlesBuffer);
|
||||
// ParticleMaterial.SetBuffer("quadPoints", _quadPoints);
|
||||
// // ParticleMaterial.SetFloat("velocityStretch", ParticleVelocityStretch);
|
||||
// // ParticleMaterial.SetVector("velocity", PlayerVelocity);
|
||||
//
|
||||
// //Set the pass
|
||||
// ParticleMaterial.SetPass(0);
|
||||
//
|
||||
// //Draw
|
||||
// Graphics.DrawProceduralNow(MeshTopology.Triangles, 6, Span * Span);
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region cleanup
|
||||
void OnDestroy()
|
||||
{
|
||||
// m_emitterProxies.Release();
|
||||
// _temperature.Release();
|
||||
DetachDraw();
|
||||
_draw?.Release();
|
||||
_draw = null;
|
||||
if(_particlesBuffer!=null)
|
||||
{
|
||||
_particlesBuffer.Release();
|
||||
|
|
|
|||
Loading…
Reference in a new issue