Correct view/projection?

Jan 9, 2012 at 10:38 PM
Edited Jan 9, 2012 at 11:50 PM

My camera works well, however I have trouble with the lights. It doesn't even appear if I set the light.Range to be 10000, X=0, Y=0.

If I set krypton.Matrix equal to the Tested's krypton.Matrix, the light appears successfully in the middle of the screen.

Ambient color displays correctly.

Let me know if there's more code I can post!



I might have found the problem. If you set Camera.Position=Vector2.Zero, do normal cameras think the topleft camera corner is, or the screencenter is

Matrix projection=PlayerCamera.Projection;
Matrix view=PlayerCamera.View;
View = Matrix.CreateTranslation() * Rotation * Zoom * CreateTranslation(translateCenter);



Jan 12, 2012 at 9:11 PM
Edited Jan 12, 2012 at 9:30 PM

After a lot of headache, I just realized a big difference:

My game's projection uses:            

projection = Matrix.CreateOrthographicOffCenter(0f, _graphics.Viewport.Width,
                                                             _graphics.Viewport.Height, 0f, 0f,


I've tried to get Krypton to work with OrthographicOffCenter to no avail, anyone have any ideas?



Here's some code:

        public Camera2D(/*GraphicsDevice graphics*/)
            _projection = Matrix.CreateOrthographicOffCenter(0f, _graphics.Viewport.Width,
                                                         _graphics.Viewport.Height, 0f, 0f,
            _translateCenter = new Vector2(_graphics.Viewport.Width / 2f,
                                           _graphics.Viewport.Height / 2f);
       public void SetView()
            _view = Matrix.CreateTranslation(new Vector3(-_currentPosition,0)) *
                    Matrix.CreateTranslation(new Vector3(_translateCenter, 0f));




Inside my Game's Draw


Jan 13, 2012 at 6:06 PM
Edited Jan 13, 2012 at 6:06 PM

Hmm... I'll look into this when I get a chance and get back with you. I don't immediately notice anything.

Jan 25, 2012 at 7:32 PM
Edited Jan 26, 2012 at 2:36 AM

I have the same issue as well. I've ported over the debug rendering (showing wireframe hulls and lights) into my code and they are correctly placed but there are no light effects at all. 

My matrix code in my camera

        public void CreateTransformationMatrix(out Matrix matrix)
            //create matrices
            var translate = Matrix.CreateTranslation(-Location.X, -Location.Y, 0);
            var offset = Matrix.CreateTranslation(viewWidth / 2, viewHeight / 2, 0);
            var scale = Matrix.CreateScale(zoom, zoom, 1);
            var rotation = Matrix.CreateRotationZ(Rotation);

            // transform them into one another
            matrix = translate;
            Matrix.Multiply(ref translation, ref scale, out translation);
            Matrix.Multiply(ref translation, ref rotation, out translation);
            Matrix.Multiply(ref translation, ref offset, out translation);


 And here is where I call krypton



            // draw to the source render target
            lightingEngine.Matrix = drawState.Camera.Transformation;



            #region Dynamic lit objects

            for (int i = dynamicLitObjectCollection.Count - 1; i >= 0; i--)
                var obj = dynamicLitObjectCollection[i];


                    if (obj.DebugRender)

                if (obj.Remove)





 Can't see any lights.. I've tried experimenting with different matrices and my only guess is that I need a projection matrix (I could then see the light effects, but they were severely skewed across the screen and only if I put my mouse pointer on 0,0 aka top left). Any ideas to why that is??


Aha I think I got it now, I think that since you do a negative scale in your LightmapGetMatrix function it flips the quad around (or you just got your cull mode wrong) because I just set the cull mode field to CullMode.CullClockwiseFace and I can see the light.

        /// <summary>
        /// Returns the final, modified matrix used to render the lightmap.
        /// </summary>
        /// <returns></returns>
        private Matrix LightmapMatrixGet()
            if (this.mSpriteBatchCompatabilityEnabled)
                float xScale = (graphics.GraphicsDevice.Viewport.Width > 0) ? (1f / graphics.GraphicsDevice.Viewport.Width) : 0f;
                float yScale = (graphics.GraphicsDevice.Viewport.Height > 0) ? (-1f / graphics.GraphicsDevice.Viewport.Height) : 0f; <- this line

                // This is the default matrix used to render sprites via spritebatch
                var matrixSpriteBatch = new Matrix()
                    M11 = xScale * 2f,
                    M22 = yScale * 2f,
                    M33 = 1f,
                    M44 = 1f,
                    M41 = -1f - xScale,
                    M42 = 1f - yScale,

                // Return krypton's matrix, compensated for use with SpriteBatch
                return this.mWVP * matrixSpriteBatch;
                // Return krypton's matrix
                return this.mWVP;


Jan 28, 2012 at 8:23 PM
Edited Jan 28, 2012 at 8:23 PM

I don't know what happened, but for some reason I got it working with code I already tried before.

This works with Camera Zoom, Rotation (however lights get clipped).

            krypton.CullMode = CullMode.CullClockwiseFace;
            krypton.Matrix = view * projection;



Looking forward to Krypton 3!

Jan 28, 2012 at 9:53 PM

After a little more investigating I found that if you comment out the scissor rectangle code in the light manager's lightmapprepare() the lights no longer get clipped when rotating


            // Render Light Maps
            foreach (var light in this.mLights)
                if (light.IsOn)
                    // Loop through each light within the view frustum
                    if (light.Bounds.Intersects(this.mBounds))
                        // Clear the stencil and set the scissor rect (because we're stretching geometry past the light's reach)
                        this.GraphicsDevice.Clear(ClearOptions.Stencil, Color.Black, 0, 0);

                        // removes the clipping 
                        // this.GraphicsDevice.ScissorRectangle = ScissorRectCreateForLight(light, lightMapMatrix, targetSize);

                        // Draw the light!
                        light.Draw(this.RenderHelper, this.mHulls);
Might have some performance implications but so far so good.

Jan 30, 2012 at 4:51 PM

I'm seriously glad people are starting to use real camera classes with Krypton now. :)

Also, props to you, M6dEEp: "I can see the light."