A small suggestion

May 10, 2010 at 3:53 PM

Excellent project! I'll test it if it works in the Xbox, but I assume that it should.

Could be possible to add new types of lights? I'm thinking on directional lights, like a flashlight (a cone instead of a circle). Great project anyway, should I credit the project as Krypton?

Aug 15, 2010 at 4:37 PM

Just add a new texture in your project's content and load it to your light.

light.Texture = Content.Load<Texture2D>("myLight");

Open the light included in the engine for a good example of how your texture should look.

Personally, the first thing I did was a light with a dark gray center, because the pure white center was just too "strong".

Aug 16, 2010 at 7:19 AM
Thanks for the tip :)
Aug 27, 2010 at 1:01 AM

Just noticed this project and I made a small class to generate different types of lightning. Maybe you should include this in krypton.

It generates spotlights and directionallights. It's really easy to extend to.

 public class LightTextureBuilder
        public LightTextureBuilder()

        public Texture2D CreateSpotLight(GraphicsDevice device, int size)
            return CreateDirectionalLight(device, size, MathHelper.TwoPi, 0);

        public Texture2D CreateDirectionalLight(GraphicsDevice device, int size, float FOV)
            return CreateDirectionalLight(device, size, FOV, 0);

        public Texture2D CreateDirectionalLight(GraphicsDevice device, int size, float FOV, float nearPlaneDistance)
            /*if (!IsPowerOfTwo(size))
                throw new Exception("The size must be a power of 2");*/
            float[,] Data = new float[size, size];

            float center = size / 2;

            FOV = FOV / 2;

            for (int x = 0; x < size; x++)
                for (int y = 0; y < size; y++)

                    float Distance = Vector2.Distance(new Vector2(x, y), new Vector2(center));

                    Vector2 Difference = new Vector2(x, y) - new Vector2(center);
                    float Angle = (float)Math.Atan2(Difference.Y, Difference.X);

                    if (Distance <= center && Distance >= nearPlaneDistance && Math.Abs(Angle) <= FOV)
                        Data[x, y] = (center - Distance) / center;
                        Data[x, y] = 0;

            Texture2D tex = new Texture2D(device, size, size);

            Color[] Data1D = new Color[size * size];
            for (int x = 0; x < size; x++)
                for (int y = 0; y < size; y++)
                    Data1D[x + y * size] = new Color(new Vector3(Data[x, y]));


            return tex;

        private bool IsPowerOfTwo(int x)
            return (x & (x - 1)) == 0;

Oct 26, 2010 at 10:53 PM


I hadn't realized there were any comments on my codeplex project until now, but I'll take a look at that code as soon as I can and see if we can implement it in the source!

If it does go in, however, I'll be reformatting the code to comply with the Krypton coding standards. Let me know If that's okay with you :)