Hello,
As you can see on the title of this post, i’m having some problems with porting the XNA 3D Particles Sample on MonoGame 3.4.
Before writing this topic, i’ve made some research about this problem and I can’t solve my problem.
Let’s resume what i’ve done so far:
- Create a MonoGame 3.4 project
- Add XNA 3D Particle Sample content into my project’s content
- Add XNA 3D Particle Sample code
At this point, I started the debug and there is a problem with the shader.
Just a little error with those lines:
compile vs_2_0 ParticleVertexShader();
compile vs_2_0 ParticlePixelShader();
Just change them into:
VertexShader = compile vs_4_0 ParticleVertexShader();
PixelShader = compile ps_4_0 ParticlePixelShader();
And problem solved. Next problem is the VertexShaderInput of XNA doesn’t like MonoGame…
XNA structure:
// XNA
struct VertexShaderInput
{
float2 Corner : POSITION0;
float3 Position : POSITION1;
float3 Velocity : NORMAL0;
float4 Random : COLOR0;
float Time : TEXCOORD0;
};
So i made some changes on this structure, and also on the VertexDeclaration to be compatible with MonoGame:
Shader VertexShaderInput structure:
// MonoGame
struct VertexShaderInput
{
float3 Position : SV_POSITION;
float2 Corner : NORMAL0;
float3 Velocity : NORMAL1;
float4 Random : COLOR0;
float Time : TEXCOORD0;
};
VertexDeclaration:
// Describe the layout of this vertex structure.
public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration
(
new VertexElement(0,
VertexElementFormat.Vector3,
VertexElementUsage.Position, 0), // Position
new VertexElement(sizeof(Single) * 3, // sizeof(Vector3)
VertexElementFormat.Vector2,
VertexElementUsage.Normal, 0), // Corner
new VertexElement(sizeof(Single) * 3 + sizeof(Single) * 2, // sizeof(Vector3) + sizeof(Vector2)
VertexElementFormat.Vector3,
VertexElementUsage.Normal, 1), // Velocity
new VertexElement((sizeof(Single) * 3) * 2 + sizeof(Single) * 2, // sizeof(Vector3) * 2 + sizeof(Vector2)
VertexElementFormat.Color,
VertexElementUsage.Color, 0), // Random
new VertexElement((sizeof(Single) * 3) * 2 + sizeof(Single) * 2 + sizeof(Single) * 4, // sizeof(Vector3) * 2 + sizeof(Vector2) + sizeof(Vector4)
VertexElementFormat.Single,
VertexElementUsage.TextureCoordinate, 0) // Time
);
// Describe the size of this vertex structure.
public const int SizeInBytes = (sizeof(Single) * 3) * 2 + sizeof(Single) * 2 + sizeof(Single) * 4 + sizeof(Single); // sizeof(Vector3) * 2 + sizeof(Vector2) + sizeof(Vector4) + sizeof(float)
With this structure, the program compiles and runs, but, nothing is displayed on my screen. No particles… I’m I missing something?
Thanks for your help!
EDIT:
There is the source code on GitHub: https://github.com/ShyroFR/MonoGame-3DParticlesSample