Setting constants to shaders

Started by
5 comments, last by sirob 19 years, 6 months ago
Hi, I'm trying to find out, how to set structures and arrays to shader? For example: I have in shader: struct DIRECTIONAL_LIGHT { float3 Direction; float4 Diffuse; float4 Specular; }; DIRECTIONAL_LIGHT DirLight; Is it correct to set it like this: struct DirectionalLight { D3DXVECTOR3 Direction; D3DXVECTOR4 Diffuse; D3DXVECTOR4 Specular; }; DirectionalLight DirLight; ConstantTable->SetValue(Device, LightDirHandle, &DirLight, sizeof(DirLight) ); ??? What about setting second member of array? (Example: DIRECTIONAL_LIGHT DirLight[4]; How to set DirLight[2] ???) How is ID3DXConstantTable interface exatly working? What is in the constant table? How is constant handle search done? Thanks for answer Filousov
Advertisement
To access an array of constants, you can use "arrayName[index]" (ie DirLight[2]). So, you can just do this:
// Initialization// Get the handles of each of the array membersD3DXHANDLE LightDirHandle0 = ConstantTable->GetConstantByName( NULL, "DirLight[0]" );D3DXHANDLE LightDirHandle1 = ConstantTable->GetConstantByName( NULL, "DirLight[1]" );/* And so on...*/// Run-time// Set each of the values using the handlesConstantTable->SetValue(Device, LightDirHandle0, &DirLight, sizeof(DirLight));
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Hi,
still the structure is not set to shader:

I have structure in shader:
struct DIRECTIONAL_LIGHT
{
float3 Direction;
float4 Diffuse;
float4 Specular;
};

DIRECTIONAL_LIGHT DirLight;

But by calling:
ConstantTable->SetValue(Device, DirLightHandle, &DirLight, sizeof(DirLight) );

member DirLight is not set!!!
Why?
Must I set each member of DIRECTIONAL_LIGHT separately?

I'm suffering very much, that Microsoft is not able to properly document such things.

Thanks for answer

Have you tried SetFloatArray() with a size of 11?
Sirob Yes.» - status: Work-O-Rama.
I tried it and the shader gets not the same data:

Data set:
Direction (-1, -1, 0)
Diffuse (1, 1, 1, 1)
Specular (1, 1, 1, 1)

And in pixel shader I have:
Direction(-1, -1, 0)
Diffuse (-1, -1, 0, 1) ????
Specular (1, 1, 1, 1)
It's interesting, that changing order of struct members makes setting using SetFloatArray correct.

So good order is:
struct DIRECTIONAL_LIGHT
{
float4 Diffuse;
float4 Specular;
float3 Direction;
};

I tried both orders with same constant setting method using SetFloatArray. Only good order worked.

Trying to set structure using SetValue at once result in no error, but NOTHING IS SET!!!!



perhaps the struct is organized according to size, somehow. First the float4 then float 3.
Sirob Yes.» - status: Work-O-Rama.

This topic is closed to new replies.

Advertisement