Graphics Reference
In-Depth Information
context.PixelShader.SetSampler(0, linearSampler);
context.PixelShader.Set(pixelShader);
// Draw the number of quad instances stored in the
// indirectArgsBuffer. The vertex shader will rely upon
// the SV_VertexID and SV_InstanceID input semantics
context.DrawInstancedIndirect(indirectArgsBuffer, 0);
This completes our particle renderer class. Now it is ready to use in your
D3DApp class.
24. Within D3DApp.Run , initialize an instance of our particle renderer with the
following code snippet:
var particleSystem = ToDispose(new ParticleRenderer());
// Initialize renderer
particleSystem.Initialize(this);
var totalParticles = 100000;
particleSystem.Constants.DomainBoundsMax =
new Vector3(20, 20, 20);
particleSystem.Constants.DomainBoundsMin =
new Vector3(-20, 0, -20);
particleSystem.Constants.ForceDirection = -Vector3.UnitY;
// Gravity is normally ~9.8f, we want slower snowfall
particleSystem.Constants.ForceStrength = 1.8f;
// Initialize particle resources
particleSystem.InitializeParticles(totalParticles, 13f);
// Initialize simulation timer
var simTime = new System.Diagnostics.Stopwatch();
simTime.Start();
25. And lastly in the render loop which is in turn within D3DApp.Run , add the
following code to update the particle simulation, and then render it:
// 1. Update the particle simulation
if (simTime.IsRunning)
{
particleSystem.Frame.FrameTime = (float)simTime.Elapsed
.TotalSeconds - particleSystem.Frame.Time);
particleSystem.Constants.Time = (float)simTime.Elapsed
.TotalSeconds;
// Run the compute shaders (compiles if necessary)
particleSystem.Update("Generator", "Snowfall");
}
// 2. Render the particles
particleSystem.Render();
 
Search WWH ::




Custom Search