How do I dynamically change vertex colors using Direct3d 12 and Visual C++?

22 Views Asked by At

Pair of adjacent gradient triangles

I wish to draw several gradient triangles with three-way color interpolation. The triangles will be drawn repeatedly at fixed locations while their vertex colors are gradually changed. I currently do this in an existing application using GDI's GradientFill function. By replacing that antiquated method with Direct3d, I hope to eliminate gradient fill artifacts, and obtain better performance and smoother animation.

In the past I did extensive programing with Direct3d 9, but Direct3d 12 is obviously very different. I have the DirectX 12 Hello World Sample compiled and running in Visual Studio 2019. I have modified the sample to update and render repeatedly, driven by a multimedia timer. I also simplified the sample slightly by using an orthographic projection.

The vertex colors need to be updated for every frame, and the target frame rate is 100 Hz. The colors must be maintained and updated in the CPU, rather than the GPU, because the colors are supposed to change in sync with a musical accompaniment that's generated by the same application via MIDI. Getting the updated vertex colors to the GPU is the issue here.

My application is purely 2D. My triangles are all non-overlapping and lie flat (parallel with the screen). Using a 3D API is overkill, as there's no need for z-buffering or even z-coordinates. The only reason to use a 3D API is that graphics hardware is designed to work in 3D and directly supports ultrafast three-way interpolation of triangles.

Initially I hoped to use Direct2d instead, but as far as I can tell, Direct2d does not natively support three-way interpolation of triangles, and would require writing a custom effect, which looks even more complex and poorly documented than Direct3d 12. I want to use Direct3d 12 because 12 is the current version, and should therefore work the best and be the most widely compatible.

I have not yet figured out how to update the vertex colors of my triangles. My reading suggests that this is maddeningly complicated and I have yet to find a comprehensible example or even a reasonable explanation. I would appreciate any information that would help me better understand what needs to be done, and how best to do it.

0

There are 0 best solutions below