aclysma

I'm porting a c++ particle system to c#. I'm almost finished, but I'm having trouble with the vertex shader and getting data into it. Even when I fill the array of data with known values (like zeroes and ones) I occasionally get a value in PIX as -170805......manyzeroes.000 (maybe it's the least float number possible ) or -1.#QO. This happens maybe once every 10-12 values but it doesn't *seem* to be exact. (this is preVS data).

Also, for some reason Position has 4 values on PIX even though I intend for it to only be a vector3. Color has 4 values (d3dcolor_argb, x, x, x, x) and texcoord has three (which *is* intended).

I'm fairly sure that this is garbage data coming from somewhere. I think serialization between the vertex format and the shader receiving the data. Anyone have some ideas Particularly, I think my custom vertex class needs to be double checked.

Thanks in advance!

-------------------------------

The data I'm feeding my custom vertex:
_vbData[vdataIndex].Position = Vector3.Zero;
_vbData[vdataIndex].Color = Color.Red;
_vbData[vdataIndex].TextureCoordinate = Vector3.One;

Here is a snip of the vertex shader (that is working in c++)
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Diff : COLOR0;
float2 TexCoord : TEXCOORD0;
};

VS_OUTPUT VS(float3 Position : POSITION,
float4 Color : COLOR0,
float3 TexCoord : TEXCOORD0 )


[Serializable]
public struct VertexColorPositionTexture3
{

public Vector3 Position;
public Color Color;
public Vector3 TextureCoordinate;

public static readonly VertexElement[] VertexElements =
new VertexElement[] {
new VertexElement(0,0,VertexElementFormat.Vector3,
VertexElementMethod.Default,VertexElementUsage.Position,0),
new VertexElement(0,sizeof(float)*3,VertexElementFormat.Color,
VertexElementMethod.Default,VertexElementUsage.Color,0),
new VertexElement(0,sizeof(float)*7,VertexElementFormat.Vector3,
VertexElementMethod.Default,VertexElementUsage.TextureCoordinate,0),
};

public static int SizeInBytes
{
get
{
return sizeof(float) * 10;
}
}

//gethashcode, tostring
}




Re: XNA Framework Custom vertex format not working

NeTBaPb

1.new VertexElement(0,sizeof(float)*3,VertexElementFormat.Color, VertexElementMethod.Default,VertexElementUsage.Color,0)

color have 4 floats - a r g b

2. new VertexElement(0,sizeof(float)*7,VertexElementFormat.Vector3, VertexElementMethod.Default,VertexElementUsage.TextureCoordinate,0)

why 7 3 coordinates - 3 floats.






Re: XNA Framework Custom vertex format not working

aclysma

The docs say that that parameter is an offset, not a size. So, [0]x, y, z, [3]a, r, g, b, [7]x, y, z.

Sizeof should be 10 floats, 3+4+3 = 10.

I assume the width of the data is embedded in the VertexElementFormat

Any other suggestions




Re: XNA Framework Custom vertex format not working

Kris Nye

The Xna Color object is only 4 bytes long. (basically an int).

So your total size should be (3+1+3) * 4;

Or you could just use sizeof(VertexColorPositionTexture3) and save yourself the trouble of miscalculating.

Also: be sure to put the attribute     [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential)]
 on your vertex struct declaration just to be safe.




Re: XNA Framework Custom vertex format not working

aclysma

That fixed my problem. For those that might be reading this in the future to debug a problem of your own, don't forget to update the offsets of the vertices.. or you'll get a message about stride lengths when you go to render. :)


The particles are showing up! And it looks great! I can't tell you how good it feels to see this working :) It's only running 40fps and I don't have many particles, but hey, I'll take progress. I'll probably try to post a screenshot later.




Re: XNA Framework Custom vertex format not working

NeTBaPb

ahh, ofc this is offsset parameter, i always mix up with this vert decl:)




Re: XNA Framework Custom vertex format not working

aclysma

I'm hoping that this works:

http://img102.imageshack.us/img102/4702/particlesko9.png

The code will probably be available some day, but not yet. And I'd need to get permission from my friend who's code I ported.