Point light

Started by
4 comments, last by GregMichael 14 years, 1 month ago
Hello trying to get a point light to work. My game is 2D so I just have a camera facing a plane of squares. I have each square a normal that is pointing towards the camera (I guess this is right way). And a material with ambient and diffuse set to white. here is my code
[source = "csharp"]

        Material m = new Material();
        m.Ambient = new Color4(1f, 1f, 1f, 1f);
        m.Diffuse = new Color4(1f, 1f, 1f, 1f);

        device.Material = m;

        device.SetRenderState(RenderState.Lighting, true);
        device.SetRenderState(RenderState.Ambient, Color.White.ToArgb());
        device.SetRenderState(RenderState.AmbientMaterialSource, ColorSource.Material);
        device.SetRenderState(RenderState.DiffuseMaterialSource, ColorSource.Material);

        Light light = new Light();
        light = new Light();
        light.Type = LightType.Point;
        light.Position = new Vector3(0, 0, -1);
        light.Ambient = Color.White;
        light.Diffuse = Color.White;
        light.Range = 500;
        light.Attenuation0 = 1f;
        light.Attenuation1 = 0f;
        light.Attenuation2 = 0f;
        //light.Direction = new Vector3(0, 0, 1f);

        device.SetLight(0, light);
        device.EnableLight(0, true);

This just gives me black. I check in PIX and the normals are correct.
Advertisement
The light must be on the same side of the squares as the camera and, since it's a point light, close enough to the squares to illuminate them.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Light light = new Light();
light = new Light();

Not related to your problem...but not good.
ty guys i get better idea now


Sry, I just so happy with outcome that I have to post picture ^_^
Congratulations !

This topic is closed to new replies.

Advertisement