Primitives Rendering black.

Hi iv been messing with basic lighting on the basiceffect. However my primitives are rendering black. Here is where I’m enabling lighting

`public void EnableLighting()
{

_effect.EnableDefaultLighting();
_effect.LightingEnabled = true;
_effect.AmbientLightColor = Color.Red.ToVector3();
}`

then here is where I render

`
foreach (EffectPass pass in camera._effect.CurrentTechnique.Passes)

            for (int i = 0; i < _parts.Count; i++)
            {

                pass.Apply();

                _device.DrawUserPrimitives(PrimitiveType.TriangleList, _parts[i]._verts, 0, _parts[i].PoligonsToRender, 
                    VertexPositionColourNormal.VertexDeclaration);
            }`

No matter what I do I just get a black cube. Any suggestions?

Are you assigning any colour to your vertices when you create them or is it just zero (black)?
Also try setting _effect.VertexColorEnabled to true.

yes I have them set to white I will see if the vertexcolorenabled helps.

I only have a second to offer a single line of hope real quick, and that is that I am positive this issue has been raised and solved in a previous post, it might even have been one of mine…

I had the same problem.

First, use a Vertex type that can store the Normal for each point of your triangle. I’m assuming you are doing this otherwise you’d get an exception when enabling the lighting for BasicEffect.

Second, make sure you calculate the Normal for each triangle. If you leave it at default 0,0,0 they will render in black.

This tutorial got me on the right track: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series1/Terrain_lighting.php

1 Like