Silverlight 3D engine
Cristian Merighi ()
Stub for a real-time software rendering 3D engine in Silverlight 2. Still waiting for new features and capabilities like those exposed by the new born "Astro" Flash Player 10.
This article is obsolete. Some functionalities might not work anymore. Comments are disabled.
3D is becoming a major need in today's web scenario. I think it is absolutely the future of the user interface front-end.
In order to share our interactive 3D stuff across the internet we desperately need appropriate plug-ins with embedded rendering capabilities.
C'mon we're in 2008!
Recently Adobe® came out with the new Flash Player 10 (beta) and its
Astro 3D GPU stuff! Great. For how far you can push
your software rendering techniques and algorithms, the best performances can be obtained only via hardware rendering, and that's indispensable.
Sadly, Silverlight doesn't show the willingness to pursue this path right now (let us just wait and see what happens in the forth-coming future),
on the other end, the extensibility capabilities that the DLR together with the Visual Studio IDE permit may push someone to try to
experiment the software rendering road... someone it's me!
I've never tried before to build up a 3D engine for real-time rendering and I must admit: it's real fun. There are a lot of factors to
keep in count as you code and the amount of maths involved is challenging.
In the diagram above you can see an extract of the full class diagram for the API;
it misses all the vectors, matrices, quaternions and so-on-stuff which are very similar to those in WPF's PresentationCore assembly.
As a first sample test micro-app for my embrional engine I provided the following link (see picture below).
Several aspects are handled in there: hierarchical relations between visual objects, affine transformations, camera motion, directional lighting...
It is useful to keep in mind that the coordinate system I adopted is a left-handed one: with x-axis going left to right,
y-axis from bottom up and z-axis coming straight from the screen.
How to use it:
- use right and left arrows to rotate the polyhedra around the polar vertical axis of the group.
- use up and down arrows to move the camera around a circumference whose plane is the yz one.
Data about the camera elements are rendered in apposite textblocks positioned on the top left corner.
- you can roll-over the dodecahedron to see its material changing (interactivity with 3D objects).
Ok, you may ask "where's the code?"... I'd love to post some but:
- You can always hack it if you want! ;)
- I can't get rid of a memory leak that makes me crazy, so I better wait to solve this problem before posting any code...
Memory leak issue: my problem is that the
memory usage amount bubbles of several kB's as
transormations and consequent re-renderings occur. As far as I know there's no performance tool for Silverlight to use in these cases, so
I ported my whole API into WPF big daddy's world and everything seems to work fine. Even using
tools like WPFPerf I can't find the pits I'm looking for!
Maybe it's just about a beta 1 issue of Sllverlight that I'll hopefully see fixed in the next releases.
As a prove, see the exact same application running (in debug mode) in the following WPF app (deployed via ClickOnce technology).
Please note how my engine, if run in debug mode, shows useful objects like
- the face edges (black segments),
- the view frustum (rectangle in red),
- the face normals (straight from the dodecahedron faces),
- the faces' point of view rays (green lines which connect the eye of the camera to the barycenter of each face of the dodecahedron)
- numeric textblocks with informations like absolute position in world coordinates and distance from the camera eye.
Next steps are for my Pacem.Silverlight3D engine are:
- handling texture mapping (bitmaps),
- make the whole thing more performing.
See you soon...
Take care. Bye.