Reorganizing vertex input structure

Started by
11 comments, last by Dawoodoz 12 years, 5 months ago
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?
Advertisement
What's the point of packing an extra value in the normal?

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


I can't find more names for constant registers.
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
}

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

It's about minimizing the hardware interpolators.
I might have to tell the users to write "(Input.Normal).xz" instead of "Input.Normal.xz" to avoid messing up the error messages.

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

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 :o
http://msdn.microsof...nding_Semantics

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

This topic is closed to new replies.

Advertisement