.net, 3D, C#, Game Development

Balder 0.8.8.5 pulled – why ?

A couple of days ago I published a new version of Balder; 0.8.8.5. It had a bunch of improvements in it, especially when it comes to the Silverlight Control support. I had to pull the release mere hours after its release. The reason for pulling it was that I did a lot of optimizations in the rendering, or at least I thought I did. Turns out that when running on a very fast Dual core or Quad core computer, it was faster – but on slower machines, it turned out to be quite slow. 

Instead of reverting the entire optimization, I've decided to actually get the performance up quite a bit. I've been working on a new rendering pipeline that would increase the performance dramatically, so no time like the present.

The biggest change however with the release was the Xaml support. In the Development branch over at GitHub you will find source code with the rendering pipeline being the same as in version 0.8.8.0, but with all the new Xaml support. So if you can't wait for the optimizations and want to get your Xaml right from the start – you should go pull the latest on the Development branch and compile the binaries yourself. In fact, it should be fairly simple to do it, just download it and run the build.cmd file from a command prompt and it will output a Drop directory with all the binaries in it.

Standard
.net, 3D, C#, Game Development, XNA

Speaking at Software 2010 with Petri Wilhelmsen

On the 9th of February, Software 2010 is kicked off. Petri Wilhelmsen and myself will be holding an hour on game development with managed code using Microsoft Xna and Silverlight (featuring Balder). We will be focusing on 3D development and cross-platform using .net.

Really looking forward to doing a co-op with Petri.

For more details and signup, go here

Standard
.net, C#

Silverlight Courses 2010

2010 is going to be a busy year for me, along side consultancy for several customers, I've been scheduled to do a few courses. Silverlight is the topic for all but one of the courses.

You'll find all the courses in this overview of all of Bouvets courses here.

Even though, listed as Silverlight 3 specific, they will be focusing on Silverlight in general and will include some of Silverlight 4 as well. We're looking into putting up a Silverlight 4 specific course as well. 

So, if you want to get your hands dirty and start learning Silverlight, these courses are the place to be. 

Update 9th of December 2009, direct links to the courses:

 

Standard
.net, 3D, Balder, C#, Game Development, WPF

Balder gets declarative

We're getting closer to the BETA mark for Balder, and we're starting to get most of the features we want in for version 1 ready. The latest feature is the ability to declaratively through Xaml get Balder up and running. Current release is versioned 0.8.7 and can be found over at the Balder page at Codeplex.

By adding the following namespace declaration in your Xaml file:

[code:c#]xmlns:Core="clr-namespace:Balder.Core;assembly=Balder.Core.Silverlight"[/code]

You now get a set of extra controls that can be used.

First off is the RenderingContainer:

[code:c#]
<balder:RenderingContainer x:Name="_renderingContainer" Width="800" Height="600" BackgroundColor="Black"/> 
[/code]

You need to specify the Width and Height, as that is used to setup the display properly. The BackgroundColor property can be any color, including transparent – which is great if you want to mix with existing Silverlight controls on your page. 

The next control we've added is the Mesh control, it enables you to add any Mesh from a file/resource to the RenderingContainer. You do this by accessing the Nodes property on the Container and putting up a RenderedNodeCollection and put your Mesh(es) within that.

[code:c#]
<balder:RenderingContainer.Nodes>
       <balder:RenderedNodeCollection>
             <balder:Mesh x:Name="_audi" AssetName="audi.ASE"/>
        </balder:RenderedNodeCollection>
</balder:RenderingContainer.Nodes>
[/code]

For now, there is a limited amount of DependencyProperties exposed, so manipulation via Storyboards aren't possible today, but will be very soon. The only way to access this is by hooking up the Updated event on the RenderingContainer and implement codebehind logic for it, something like this:

[code:c#]
private float _angle = 0f;

private void Updated(RenderingContainer renderingContainer)
{
    _audi.Node.World = Matrix.CreateRotationY(_angle);
    _angle += 0.5f;
    _renderingContainer.Camera.Position = new Vector(0,-5,-20);
}
[/code]

Last but not least, to get it all working, you need to initialize Balder. In your App.xaml.cs file, during the Application_Startup event, you need to add one line of code. It is very important for now that you add that line before your page (RootVisual) is created and set.

[code:c#]
  private void Application_Startup(object sender, StartupEventArgs e)
  {
   TargetDevice.Initialize();
   RootVisual = new Page();
  }
[/code]

I you want to use it the "conventional" way – non Xaml based, you need to add a similar line of code, but that line of code needs to be added after the page has been created. This is something that makes absolutely no sense and is something we're trying to fix and make it a lot more sense. Our goal is to get rid of that line of code all together.

A little note, we're not trying to mimick the WPF 3D namespaces at all, we're going our own direction. We don't feel the urge to replicate those, as the purpose of Balder is very different. 

Standard
.net, C#

Bing / Virtual Earth WPF MapControl – Localization issues

I just got an email from a guy that watched my WPF talk on the MSDN Live tour in Trondheim, he had downloaded one of my samples from that talk and gave it a go. But he constantly got this "Script Error" thing. The demo was using the WPF MapControl for Virtual Earth maps. It worked OK in all browsers he had tried. Kinda odd I thought. 

The error message was "String was not recognized as a valid boolean". I googled the error message without any concrete results.

Then it struck me; "could it be… Naahh.. It couldn't,  lets try switching regional format settings.." – I always set mine to English – U.S., without really having any good reason for doing so, seeing that I live in Norway. Anywho, I switched it to Norwegian, and there the same error was. 

The simple solution, codewize, is to set the CurrentCulture to be Invariant:

[code:c#]

System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; 

[/code]

I haven't had time to investigate why this happens, but it sure is kinda odd, since running the map in a browser works and the WPF Control is in fact just a WebBrowser control, using the same browser. 

Standard
.net, 3D, Balder, C#, Game Development

Balder in the news.. sort of..

We're starting to get a little bit of publicity with regards to the Balder project, which of course can hardly ever be a bad thing. 🙂

Gastón Hillar has just published an article on the Dr.Dobbs blog about Balder and the optimizations we've been working on the past couple of months. I think it is pretty much thanks to Gastón that Balder was revitalized earlier this year, and he has been very active with testing all the new bits we've been putting in and given us pin-pointers to were to start looking for optimizations and so on. A huge thanks to him for the article and the go-go-spirit in using Balder and giving us the kick in the behind we needed to get the engine to a more decent level.

You can find the article here.

Gastón has written a few books earlier that can be found over at Packt Publishing.

Standard
.net, C#, WPF

Extensions and Helpers for Silverlight and WPF

Earlier I posted about some extensions I did for Silverlight handling INotifyPropertyChanged and helpers for DependencyProperties. Recently I've had a couple of request to release a downloadable source with samples of their use. Since the original posts (found here and here), I've refined them a little bit and worked out some quirks that was left in the originals.

So, why should one use these kind of extensions and what do they solve?

INotifyPropertyChanged and creating DependencyProperties rely on the usage of literals. When for instance notifying the PropertyChanged event with a change on a particular property, the argument one passes in is the literal holding the name of the property. This is bad for at least a couple of reasons:

  • Refactoring goes out the window – renaming the property means renaming the literals by hand
  • Obfuscation – if one were to obfuscate the code, literals will still stay the same but your propertynames will change – your code is broken

I've wrapped it all in a nice download with both a Silverlight and a WPF version of the code (actually pretty much the same code, you'll find #if(SILVERLIGHT) #else #endif statements where specifics are needed). Also in the download, you'll find a Silverlight sample with a usercontrol implementing a dependencyproperty and a data object using the INotifyPropertyChanged extensions. In addition to this, there are a few other nifty helper classes and extensions for other aspects of both Silverlight and WPF development. Hope you'll find it handy.

The download can be found here.

Standard
.net, 3D, C#, Game Development

Balder gets its long awaited texture support

UPDATE, July 5th 2009: read about Silverlight 3 optimizations here and the alpha release here

Ever since I started the Balder project back in 2007, the main goal has always been to get proper texturemapping support in the engine. At one point I had it all up and running by utilizing the Silverlight Matrix transformations for the brush used to make it scale and skew according to the given texture coordinates.

The problem was speed. I never really figured out what the speed issue was, but I guess the architecture of Silverlight was never built with 3D graphics in mind. 

With the new software rendering technique in place, it is a lot easier to get different drawing techniques up and running. One drawback we ran into when doing everything with "software", we can't utilize the imaging support, such as the PNG decoder that Silverlight has built in, there is no way to get hold of the pixel data. So, the first thing we needed is to have a C# decoder og image data and we started off with PNG. Looking for an existing PNG decoder entirely written in managed code (C# preferably) turned out to be quite an interesting task. After some time googling, I finally came across a project called PR2 that has something called SharpPNG. After bending the code a bit, I got it running in a more generic way and put it in the Balder repository (with all credits intact – ofcourse).

After getting the image loading in place, it was off to write the texturemapping support. With the generic implementation we have for doing triangle drawings at the moment, the task ended up being quite simple.
A snippet from the SimpleSpanRenderer as an illustration:

[code:c#]
        public void Texture(IBuffers buffer, Span span, Image image, ImageContext texture)
        {
            var spreadCount = span.XEnd – span.XStart;
            TextureInterpolator.SetPoint(0, span.ZStart, span.ZEnd);
            TextureInterpolator.SetPoint(1, span.UStart, span.UEnd);
            TextureInterpolator.SetPoint(2, span.VStart, span.VEnd);
            var yOffset = span.Y * buffer.Display.Stride;
            var rOffset = buffer.Display.RedPosition;
            var gOffset = buffer.Display.GreenPosition;
            var bOffset = buffer.Display.BluePosition;
            var aOffset = buffer.Display.AlphaPosition;
            var bufferOffset = yOffset + (span.XStart * 4);
            var depthBufferOffset = (buffer.Width * span.Y) + span.XStart;
            TextureInterpolator.Interpolate(spreadCount);
           
            for (var index = 0; index < spreadCount; index++)
            {
                var z = TextureInterpolator.Points[0].InterpolatedValues[index];
                var bufferZ = (UInt32)(z * (float)UInt32.MaxValue);

                var u = TextureInterpolator.Points[1].InterpolatedValues[index];
                var v = TextureInterpolator.Points[2].InterpolatedValues[index];

                var intu = (int)(u*image.Width)&(image.Width-1);
                var intv = (int)(v*image.Height)&(image.Height-1);

                var texel = ((intv*image.Width) + intu)*4;

                if (bufferZ < buffer.Depth[depthBufferOffset] &&
                    z >= 0f &&
                    z < 1f
                    )
                {
                    buffer.Display[bufferOffset + rOffset] = texture.Bytes[texel + 1];
                    buffer.Display[bufferOffset + gOffset] = texture.Bytes[texel + 2];
                    buffer.Display[bufferOffset + bOffset] = texture.Bytes[texel];
                    buffer.Display[bufferOffset + aOffset] = texture.Bytes[texel + 3];

                    buffer.Depth[depthBufferOffset] = bufferZ;
                }

                bufferOffset += 4;
                depthBufferOffset++;
            }
        }
[/code]

Finally we had to add support for materials in the ASE file loader, I ended up spending too much time trying to figure out a good way to do it with regular expression, ending up with also adding a project by Joshua Flanagan called Readable Regular Expressions in combination with LINQ to RegEx by Roy Osherove. Both projects are now part of the Balder repository as well. The reason for adding them to the repository is for maintenance purposes, seeing that we're targeting Balder for multiple platforms. The better way would probably be to contribute to the projects so they had the modifications or support we need to have for Balder. 

With all this in place, it was texturemania going on:

 

There is also experimental code in the Balder repository for doing spherical environment mapping. This will be part of the material system, so one does not have to think about it in the code.

 

 

You can see both demos in realtime here and here.

Standard