Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3966776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:38:30+00:00 2026-05-20T03:38:30+00:00

I made this very simple 3D model exported to .x format with Google SketchUp,

  • 0

I made this very simple 3D model exported to .x format with Google SketchUp, the model is a simple cube and has no textures, only different colors for each of it’s face.

I have written this HLSL code to try to render this model with it’s original colors, but it doesn’t work, I get a "The current vertex declaration does not include all the elements required by the current vertex shader. Color0 is missing" when calling the ModelMesh.Draw() method. Here is my HLSL Code:

float4x4 World;
float4x4 View;
float4x4 Projection;

struct AppToVertex
{
    float4 Position : POSITION0;
    float4 Color    : COLOR0;
};

struct VertexToPixel
{
    float4 Position : POSITION0;
    float4 Color    : COLOR0;
};

VertexToPixel ColoredVS(AppToVertex input)
{
    VertexToPixel output = (VertexToPixel)0;

    float4 iTransformed = mul(input.Position, World);
    float4 iView = mul(iTransformed, View);
    float4 iProjection = mul(iView, Projection);

    output.Position = iProjection;
    output.Color = input.Color;

    return output;
}

float4 ColoredPS(VertexToPixel input) : COLOR
{
    return input.Color;
}

technique Colored
{
    pass Pass0
    {
        VertexShader = compile vs_2_0 ColoredVS();
        PixelShader = compile ps_2_0 ColoredPS();
    }
}

This is probably a noob question and I am aware that I could draw this model by simply using the BasicEffect class(which works), but I am doing this just for learning HLSL, and up to now all I was able to do was to draw a model with another color defined in the shader all over the model :[

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:38:30+00:00Added an answer on May 20, 2026 at 3:38 am

    This is the first time i’ve looked at a .X but I don’t believe that Sketchup is exporting vertex colours for your model.

    (Someone who is more experienced with this format please correct me if you see anything wrong!)

    template Mesh {
    <3D82AB44-62DA-11cf-AB39-0020AF71E433>
    DWORD nVertices;
    array Vector vertices[nVertices];
    DWORD nFaces;
    array MeshFace faces[nFaces];
    [...]
    }
    
    template MeshVertexColors {
    <1630B821-7842-11cf-8F52-0040333594A3>
    DWORD nVertexColors;
    array IndexedColor vertexColors[nVertexColors];
    }
    

    Looking at your model’s .X ‘declarations’, I can see the mesh’s geometry, channels such as colours & normals, etc are stored as seperate ‘objects’ (just like they are in the DOM in XNAs Content Pipeline).

    Whereas your model has definitions for position data (Mesh), normal data (MeshNormals) and texture coords (MeshTextureCoords) (all defined below the templates section) I can see no section of the type MeshVertexColors.

    Instead it appears that four Materials are defined, and applied to your models faces using the

     template MeshMaterialList {
    <F6F23F42-7686-11cf-8F52-0040333594A3>
    DWORD nMaterials;
    DWORD nFaceIndexes;
    array DWORD faceIndexes[nFaceIndexes];
    [Material]
    }
    

    section.

    So you don’t have any vertex colours for ModelProcessor to import, or your shader to display.

    There is probably an option in Sketchup to enable Vertex Colours. However if you can’t find/don’t want to look for it, you can add and remove vertex channels in the Content Pipeline by creating a Content Processor in a Content Pipeline Extension project.

    (I know this sounds really unpleasant but acctually this is a really great feature when you get used to it!)

    There are quite a few tutorials online about this but in a nutshell:

    1. Go into VS, right click, Add New Project > Content Pipeline Extension Library
    2. In that new project, add a new Content Processor item, something along the lines of that below.
    3. Recompile and then in the Content Processor field of your models .X file entry in the Content project, select your new importer (by the name you give it in the DisplayName attribute)

    What this is doing is essentially intercepting the data from your .X after it has been imported into XNAs Document Object Model, and before it is processed into a new Model class, the processor checks for the presence of a vertex colour channel, and if one is not found, generates and adds it, before the ModelProcessor creates the VertexDeclaration and packs all the vertex data into a VertexBuffer to be loaded by the GPU.

    This will just the display the cube as a solid purple but at least you can see if your shader is working.

    [ContentProcessor(DisplayName = "Processor to make sure we have vertex colours in all models")]
    public class Character_Model_Processor : ModelProcessor
    {
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            foreach(NodeContent c in input.Children)
            {
                if(c is MeshContent)
                {
                    foreach(GeometryContent g in (c as MeshContent).Geometry)
                    {
                        //Stop here and check out the VertexContent object (g.Vertices) and the Channels member of it to see how
                        //vertex data is stored in the DOM, and what you can do with it.
                        System.Diagnostics.Debugger.Launch();
    
                        AddVertexColorChannel(g.Vertices);
                    }
                }
            }
    
            ModelContent model = base.Process(input, context);
    
            return model;
        }
    
        private void AddVertexColorChannel(VertexContent content)
        {
            if(content.Channels.Contains(VertexChannelNames.Color(0)) == false)
            {
                List<Microsoft.Xna.Framework.Color> VertexColors = new List<Microsoft.Xna.Framework.Color>();
    
                for (int i = 0; i < content.VertexCount; i++)
                {
                    VertexColors.Add(Color.Purple);
                }
    
                content.Channels.Add(VertexChannelNames.Color(0), VertexColors);
            }
        }
    }
    

    Good luck, sorry if you already knew most of that, I guess you probably know all about the pipeline modifications if you are writing your own shaders but better safe 🙂

    EDIT: Just a note about that System.Diag… line, if you break into the debugger, make sure you when you’re done exploring that you hit F5 and let it run its course otherwise it takes your main VS window with it when it exits – not a problem just really annoying when you forget to comment it out 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my personal website, I built a very simple dropdown menu system entirely from
This is one of the strangest errors I've ever seen. I'm doing a very
Hey all, I am trying to accomplish something very simple yet getting an error
I'm making a flex 3.5a/air2 application and I've made a popup window but I
I have been working on developing some RESTful Services in Django to be used
I have an application that manages documents called Notes. Like a blog, Notes can
In modern versions of ActiveRecord you can define any number of before_validation handlers using
Just getting started on iPhone dev today and have run through Apple's HelloWorld tutorial:
I have been using asp.net programming just from few months and I have to
A series of applications I'm writing require that the user be able to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.