HLSL Code:
//Lights
struct Light
{
float3 pos;
float3 dir;
int type;
} m_aLights[3];
How can I get/set an effectvariable to m_aLights with Direct3D10?
Thanks
|
say you have a global effect variable in your effect file like:
you have to create a pointer to this in your code like this: declare it:
point to the effect:
Set it:
There are also methods which are called appropriate things such as AsIntVector, AsFloatVector, AsMatrix, SetMatrix, SetIntVector etc for the appropriate types of variables. |
|||
|
This is simple. First skip when you initialize your effect variable AsScalar() or whatever because this is your own structure, and DirectX does not know your stuff. Then, the most important thing is when you refresh effect variables every frame. Do: P.s: if it is already a pointer, pass it without "&", offset (if padding problem, add offset or shift will be shifting everything in your structure by passing in the shader), Note: First, padding can be caused by virtual function thanks to inheritance, so struct should be okay, it is not a class which inherits. Second, in your struct, be sure to place bigger variable first, then place other in a decreasing size order. Make sense? Should be. Therefore, weird things can appear if not power of two with DirectX so if you start with a float4 as color and place couple of vector3 after, add a float between each vector3 as padding and don't worry, you're not going to add these float but they will set your variable's values in the shader to the right BYTE.
That's it. |
||||
|