hlsl structure packing

Started by
1 comment, last by Jason Z 11 years, 3 months ago

Hello,

I pass a material definition structure from c++ to hlsl however in the debug view I see some of the values are NAN

here is my c++, hlsl structure definitions and debug view results. Only unused0 must be NAN I use it as padding variable, however

all other float values are olso NAN I couldn't point out the problem here, may be you can

C++ structure

struct MaterialData {
Vector3 diffuseColor;
float unused0;
Vector3 specularColor;
float specularLevel;
Vector3 ambientColor;
float glossiness;
};
Shader structure
struct material {
float3 diffuseColor;
float unused0;
float3 specularColor;
float specularLevel;
float3 ambientColor;
float glossiness;
};
Shader debug values
diffuseColor x = 0.588000000, y = 0.588000000, z = 0.588000000 float3
unused0 NaN float
specularColor x = 0.900000000, y = 0.900000000, z = 0.900000000 float3
specularLevel NaN float
ambientColor x = 0.588000000, y = 0.588000000, z = 0.588000000 float3
glossiness NaN float
www.lostchamber.com
Advertisement
It also seems right to me.

Try this though:
Change the specularColor to float4 in the shader struct and try to access the specularLevel in specularColor.w (do the same for ambientColor/glossiness).

You can also remove unused0 from the shader structure because hlsl adds padding automatically.

Also double check that the structure is correctly filled with data in C++.

Is you Vector3 class a subclass (that is, does it have any virtual methods) or is it a pure struct-type of object? I wonder if the vtable could be causing some issues here...

This topic is closed to new replies.

Advertisement