Skip to main content
gamedev.net
🔒 Locked

HLSL Structures

Started by Mindowindow Aug 31, 2006 at 3:02 AM 0 replies 1.2k views
Original Post
Mindowindow
Mindowindow
I have never seen the use of structures in HLSL besides for vertex/pixel shader input/output. For this reason I don't even know if what I'm doing is valid... This is in my HLSL effect file:

struct MeshMaterial
{
	vector DiffuseColor;
	vector AmbientColor;
	vector SpecularColor;
	vector EmissiveColor;
	float Power;
};

MeshMaterial Material < string Binding = "Mesh.Material"; >;


The reason I'm using a structure is to simply encapsulate the material into one D3DXHANDLE and to directly parallel the D3DMATERIAL9 structure within the application. This is in the application code:

HRESULT hr = Effect->SetFloatArray(hMaterial, (float*)&material, 17); 


where Effect is a valid ID3DXEffect interface, material is a valid D3DMATERIAL9 structure, and hMaterial is a valid D3DXHANDLE to the "Material" parameter in the effect. hr == INVALIDCALL Either what I'm doing isn't valid or I'm forgetting something? [Edit] Apparently I bypassed the phrase "Gets the handle of a top-level parameter or a structure member parameter." in the ID3DXBaseEffect::GetParameter documentation. I assume this is the issue, but is there any better way to do this than just doing 4 calls to SetFloatArray and 1 call to SetFloat? I thought maybe SetRawValue but I'm not sure if this would be better or not and I'd have to split off the Power since it isn't an even float4 structure. [Edited by - Gondolin on August 31, 2006 3:49:04 AM]
Baltz
Baltz
Hi there

i had similar problems awhile ago and the code i use tha works is as follows



float[] omni_light_data = new float[omni_lights.Length * 8];

for (int i = 0; i < omni_lights.Length; ++i)
{
Array array = omni_lights.GetDataInFloatArray();
array.CopyTo(omni_light_data, i * 8);
}

unsafe
{
fixed (void* thisdata2 = &omni_light_data[0])
{
shader.Effect.SetValue("LightPixelOmni", thisdata2, 4 * (omni_lights.Length * 8));
}
}


SetValue basically takes 3 parameters, the handle, void data , and size of data

so what you might need to do is create a big float array and copy all your values there and then upload that float array

i hope this helps

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.