Sign in to follow this  

Using struct and array uniform variables in HLSL

This topic is 4856 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

This topic is 4856 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this