Book Image

Direct3D Rendering Cookbook

Book Image

Direct3D Rendering Cookbook

Overview of this book

Table of Contents (19 chapters)
Direct3D Rendering Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Further Reading
Index

Applying multisample anti-aliasing


In this recipe, we will enable multisample antialiasing (MSAA) to smoothen lines and edges.

Getting ready

We can apply this recipe to any of our recipes that are implemented with a class that descends from D3DApplicationBase. Otherwise, this can be easily adapted to work with the creation of any swap chain.

How to do it…

We can smooth the lines in our example by enabling multisampling:

  1. To do this, simply override the D3DApplicationBase.CreateSwapChainDescription() method in our class as follows:

    protected override SwapChainDescription1 CreateSwapChainDescription()
    {
        var description = base.CreateSwapChainDescription();
        description.SampleDescription.Count = 4;
        description.SampleDescription.Quality = 0;
        return description;
    }
  2. Compile and run the project (F5), and you will now have antialiased edges.

How it works…

The following screenshot compares the difference between having antialiasing off and on—notice the jaggies along the bottom of the triangle...