Tom's Blog

Musings on Windows, Graphics, and Technology

Direct2D Sample Videos

Direct2D Sample Videos

  • Comments 17
  • Likes

ChartDemo.wmv -- Although D2D can render thousands (the exact amount depends on the video hardware that's used, quality of drivers, amount of memory, etc) of anti-aliased primitives per second, there are some cases where even greater performance is required. ChartDemo demonstrates an alternative approach that uses aliased lines and rectangles (primitives that have been highly optimized in D2D) along with MSAA rendering (via D3D interop). With this approach, ChartDemo is able to scale much further.

 

Chomp.wmv -- This demo started out as a simple 2D Pac Man-like game and, gradually, we kept adding features; for example, zooming, god-mode and, unlike the original Pac Man game, our variation maps the playfield onto the outside faces of a cube, and rotates the cube to the closest contiguous face as the Chomp character runs through the tunnels. One other important note is that the playfield is rendered entirely using anti-aliased vector primitives -- not bitmaps -- so features such as zooming can be accomplished without scaling artifacts.

 

SciFiText.wmv -- This sample combines Direct2D and Direct3D to achieve what is commonly known as the "scrolling Star Wars text effect". An application can render Direct2D content into a Direct3D surface, and then display that surface at an angle to the camera.

 

SimplePathAnimation.wmv -- This sample demonstrates how to use a Direct2D Path Geometry to drive a path animation. Every D2D geometry exposes a ID2D1Geometry::ComputePointAtLength method, which can be used to obtain a point and tangent vector for any given length.

 

TextExtrusion.wmv -- This sample illustrates how DirectWrite, Direct2D, and Direct3D can be combined to create a text-extrusion effect. Text geometry is generated using a custom IDWriteTextRenderer that calls into IDWriteFontFace::GetGlyphRunOutline. D2D geometry operations are then used to eliminate self-intersections and tessellate the front and back faces. Side faces are generated by walking the text geometry and emitting quads. DWrite hit-testing is also used for positioning of the cursor. Finally, the generated triangles are sent to D3D for rasterization.

 

Demos.zip

 

Comments
  • Tom,

    I really like the concept of path animation. I believe it's going to result in many creative ideas for applications, games, and data visualization. I'm also glad you've included the tangent vector.

    As just a normal programmer, not a MVP or subscribing to any developer programs (MSDN), what's the best route I can follow to get these bits early? I'm quite eager to test D2D out.

  • I really like the concept of path animation. I believe it's going to result in many creative ideas for applications, games, and data visualization. I'm also glad you've included the tangent vector.

    Thank you, I agree. The rich geometry API in Direct2D will make it easier for developers to create some really interesting applications. On a related note, Windows 7 will include a cool new animation API that you can preview at the very end of the PDC session video for Direct2D and DWrite. It's definitely worth checking out.

    http://channel9.msdn.com/pdc2008/PC18/

     As just a normal programmer, not a MVP or subscribing to any developer programs (MSDN), what's the best route I can follow to get these bits early? I'm quite eager to test D2D out.

    A lot of people have asked that same question. I've asked my management for more information, and I will let you know as soon as possible. Meanwhile, if you like, send me an email (via the link to above right), and I will put you in touch with our program manager for developer engagements.

  • Tom,

    Today an idea popped into my head. Are you guys going to support a few different pixel blending operations to replicate the now standard concepts of layer: normal, darken, lighten, screen, dodge, burn, overlay, luminance, etc?

  • @sysrpl: 

    Today an idea popped into my head. Are you guys going to support a few different pixel blending operations to replicate the now standard concepts of layer: normal, darken, lighten, screen, dodge, burn, overlay, luminance, etc?

    D2D provides two fundamental pixel blending operations: Normal (Source Over) and Alpha; however, I should point out that our rich D3D interop support makes it possible to implement any blend operation with a pixel shader. Which is ultimately more flexible for customers than a limited subset.

  • Tom,

    Ah okay, I haven't done too much (or anything at all) with HLSL, which I assume is what language we will need to use to blend pixels together.

    I have used other shading languages. I am guessing we can forego the fragment vertext shader, and just provide our own custom pixel/fragment shader.

    Hrm, but if you provide our own fragment shader, wouldn't that eliminate antialiasing?

    Also, I had another question regarding paths. Will Direct2D include a feature to allow us to expand and contract paths? You know, something like offsetting a path along the tangent vector using an arbitrary distance (could be positive or negative)?

  • Correction from above:

    ".. I am guessing we can forego the vertex shader .."

  • @sysrpl: 

    Ah okay, I haven't done too much (or anything at all) with HLSL, which I assume is what language we will need to use to blend pixels together.,

    Correct.

    I have used other shading languages. I am guessing we can forego the fragment vertext shader, and just provide our own custom pixel/fragment shader.

     Yes.

    Hrm, but if you provide our own fragment shader, wouldn't that eliminate antialiasing?

    If you have provide both the source and destination textures as inputs to the shader, you have complete control over how the pixels are blended. 

    Also, I had another question regarding paths. Will Direct2D include a feature to allow us to expand and contract paths? You know, something like offsetting a path along the tangent vector using an arbitrary distance (could be positive or negative)?

     We do have the ability to widen (expand and contract) arbitrary geometries. You may have to do a little work to calculate the stroke width, of course, but we do most of the heavy lifting. :-)

        HRESULT ID2D1Geometry::Widen(

            FLOAT strokeWidth,

            __in_opt ID2D1StrokeStyle *strokeStyle,

            __in_opt CONST D2D1_MATRIX_3X2_F *worldTransform,

            FLOAT flatteningTolerance,

            __in ID2D1SimplifiedGeometrySink *geometrySink

            ) CONST PURE;

  • @sysrpl: 

    ".. I am guessing we can forego the vertex shader .."

    Correct.

  • Is Direct2D also useful if the application render target is the system memory (from gdi:createDIBSection)?

    Can Direct2D directly render to system memory or will it automatically read back

    from video memory? Please note that system memory is very useful for many

    application developers (optimal pixel access in any language).

  • @PeterG:

    Is Direct2D also useful if the application render target is the system memory (from gdi:createDIBSection)? Can Direct2D directly render to system memory or will it automatically read back from video memory?

    Direct2D can render directly to system memory. We understand that this scenario is important to many developers.

  • @sysrpl:

    Geometry expansion/contraction can be achieved by Widen()ing the geometry and then Combine()ing the result with the original geometry with either D2D1_COMBINE_MODE_UNION or D2D1_COMBINE_MODE_EXCLUDE, respectively.

  • Direct2D and DirectWrite look amazing.  I cannot wait to play around with these APIs.  The most exciting aspect to me is the Direct3D interop; the possibilities really are endless!

  • If Direct2D is part of DirectX and DirectX 11 is going to be available on Vista, does this men Direct2D will be available on Vista as well?

  • @anonymous:

    If Direct2D is part of DirectX and DirectX 11 is going to be available on Vista, does this men Direct2D will be available on Vista as well?

     Yes, we announced at PDC that Direct2D will be available on Vista.

  • I know this post is nearly a year old but hopefully I'll still get a response.  Is the source available for these examples?  It would be nice to have a look at how these examples were put together.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment