Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

hlsl structure packing

4: Adsense

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   

278
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

#2 TiagoCosta   Members   

3656
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   Members   

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