Jump to content
  • Advertisement
Sign in to follow this  
Dawoodoz

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites

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

It's about minimizing the hardware interpolators.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


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

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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!