Download from Wow! eBook <www.wowebook.com>
HLSL and Pixel Shaders for XAML
Developers
Walt Ritscher
Beijing • Cambridge • Farnham • Kưln • Sebastopol • Tokyo
HLSL and Pixel Shaders for XAML Developers
by Walt Ritscher
Copyright © 2012 Walt Ritscher. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (). For more information, contact our
corporate/institutional sales department: 800-998-9938 or
Editor: Rachel Roumeliotis
Production Editor: Rachel Steely
Proofreader: Rachel Steely
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrators: Robert Romano and Rebecca Demarest
Revision History for the First Edition:
2012-07-03
First release
See for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. HLSL and Pixel Shaders for XAML Developers, the image of an American bittern,
and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
ISBN: 978-1-449-31984-7
[LSI]
1341330024
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
1. Shader 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Why Should XAML Developers Learn HLSL?
The Tale of the Shader
HLSL and DirectX
Understanding the Graphics Pipeline
XAML and Shaders
Summary
1
2
3
5
7
9
2. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Setting Up Your Development Computer
Silverlight Development
WPF Development
Expression Blend 4
Choosing a Shader Compiler
DirectX Compiler
WPF Build Task
Shazzam Shader Editor
Other Tools to Consider
FX Composer
NShader
Visual Studio 2012
A First Shader Project
Using Prebuilt Effects
Adding Effects
Debrief
Custom Shader
Create a Shader Algorithm
11
11
12
12
12
12
13
13
13
13
14
14
15
16
19
22
22
23
iii
APPENDIX B
Shazzam Settings
Table B-1. Shazzam tags, general and class level
Shazzam Tag
Description
///
A Shazzam XML comment tag. Content is ignored by the DirectX compiler.
<class>
Specifies the desired classname for generated file. By default, Shazzam uses the filename for the
effect name. A class named SwirlyEffect is generated from the Swirly.fx file. Use the
<class> tag to override the default name.
<namespace>
Specifies the desired namespace for the effect class. By default, Shazzam uses the namespace
configured in the Tools panel settings panel. Use the <namespace> tag to override the default
namespace name.
<description>
Provides a description for this effect. Shazzam will generate comments in the .cs/.vb file from this
description.
<target>
Forces the compiler to generate a Silverlight or WPF version of the .NET effect class. The default
target is configured in the Settings panel. Use the <target> tag to override the default target.
<type>
Use the <type> tag to change the default .NET type specified for the generated dependency
property.
Table B-2. Shazzam Tags, parameter level
Shazzam Tag
Description
<summary>
This tag is used by the Tryout tab.
It is used on a shader input parameter to describe the purpose of the input parameter. It causes a
tooltip to show in Shazzam for the test control.
<minValue>
This tag is used by the Tryout tab.
It provides an initial value for the minimum textbox.
<maxValue>
This tag is used by the Tryout tab.
It provides an initial value for the maximum textbox.
<defaultValue>
This tag is used by the Tryout tab.
It provides a starting value for the value slider.
183
Download from Wow! eBook <www.wowebook.com>
About the Author
Walt’s enthusiasm for crafting software interfaces blossomed early. Just a few days after
discovering how to make pixels move around the screen of a borrowed computer, he
was devouring books on the topic of computer graphics and UI design. Now he travels
the world, speaking at software conferences and teaching a diverse portfolio of programming topics for corporate clients. On the consulting side, he continues to work
with customers like Microsoft, HP, Intel, and Intuit and enjoys being part of the
Wintellect consultant group. Recently, he has entered the video training market producing .NET titles for Lynda.com He writes for several publications including Code
Magazine and TechTarget.com. His current UI obsession revolves around the
Windows 8 Metro, Silverlight, Surface, and WPF APIs. You can find his blog at
blog.wpfwonderland.com. Walt is also a Microsoft MVP and author of the free Shazzam WPF Shader utility.