Passing structures to shaders

From XNAWiki
Jump to: navigation, search

Passing structures to shaders

Passing structures to HLSL is easy, once you know how.

If you are using an array of structures then you start by grabbing an EffectParameter like this...

EffectParameter spv = cell.Parameters["spotlights"];

This gives you a pointer to the array of structures.

If you are using a single structure, the same code gets you a pointer to that structure and you can skip the next step.

To get a single structure from the array you use this code...

EffectParameter el = spv.Elements[index];

To then set the individual elements, which applies to both cases, you use this simple code.

el.StructureMembers["position"].SetValue(location);