Silverlight 5 RC is now available and you can grab it here.
If you want to know more about non 3D features, here are some interesting posts:
This release also introduces a lot of new features for XNA support in Silverlight 5:
The first thing you will note is the rename of the assemblies:
- Microsoft.Xna.Framework.Silverlight became System.Windows.Xna.dll.
- Audio moved from System.Windows.dll to Microsoft.Xna.Framework.dll
The device is no longer handled by the DrawEventArgs class. It is now available on GraphicsDeviceManager.Current.GraphicsDevice. So it is far easier to initialize your code because you don’t have to wait for the first draw to get the device:
- private void myDrawingSurface_Draw(object sender, DrawEventArgs e)
- // Render scene
- // Let's go for another turn!
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- // Check if GPU is on
- if (GraphicsDeviceManager.Current.RenderMode != RenderMode.Hardware)
- MessageBox.Show("Please activate enableGPUAcceleration=true on your Silverlight plugin page.", "Warning", MessageBoxButton.OK);
- // Create the scene
- scene = new Scene(GraphicsDeviceManager.Current.GraphicsDevice);
A new base class for effect was introduced. It has the same features as the Effect class in XNA.
Obviously the 5 children of this class are also supported:
So from now, you can write the following code:
- // Clearing screen
- GraphicsDeviceManager.Current.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Color(0.2f, 0.2f, 0.2f, 1.0f), 1.0f, 0);
- basicEffect = new BasicEffect(GraphicsDeviceManager.Current.GraphicsDevice);
- basicEffect.VertexColorEnabled = true;
- // Compute matrices
- Matrix world = Matrix.CreateRotationX(rotationAngle) * Matrix.CreateRotationY(rotationAngle);
- Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, -5.0f), Vector3.Zero, Vector3.UnitY);
- Matrix projection = Matrix.CreatePerspectiveFieldOfView(0.85f, aspectRatio, 0.01f, 1000.0f);
- // Affect parameters values
- basicEffect.World = world;
- basicEffect.View = view;
- basicEffect.Projection = projection;
- foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
- // Apply pass
- // Drawing the cube
- // Animate rotation
- rotationAngle += 0.05f;
Actually, this is really simple now to port a XNA 4.0 code to Silverlight 5.
Silverlight 5 RC now supports render target (2d as well as cube). So you can produce stellar effects such as mirrors, real-time environment maps, shadows, etc.
Like in XNA 4.0, you can easily create and affect a render target:
- RenderTarget2D renderTarget2D = new RenderTarget2D(GraphicsDeviceManager.Current.GraphicsDevice, 200, 200, false, SurfaceFormat.Color, DepthFormat.Depth24, 2, RenderTargetUsage.DiscardContents);
You can activate multisample on render targets and on the main DrawingSurface. For the DrawingSurface, you must define it directly in the XAML code:
- <DrawingSurface Draw="OnDraw" x:Name="renderSurface">
- <OffscreenCompositionMode PreferredMultiSampleCount="2" />
You can note the soft edges on the roof for example.
Using the same Xaml tag (CompositionMode), you can also define the depth buffer and stencil buffer format.
- <OffscreenCompositionMode PreferredMultiSampleCount="2" PreferredDepthStencilFormat="Depth24Stencil8" RenderTargetUsage="DiscardContents"/>
And last but not least, the Microsoft.Xna.Framework.Math is now included in the SDK! Vectors, Matrices and other painful mathematical concepts are now handled for you .
Finally Silverlight 5 offers a really well integrated XNA experience. You will be able to reuse directly a large part of your XNA 4.0 code. The only point which is missing is the support for the content pipeline….but…wait…. ^^