# Reorganizing vertex input structure

This topic is 2608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I use DirectX 11 and shader model 4.

I am reorganizing the vertex structure in my graphics engine to allow bone animation.
The problem is that I have packed both normals and selection in "NORMAL" by giving xyz to the normal and w to selection but I don't want the users to rewrite their shaders.

HLSL:
 struct VS_structure { float4 Pos : POSITION; float4 Tex : TEXCOORD; float4 Color : COLOR; float4 NormalAndSelected : NORMAL; float4 A : BINORMAL; float4 B : TANGENT; float4 BoneData : TEXTURE; }; 

These macros are working for most shaders but not the ones that are already accessing specific elements of the normal.
HLSL:
 #define Normal NormalAndSelected.xyz #define Selected NormalAndSelected.w 

How do I define 2 variables on the same registry in VS_structure?

##### Share on other sites
What's the point of packing an extra value in the normal?

##### Share on other sites

What's the point of packing an extra value in the normal?

I can't find more names for constant registers.

##### Share on other sites
You can separate the input structure of shader and a structure which users can operate on. HLSL compiler will optimize it away. Say:

 struct VS_packed_input { float4 Pos : POSITION; float4 NormalAndSelected : NORMAL; }; struct VS_input { float4 Pos; float3 Normal; float1 Selected; }; struct VS_output { float4 Pos; float3 Normal; // stuff }; VS_input unpack(VS_packed_input input) { // unpack and return } VS_output VS(VS_packed_input packed_input) { VS_input input = unpack(packed_input); // do stuff and return VS_output }

##### Share on other sites

What's the point of packing an extra value in the normal?

It's about minimizing the hardware interpolators.

##### Share on other sites
I might have to tell the users to write "(Input.Normal).xz" instead of "Input.Normal.xz" to avoid messing up the error messages.

##### Share on other sites

I might have to tell the users to write "(Input.Normal).xz" instead of "Input.Normal.xz" to avoid messing up the error messages.

Can you elaborate a bit about what errors?

##### Share on other sites
If I go around the user too much, making a mistake and getting reports from the HLSL compiler will make no sense. Even the macros can cause confusion when the compiler is quoting something that does not exist in the shader.

##### Share on other sites
I misunderstood, I thought the errors would come from my example. I understand the macros will not work that way. Macros usually ruin the error messages aswell. You could surround the macro values with parantheses. I was only suggesting a solution without macros, a one which I've implemented few times.

Can you say who are these users which you're talking about?

##### Share on other sites

I misunderstood, I thought the errors would come from my example. I understand the macros will not work that way. Macros usually ruin the error messages aswell. You could surround the macro values with parantheses. I was only suggesting a solution without macros, a one which I've implemented few times.

Can you say who are these users which you're talking about?

The engine is mostly used from Visual Basic and I try to keep it simple for beginners.

The best solution would be to find another constant register name. It would be weird if there was only 7 names since that is not a power of 2.

Edit:
There was only 7 names
http://msdn.microsof...nding_Semantics

Edit 2:
It is now working by moving selection to the PSIZE register Thanks for your time

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013734
×