Hello guys,
I am relatively new to monogame, and I am just trying to draw a basic 3d cube and enable lighing.
So drawing the cube works, but if enable Lighting via “effect.EnableDefaultLighting()” i get the following error.
System.InvalidOperationException: “An error occurred while preparing to draw. This is probably because the current vertex declaration does not include all the elements required by the current vertex shader. The current vertex declaration includes these elements: SV_Position0, COLOR0.”
I have read through quite a bit of similar errors, but i couldn’t fix it.
i importet it with the fbx importet and defaulteffect is set to BasicEffect.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.VertexColorEnabled = true;
effect.EnableDefaultLighting();
effect.View = viewMatrix;
effect.World = worldMatrix;
effect.Projection = projectionMatrix;
//effect.LightingEnabled = true; // turn on the lighting subsystem.
effect.DirectionalLight0.DiffuseColor = new Vector3(0.5f, 0, 0); // a red light
effect.DirectionalLight0.Direction = new Vector3(1, 0, 0); // coming along the x-axis
effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0); // with green highlights
}
mesh.Draw();
}
base.Draw(gameTime);
}