What is the status of the XNA 4.0 project?

Jan 5, 2011 at 11:43 PM

xixonia,

I contacted you a bit ago about this, but I was very interested in using the XNA 4.0 version of this project. I was wondering if it was close to completion, and if so if you could commit what you have to the repository so that we could all get a look at it and even help out if possible. I hope that you are using other source control, as there isn't any activity in this repository! But as I said, it would be cool to monitor development and be able to test out what you have, as your update is a couple months old now. Thanks for any info.

Jan 11, 2011 at 8:17 AM

Hi phoenix, I'm trying too to convert the project to XNA 4.0. I found this cheat sheet which you could use too on your attempts to port the project.

Developer
Jan 11, 2011 at 4:57 PM

Phoenix,

We apologize for the delay in getting our XNA 4.0 version out to you. Lot's of work in the past few months has kept us both rather busy, but it looks like we're going to have a free day (or two) in the next week to hammer out an update. We will keep you posted on our progress.

-Dindak

Jan 11, 2011 at 7:50 PM

Dindak,

It's really great to hear from you! I hope that everything is going well for both of you, and that you do indeed push out an update. I appreciate you keeping me and other users posted. I absolutely can't wait to integrate this project with my own!

Coordinator
Jan 14, 2011 at 5:14 AM

Pheonix,

If I remember correctly, you requested some features regarding "shininess" or reflective properties on the shadow hulls. However, the way in which I interpreted the idea differs from the goal of Krypton, in that it is strictly a 2d lighting and shadow engine. Because of this, it would be much faster, in my opinion, to use a port of the Box2D library to do any collision detection logic for the lights being casted, and possibly create additional lights based on those.

That being said, if we get enough time after converting the project to XNA 4, we may start working on additional features.

Jan 14, 2011 at 5:24 AM

xixonia,

I actually don't think that was me that requested anything as far as shininess or reflectivity goes. I did want to know if an object was being hit by a light so that I could implement game effects based on that, but I'm sure if there isn't a way to do that with Krypton I could do it myself with Farseer. Thanks for your work on the XNA 4 project, I still can't wait to use it!

Coordinator
Jan 17, 2011 at 7:28 AM
Edited Jan 17, 2011 at 7:28 AM

Dindak and I got around to working on Krypton this weekend.

Due to the fact that we didn't really know anything about XNA 4, because we haven't dealt with it yet (haha). We decided to start the entire project from scratch, as our prior attempts just left us frustrated. Turns out it had to do with the render states being set in the effect files. BLAH. Long story short, we have a working version of Krypton for XNA 4, but it's lacking some features. Those features will be added sometime this week (hopefully), and we'll upload the first revision Krypton v2 here for everyone to see and download.

I've also contacted Codeplex to transfer our project to TFS, rather than subversion, as we all use Visual Studio anyways (right.. ?) :) However, they're saying I'd need to unpublish, delete, and re-make the account :( - We may go this route, seeing as how we have such few follows. It may be an option to just send each one a message saying they need to re-subscribe :)

Things still to-do for v2 are as follows:

  • Shadow Hull Illumination(so the hulls are excluded from the shaded region)
  • Shadow Hull Occlusion (so the hulls behind other hulls are shaded by the shadow region)
  • Blur (either distance based or 
  • Directional Light
  • Documentation
  • Tutorial ?

Things to-do for future versions:

  • Optimizations - for both rendering, hull transformation, static hulls & lights (*maybe*), etc...
  • Different kinds of lights? (Lazer)
  • Different blur techniques?
  • Support for normal mapping (yes, it will be awesome).
  • HDR & bloom.

I'm also thinking about creating a bitmap based lighting engine (as apposed to the geometry based Krypton), which should allow for more complex shadow casting, 

I'd also like to point out that school will be starting tuesday, and therefore my alloted time for krypton will go way down again. Also, I'm starting a new job as a developer at my company (previously on the support team) tomorrow, and that will require much of my time as well for some time. Also, it means I won't be getting any vacation for at least the next 3 months.

SO. Krypton v2 will be the newest version of Krypton for quite some time. But, you'll all be able to use it in XNA 4, in Reach mode. :)

 

Coordinator
Jan 17, 2011 at 7:50 AM

Scratch that, not Reach. I meant HiDef.

Sorry about that. However, you can modify it to work using the Reach profile, but without windows phone support. Windows Phone 7 doesn't allow custom shaders. Boo.

Jan 17, 2011 at 10:06 AM

Awesome news! Thanks for the hard work :)

Coordinator
Jan 17, 2011 at 5:44 PM

And by modify, I mean change all of the vertex indices to 16 bit. Ie. Int16 vs Int32.

No problem! This is a fun project to work on :)

Jan 17, 2011 at 8:51 PM

This is absolutely fantastic news, I'm extremely excited! Thanks so much for the detailed update and as Pnikosis said, all of the hard work!

Coordinator
Jan 19, 2011 at 5:31 AM
Edited Jan 19, 2011 at 5:31 AM

Just out of curiosity... did you guys care about the blur feature too much?

Coordinator
Jan 19, 2011 at 6:14 AM

Also, what features are you looking for, etc...

So far, I've only implemented a point light. It performs similar to the original, but supports texture rotation... Also, if you need to do any advanced animations on a light, you can implement the ILight2D interface, and add your drawing code in there...

The hull occlusion is working properly, but unlike before it assumes your hulls are not overlapping (otherwise you'll get some artifacts...) I foresee this being a problem with level design, etc, but there are ways around it, and I'll be willing to give advice for that. The artifacts stem from the fact that I'm doing all of the shadowing (including occlusion and occlusion fixes) in a 2 pass shader, rather than using multiple textures and render calls. This makes the whole app much faster. If I recall correctly, I'm getting a pretty substantial increase in framework for the amount of lights I'm using, but I'll need to test that.

I haven't added blur yet (see previous post), and I'm not entirely sure it's beneficial, so I'm not considering it a high priority task, yet.

Currently, I'm more focused on adding comments, and abstracting away some of the more misplaced and ornery code.

Jan 19, 2011 at 8:02 AM

I don't use blur, as I like more the hard-edged shadows. The improvement on the performance (using a 2 pass shader instead of one render call per light) is an awesome new!

Thanks again. If you need help on something, don't hesitate to ask.

Jan 19, 2011 at 2:46 PM

I would definitely experiment with blur given the opportunity, but it's not a requirement I have. It sounds like a great feature for the project in general, although I wouldn't give it a high priority personally.

On the subject of help, once I get something working I can try to write a little tutorial on getting started with Krypton and 4.0, if that would be helpful.

Coordinator
Jan 20, 2011 at 7:13 PM

Looks like blur is going to need to happen on a per light basis, assuming I leave the option open for normal mapping and per pixel lighting.

so, basically...

 

loop each light

ClearShadowMap

DrawShadowToShadowMap

BlurShadowMap (optional per light)

DrawLightOntoShadowMap (with normal mapping)

AddShadowMapToLightMap

end loop

Coordinator
Jan 20, 2011 at 7:15 PM

If you could, write down your games requirements for krypton, as well as feature requests.

Coordinator
Jan 20, 2011 at 7:17 PM

Also, you can check out the source code page for the latests source, in case you're curious how this is all playing out. It's all running, at this point. I'm just adding features.

Jan 21, 2011 at 9:51 AM

Personally my requirements are pretty basic :)

  • Hard-edged shadows
  • Directional lights (cones, that can be done adding additiona hulls though)
  • Lights with dynamic sizes (this means that I can change the light size)
  • Colored lights
  • Good performance, of course.

And that's all I guess.

Jan 21, 2011 at 3:32 PM

Ah, also the chance to acces to the rendertarget instead of directly draw the lightmap, for additional post-processing (in my case I need to use the lightmap for creating some masks) :)

Coordinator
Jan 22, 2011 at 5:07 PM

Out of curiosity... By conic lights, do you also need them to have dynamic FOV? because that would be a bit more work. Otherwise, everything you're asking for is done.

Jan 22, 2011 at 9:36 PM

No need of dynamic FOV. Also camera support, but I guess this is also already there :)

In a future, if it's not too much work (just asking) instead of a cone, a some kind of trapezoid would be awesome. I mean, in the cone, instead of a single point origin like a triangle, a trapezoid. Somethnig like this (the light is aiming down):

 

        ____
      /      \
    /          \
  /              \

Coordinator
Jan 23, 2011 at 8:44 AM
Edited Jan 23, 2011 at 8:47 AM

Ahh... that brings up a valid point. I see what you're saying. You can't use a point light in that scenario because there could be a shadow hull directly above the lamp source. Makes sense. I'll keep that in mind.

Also, I've added dynamic FOV support for the lights. I'm not going to put up a download on the main page, as Krypton for XNA 4 is still in beta, and is lacking a few features. However, if you check out the source code page, you'll see change set 2199. That's the first beta release. Let me know if you run into any trouble with it.

Keys are as follows:

A & Z: Fov change for light

Up & Down: movies light forward and backwards

Left & Right: Rotate's light around it's axis.

Jan 23, 2011 at 11:44 PM

This seems like an excellent release! I'm having some trouble integrating it into my current project. I'm sure that this is on me, but I am using a camera class, and every call to SpriteBatch.Begin I give it this camera class' CameraMatrix property. The code for the camera class is here, with a few adjustments: http://pastebin.com/HKedyi11. I tried just setting Krypton's matrix to the same matrix I'm passing to SpriteBatch every time, but that didn't get me anything but darkness.

Is there any advice or resources I should look at for understanding how to use Krypton's Matrix property properly? I'm still pretty new to XNA, so my ignorance is a bit of a roadblock for me at the moment. I can indeed draw a light over my game, but integrating it with the camera and thus game objects seems to be the issue I can't solve.

Coordinator
Jan 24, 2011 at 12:02 AM

Pheonix,

I'll do some testing to see if it's the engine and get back with you...

Coordinator
Jan 24, 2011 at 2:17 AM

Here's the problem.

Krypton accepts a World * View * Projection (WVP) matrix, whereas SpriteBatch accepts a Transformation matrix. This means that the ONLY matrix Krypton uses it the one you pass to krypton. However, when you pass a matrix to sprite batch, it will multiply it by a prexisting matrix, based on the current scissoring of the render target. In other words, SpriteBatch tries to help you by making the top left hand corner of the screen x=0 y=0, and scaling things to fix on a per-pixel basis. However, this is not what the GPU is accustomed to.

There's two ways to work around this. The less "hacky" way is to create your own vertex and pixel shaders and use that to draw sprites. You can then use normal WVP matrices for rendering, and your sprite batch would accept the same matrix as Krpyton.

The second way is to create a different matrix that Krypton could use. The idea would be to mimic the matrix that SpriteBatch is creating, and multiply your matrix by that. However, I'm sure that's going to something a lot of people are asking to be built into krypton, so I'll try and add it. :)

Jan 24, 2011 at 2:55 AM
xixonia wrote:

Here's the problem.

Krypton accepts a World * View * Projection (WVP) matrix, whereas SpriteBatch accepts a Transformation matrix. This means that the ONLY matrix Krypton uses it the one you pass to krypton. However, when you pass a matrix to sprite batch, it will multiply it by a prexisting matrix, based on the current scissoring of the render target. In other words, SpriteBatch tries to help you by making the top left hand corner of the screen x=0 y=0, and scaling things to fix on a per-pixel basis. However, this is not what the GPU is accustomed to.

There's two ways to work around this. The less "hacky" way is to create your own vertex and pixel shaders and use that to draw sprites. You can then use normal WVP matrices for rendering, and your sprite batch would accept the same matrix as Krpyton.

The second way is to create a different matrix that Krypton could use. The idea would be to mimic the matrix that SpriteBatch is creating, and multiply your matrix by that. However, I'm sure that's going to something a lot of people are asking to be built into krypton, so I'll try and add it. :)

Wow! I'm so glad that you could identify the problem! Like I said, my ignorance would not have helped me get to that point! So if I could multiply my camera matrix by SpriteBatch's mysterious matrix and give that to Krypton, it would ideally work out? I guess that's my big feature request! Do you know how to even go about doing so? I'll try to find some resources and see if I can make something work in the meantime.

Coordinator
Jan 24, 2011 at 3:24 AM

Using reflector, we can see what SpriteBatch is actually doing:

 

Viewport viewport = base._parent.Viewport;
    float num2 = (viewport.Width > 0) ? (1f / ((float) viewport.Width)) : 0f;
    float num = (viewport.Height > 0) ? (-1f / ((float) viewport.Height)) : 0f;
    matrix = new Matrix {
        M11 = num2 * 2f,
        M22 = num * 2f,
        M33 = 1f,
        M44 = 1f,
        M41 = -1f,
        M42 = 1f,
        M41 = matrix.M41 - num2,
        M42 = matrix.M42 - num
    };
    this.effectMatrixTransform.SetValue(this.transformMatrix * matrix);

So, you could mimic this in your own code, or I may add it to Krypton. However, this forces us to set the CullMode to counter clockwise. I'll do a bit more testing and get back with you.

 

Coordinator
Jan 24, 2011 at 3:31 AM

Adding this to KryptonEngine would work, if all of the appropriate cull modes were set to counterclockwise... more on that later:

 

        public void SetMatrixLikeSpriteBatch(Matrix transformMatrix)
        {
            var viewport = this.GraphicsDevice.Viewport;

            float num2 = (viewport.Width > 0) ? (1f / ((float)viewport.Width)) : 0f;
            float num = (viewport.Height > 0) ? (-1f / ((float)viewport.Height)) : 0f;
            Matrix matrix;
            matrix = new Matrix
            {
                M11 = num2 * 2f,
                M22 = num * 2f,
                M33 = 1f,
                M44 = 1f,
                M41 = -1f - num2,
                M42 = 1f - num
            };

            this.mWVP = transformMatrix * matrix;
            this.mEffect.Parameters["Matrix"].SetValue(this.mWVP);
        }

Jan 24, 2011 at 3:33 AM

Thanks for your help, xixonia. I really can't thank you enough for your continuing support.

Coordinator
Jan 24, 2011 at 3:33 AM

Or... I have another idea. :)

Coordinator
Jan 24, 2011 at 3:57 AM

Ok,

So now all you'll do is this:

	this.krypton.Matrix = matrix;
	this.krypton.SpriteBatchCompatablityEnabled = true;
	this.krypton.LightMapPrepare();

However, the SpriteBatchCompatabilityEnabled property need only be set once, as it retains it's value. Also, the property does not effect the Matrix property, as the matrix is evaluated upon preparing the light map. Thus, you can set the Matrix property whenever you please.

 

Coordinator
Jan 24, 2011 at 3:59 AM

Checked in the change. Just download the newest KryptonEngine.cs file, and you should be set to go.

Jan 24, 2011 at 7:51 AM

I just did a ton of fiddling and am still not having any luck. I tried to bring in the camera class I posted into the testbed project but I couldn't get the light or hulls to show up. Did you have a testbed for this addition that you had working? I must be doing something wrong.

Jan 24, 2011 at 7:57 AM

Just sat down to fiddle with my project's camera matrix, after spending an hour or so last night failing to get it to behave. Glad I checked this thread. ;)

New changeset worked perfectly here.

Jan 24, 2011 at 4:13 PM
Edited Jan 24, 2011 at 4:18 PM

[stupid mistake removed ;)]

Coordinator
Jan 24, 2011 at 6:53 PM

Phoenix,

Can you open a new thread or issue so we can resolve this there? :)

I'll try to add a testbed that shows the spritebatch compatibility mode, but it would be best to include your spritebatch.Begin(...), .End(), and Draw(...) code for me, so I can see what's going on.

Jan 24, 2011 at 8:57 PM

xixonia,

I created a new thread, I'll stop filling up this one now!