[Solved] My effect stopped working once I added a light

My effect stopped working once I added a light
My light is

effect.LightingEnabled = true; // turn on the lighting subsystem.
effect.DirectionalLight0.Enabled = true; // turn on the lighting subsystem.
effect.AmbientLightColor = new Vector3(0.5f, 0, 0); // a red light
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

Vertex declaration

    floorVertices = new VertexPositionTexture[]
    {
        new VertexPositionTexture(position, Vector2.Zero),
        new VertexPositionTexture(position1, new Vector2(0, mapHeight)),
        new VertexPositionTexture(position2, new Vector2(mapWidth, 0)),
        new VertexPositionTexture(position3, new Vector2(mapWidth, mapHeight)),
    };

Draw call

        graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, floorVertices, 0, 2);

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, TEXCOORD0.’

The geometry would draw just fine before the lights were added.

Lighting requires normals

You are not supplying any

VertexPositionNormalTexture

1 Like