Using struct and array uniform variables in HLSL

Started by
0 comments, last by RenderTarget 19 years, 8 months ago
I'm writing a per-fragment lighting shader in HLSL and I'd like to use user-defined structures and arrays as uniform variables as in the following:

// fragment shader code 

/*
 input/output vertex structures snipped
*/

struct LightSourceParams
{
	int type;
	float4 diffuse;
	float4 specular;
	float4 ambient;
	float3 position;
        // ...
};

struct MaterialParams
{
	float4 diffuse;
	float4 specular;
	float4 ambient;
	float4 emissive;
	float power;
};


uniform LightSourceParams Lights[4];  
uniform MaterialParams FrontMaterial;
uniform bool LightEnabled[4]; 

// functions, etc.
My shader with this code compiles and runs but I can't get handles to the struct or array members using ID3DXConstantTable functions:


// this returns zero (i.e. null handle)
D3DXHANDLE le = FConstTable->GetConstantByName(NULL, "LightEnabled");

// so does this
D3DXHANDLE lightSource = FConstTable->GetConstantElement(FConstTable->GetConstantByName(NULL, "Lights"), 0);

// and since I can't get handles to the parent structure, 
// I can't access structure members
D3DXHANDLE spec = FConstTable->GetConstantByName(lightSource, "specular");


Can anyone explain to me how this works (or if it is even possible to do it this way)? Reading the DX documentation, it seems like this would be the way to do it but I must be missing something. Jason
Advertisement
Ugh. Sorry for the late reply.

Are you using these values in your shader? If they're not getting used, the compiler will optimize these out, and they won't be available in the constant table.
[sub]My spoon is too big.[/sub]

This topic is closed to new replies.

Advertisement