Question

I'm writing a particle system manager with SlimDX/D3D11, and I'm finding some problems with the constant buffers.

My particle system manager can draw multiple particle systems with different physical characteristics at the same time, and is based on the Particle 3D sample of XNA. The general idea of the draw operation is:

  • context.ClearRenderTargetView(...)
  • render particles
  • swapChain.Present()

The "render particles" operation is implemented like that:

  • shaderTimeGlobalVariable.Set(currentTime)
  • for each pass of the shader technique:
    • apply pass
    • for each particle system:
      • set constant buffer with physical constants (EffectConstantBuffer.SetRawValue)
      • issue one or more context.Draw calls

My problem is that it seems only the last constant buffer call is considered, thus forcing all the particle systems to have the same physical characteristics.

So, first of all: I suspect this is correct/expected, and I'm missing some crucial point. Can anyone clarify me what am I missing?

I expect a solution would be to insert the physical characteristics of the particles into the vertex buffer, with a cost of about 12 bytes more per vertex, thus between 12k and 120k more for each physical system I'm working with. Something I would like to avoid, if possible: is there any other option available?

Was it helpful?

Solution

If you change a shader variable, you have to (re-)apply the pass. So your steps will be:

  • Set time
  • for each particle system
    • set constant buffer
    • for each pass
      • Apply pass
      • Draw

Depending on the actual buffer data, you can reorder the calls for performance optimization.

The reason, why you have to apply the pass after setting the constant buffers, is that the effect framework sends data to the GPU on apply-calls only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top