• Advertisement
Sign in to follow this  

Using struct and array uniform variables in HLSL

This topic is 4929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement