• Advertisement
Sign in to follow this  

hlsl structure packing

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

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
 

Share this post


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

Share this post


Link to post
Share on other sites

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...

Share this post


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

  • Advertisement