This project is read-only.

Help With Camera Matrix

Mar 26, 2013 at 3:13 AM
I've spent the last 4 hours reading practically every post on here and have made little progress so I'm finally giving in an making a post.. I use a camera matrix for drawing and no matter what I try, I can't get Krypton to work with it. I've gotten everything from tiny lights to huge lights to no lights and sometimes the lights stick to the terrain, most of the time they don't. As you can probably tell I'm still a beginner programmer so I'd really appreciate it if someone could post the Krypton matrix code needed to work with my camera..

Here's my camera matrix
transform = Matrix.CreateTranslation(new Vector3(-origin.X, -origin.Y, 0f)) * 
                Matrix.CreateRotationZ(rotation) * 
                Matrix.CreateScale(new Vector3(Zoom, Zoom, 1f)) * 
                Matrix.CreateTranslation(new Vector3(viewport.Width * 0.5f, viewport.Height * 0.5f, 0f));
I would post the Krypton matrix code I've already tried but it's a long list..
And I've tried SpriteBatchCompatablityEnabled = true and CullMode = CullMode... also with varied results.
Mar 28, 2013 at 7:47 PM
Edited Mar 28, 2013 at 7:48 PM
kryptonEngine.Matrix = yourcamera.transform;
kryptonEngine.SpriteBatchCompatablityEnabled = true;
kryptonEngine.CullMode = CullMode.None;
kryptonEngine.Game.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
kryptonEngine.Bluriness = 4;
Just a code dump of what I got working. Thought for me I had to minus the screen width/height to the x/y of the light to get it to line up with the pixel location of my camera.
Mar 29, 2013 at 12:34 AM
Could you possibly post an example of your camera matrix and light creation? I've added your code and the lights follow the terrain but each light is about 5x5 pixels.
Mar 29, 2013 at 12:39 AM
Edited Mar 29, 2013 at 12:40 AM
-Must remember not to reload the page after posting.. xP-
Apr 1, 2013 at 9:50 AM
So, anyone know how I fix the lights being pixel sized when using a camera matrix with no zoom?
Apr 3, 2013 at 9:39 AM
Edited Apr 3, 2013 at 9:44 AM
Hi sorry about the late reply, this forum is so slow at the moment.

My lights I created were 400 in size and came out as 400 pixels in size.

I don't have access to my code right now but I can take a look at your code. How did you create a light?

My matrix is nothing exciting, as I'm still prototyping. The matrix I use is literally all 0s, except 1s for the zoom levels.
Apr 3, 2013 at 10:15 AM
Edited Apr 3, 2013 at 10:19 AM
Thanks Cyber, I appreciate the help. My light creation is the sample CreateLights() for testing. It works like in the sample if I don't use a matrix eg, the lights are full sized and don't move with the world.

Here's all my Krypton related draw code;
krypton.Matrix = camera.transform;
krypton.SpriteBatchCompatablityEnabled = true;
krypton.CullMode = CullMode.None;

spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, camera.transform);
// Drawing

The above produces a patch of lights about 40x40 pixels centered at 0,0 in my world. I've tried taking out the rotation and zoom from my camera matrix as I don't use it anyway but it's still the same.

PS Adding kryptonEngine.Game.GraphicsDevice.RasterizerState = RasterizerState.CullNone; doesn't change anything so I've left it out for now.
Apr 3, 2013 at 10:35 AM
I'm so stupid.. Just looked into the light creation and I see range and x/y were based on a 50x50 resolution in the example..
Apr 3, 2013 at 2:25 PM
Next issue, I can't find where I can set the shadow type from Occluded ect.
Apr 5, 2013 at 8:51 AM
Edited Apr 5, 2013 at 11:02 AM
Twisted wrote:
Next issue, I can't find where I can set the shadow type from Occluded ect.
This is set per light source.
// Example code I use to add a test light.
Light2D newLight = new Light2D()
      Texture = this.lightTexture,
      Range = 450,
      Color = new Color(252, 206, 107),
      Intensity = 1f,
      Angle = (float)(2 * Math.PI),
      X = -550,
      Y = -300
newLight.ShadowType = ShadowType.Occluded;
newLight.Fov = (float)(2 * Math.PI);

You may notice a difference with the RasterizerState when using different types of lights and shadow hulls. Especially when you start using transparent ShadowHulls (but they don't quite work how I'd expect them too anyway).
Apr 5, 2013 at 9:52 AM
Hmm, ShadowType doesn't come up under my lights. I've checked the Light2D/ILight2D classes and have done a search for "ShadowType" and haven't found anything.
Apr 5, 2013 at 11:02 AM
Ah, my mistake. You are using the last stable release am I right?

Try downloading all the code from the Source Code view at the top of this page. I just copy and pasted the contents of each file into a project, built the .DLL and included the .DLL in to my project.
Apr 5, 2013 at 11:29 AM
Thanks Cyber, all working now. Do you know if it's possible to have shadows fill in so they don't just create big beams of shadow?
Apr 5, 2013 at 12:17 PM
Can you elaborate? I'm not sure what you mean.
Apr 5, 2013 at 12:49 PM
It was hard to find examples but this effect, where the shadows extend then kinda fade out.
Apr 5, 2013 at 2:46 PM
Edited Apr 5, 2013 at 2:48 PM
Ah, well the physical reasoning behind the shadows doing that is that it's coming from the sun and the shadows don't stretch far enough due to lights angle. Krypton is strictly 2D so either side on, or top down. Some people have tried with Isometric but it's not designed for it.

If you want to do that you'll need multiple light sources to lighten up the shadow on the other side.

So: Lightsource --> Object --> Lightsource, The further away the light sources are, the stronger and longer the shadow will be.

Krypton works by basically masking the whole world in darkness and then lighting it up. If a light gets blocked then the shadow will cast to the edge of the light source. So to have shadows like that, you'll need a lot of light sources.
Apr 5, 2013 at 2:51 PM
Lightsource --> Object --> Lightsource
That would cause a shadow towards the original light source and would look weird. I guess I'll just leave out shadows for now unless it's something that's meant to be big.
Apr 5, 2013 at 3:00 PM
Edited Apr 5, 2013 at 3:00 PM
You can set a ShadowHulls opacity if you want the shadows to be weaker. However, this causes some weird issues. If you use Occluded light types for example, the shadows cast through the object will make any hulls it hits be pitch black, rather than tinted based on the opacity you'd expect.

And yes, from what I've found Krypton only really supports a dark world being illuminated by light sources. You can tweak/fake it to look different but the best results come from only having major objects (such as ones that block players/objects) cast shadows. I've tried to experiment in getting shadows to look more realistic but unfortunately haven't got far.

If you feel brave enough to edit the engine yourself, you can set up multiple light and hull lists. This way certain lights will ignore certain objects and not cast shadows.

So you could have LightA interact with TreeA but LightB to ignore TreeA. This way you could cut the shadow off as you see fit without casting another shadow towards LightA.

This will change the performance of the engine though.