Jump to content
  • Advertisement
Sign in to follow this  
AxeGuywithanAxe

VertexLayout

This topic is 826 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

Hey guys and gals, so I'm currently working on my shader generator and I wanted to get a feel on how you some of you abstract away the vertex declaration and vertex formats. Depending on user provided features , i.e if this shader will be used for static meshes, oceans, and etc, I generate a set of permutations. As of now my resources are split like so;

  One File per vertex type, i.e "StaticMeshFeature.hlsl" , "OceanFeature.hlsl" , "SkeletalMeshFeature.hlsl", each of these files provide features for accessing world position, tangents, and etc.. so for example StaticmeshFeature will have a file that looks somewhat like this :


class CStaticMeshVertexLayout
{
   float3 Position : POSITION0;
   float3 Normal   : NORMAL;
   float3 Tangent  : TANGENT;
   float2 UVs[NUM_SHADER_UVS] : TEXCOORD0
};

//define the current feature vertex type for subsequent shader usage
#define FeatureVertexLayout CStaticMeshVertexLayout

//helper functions called by shaders, such as the base pass shader, velocity shader, etc.
float3 GetFeatureLocalPosition(in FeatureVertexLayout Vertex)
{
   return Vertex.Position;
}

float2 GetFeatureTexCoord(in FeatureVertexLayout Vertex, in uint UVIndex)
{
  return Vertex.UVs[UVIndex];
}

etc...


In C++ I then use a class factory system that connects the c++ vertex description to the shader file. This class factory contains the general vertex declaration , the position only vertex declaration, for static meshes and etc, and the instancing vertex declaration, and certain flags, i.e if the vertex file supports instancing , tessellation, etc. This file looks somewhat like this :




class CStaticMeshVertexLayout : public CVertexLayout
{
public:
   DECLARE_VERTEXLAYOUT_TYPE(CStaticMeshVertexLayout)

   void InitDeclarations()
    {
      ..initialize all of the vertexdeclarations to match the shader side vertex declarations 
   }
};

IMPLEMENT_VERTEXLAYOUT_TYPE(CStaticMeshVertexLayout,"StaticMeshFeature.hlsl", VLF_CanInstance | VLF_SupportsTessellation | VLF_SupportsPositionOnly);


Share this post


Link to post
Share on other sites
Advertisement

So to make sure I have what you are asking correct here, you are making a C++ program that allows access to data for models being drawn by your shader? So you're asking us what our HLSL shaders normally look like so you have an idea of what most devs shaders will look like? It's a bit unclear what you're asking.

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!