Jump to content
  • Advertisement
Sign in to follow this  
DreadID4

Shader to Declaration

This topic is 4810 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'm looking to convert the vertex shader inputs (HLSL) easily into a vertex declaration. At first I thought it would be easy since we declare the inputs similarly to the vertex declarations themselves:
struct VS_INPUT 
{
   float4 Position : POSITION0;
   float2 Texcoord : TEXCOORD0;
   float3 Normal :   NORMAL0;
   float4 Tangent :  TANGENT0;
};
But so far, I haven't found a way in DirectX to automatically generate a vertex declaration based on the what the compiler saw in the vertex shader input structure. Right now I'm thinking of writing either a proprietary shader file format to define these declarations, or parsing through the shader file myself before handing it over to DirectX. For example, to compute the above input structure I could do the following:
decl[m_vertexDeclIndex].Stream  = 0;            // Always 0
decl[m_vertexDeclIndex].Offset  = streamOffset; // Can be computed by the order of the inputs in conjunction with the size of each input
decl[m_vertexDeclIndex].Type    = declType;     // Can be computed by the size of each input (float1,2,3,4)
decl[m_vertexDeclIndex].Method  = declMethod;   // Always D3DDECLMETHOD_DEFAULT
decl[m_vertexDeclIndex].Usage   = declUsage;    // Can be computed by the identifier following the colon.
decl[m_vertexDeclIndex].UsageIndex = 0;         // Always 0
If any one has any insights as to what I might be able to do to ease the creation of the vertex declarations, I would greatly appreciate it. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by DreadID4
But so far, I haven't found a way in DirectX to automatically generate a vertex declaration based on the what the compiler saw in the vertex shader input structure. Right now I'm thinking of writing either a proprietary shader file format to define these declarations, or parsing through the shader file myself before handing it over to DirectX.


Nope, it doesn't do it automagically. There are two things you can probably do that would be cool:

(1) Parse the VS_INPUT structure and all of its members. All of the info you need will be contained in the parameter description, such as type and semantic. This way is pretty sweet, because you don't need any external files or anything.

(2) Create a simple text-based file for vertex declarations. Just load and parse the file. This way will be easier to do, but less convient to work with.

I would probably go with #1.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!