Jump to content
  • Advertisement
Sign in to follow this  
martinperry

SlimDX - VertexDeclaration problem

This topic is 3055 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 tried to create VertexDeclaration with color If I use this:
Color4 color;

...
new VertexElement(0, 36, DeclarationType.Float4,
DelarationMethod.Default,
DeclarationUsage.Color, 0)
...
It worked for shader, but without shader my app crash: Direct3D9: Decl Validator: X254: (Element Error) (Decl Element [2]) Declaration can't map to fixed function FVF because color0/color1 cannot have type other than D3DDECLTYPE_D3DCOLOR But If I use this:
int color;

...
new VertexElement(0, 36, DeclarationType.Color,
DelarationMethod.Default,
DeclarationUsage.Color, 0)
...
It didnt crash, but colors are incorect... What is wrong ?

Share this post


Link to post
Share on other sites
Advertisement
DeclarationType.Color is 4 bytes - one byte per component, which is mapped to the 0-1 range in the shader. DeclarationType.Float4 is 16 bytes - one float per component.

I'd suggest using DeclarationType.Color unless you need colours outside the 0-1 range.

Share this post


Link to post
Share on other sites
I tried this


Color4 color;

...
new VertexElement(0, 36, DeclarationType.Color,
DelarationMethod.Default,
DeclarationUsage.Color, 0)
...


It didnt crash neither, but I got still same red color (or better .. colors are incorrect.. i have black / red / weird blue-to-white color... no matter what i set up as color)

If I use DeclarationType.Float4, than colors are correct, but only if it goes thru my shader, otherwise crash, as i posted before.


[Edited by - martinperry on February 11, 2010 6:01:39 AM]

Share this post


Link to post
Share on other sites
In order to make DeclarationType.Color work, you'll need to modify your vertex data as well as the declaration.

Share this post


Link to post
Share on other sites
For VertexDeclaration.Color I have data set-up this way:


private Color4 color;
public Vector3 Position;
public Vector2 texture;
public Vector4 additionalData; //special data needed in shader, without shader its useless

public static int SizeInBytes
{
get { return Vector3.SizeInBytes + Vector2.SizeInBytes + Vector4.SizeInBytes + Vector4.SizeInBytes; }
}

public static VertexElement[] Declaration
{
get
{
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3,
DeclarationMethod.Default,
DeclarationUsage.Position, 0),

new VertexElement(0, 12, DeclarationType.Float2,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 0),

new VertexElement(0, 20, DeclarationType.Float4,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 1),

new VertexElement(0, 36, DeclarationType.Color, //with Float4 ok colors in shader, but crash without shader
DeclarationMethod.Default,
DeclarationUsage.Color, 0),

VertexElement.VertexDeclarationEnd
};
return elements;

}
}

public int Color
{
get { return this.color.ToArgb(); }
set { this.color = new Color4(System.Drawing.Color.FromArgb(value)); }
}


Shader work, without shader crash

Share this post


Link to post
Share on other sites
You need to store your color in the vertex structure as a packed int, not a Color4 for it to work with the fixed function pipeline (ie. without a shader).

Change the following:
private Color4 color;


To:
private int color;


And:
public int Color
{
get { return this.color.ToArgb(); }
set { this.color = new Color4(System.Drawing.Color.FromArgb(value)); }
}


To:
public int Color
{
get { return this.color; }
set { this.color = value; }
}

Share this post


Link to post
Share on other sites
Ah.. I can see now... I thought, that I can do it in one piece. Shader and non-Shader version. I will made 2 VertexDeclarations than.

thanks :)

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!