Jump to content

  • Log In with Google      Sign In   
  • Create Account


hlsl structure packing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 afraidofdark   Members   -  Reputation: 242

Like
0Likes
Like

Posted 13 January 2013 - 04:58 PM

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

Sponsor:

#2 TiagoCosta   Crossbones+   -  Reputation: 2053

Like
0Likes
Like

Posted 13 January 2013 - 05:11 PM

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, 13 January 2013 - 05:15 PM.


#3 Jason Z   Crossbones+   -  Reputation: 4905

Like
0Likes
Like

Posted 13 January 2013 - 08:35 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS