Sign in to follow this  

Point light

Recommended Posts

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this