Download from Wow! eBook 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 (http://my.safaribooksonline.com) For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com 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 http://oreilly.com/catalog/errata.csp?isbn=9781449319847 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 Shader 101 Why Should XAML Developers Learn HLSL? The Tale of the Shader HLSL and DirectX Understanding the Graphics Pipeline XAML and Shaders Summary Getting Started 11 Setting Up Your Development Computer Silverlight Development WPF Development Expression Blend 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 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 tag to override the default name Specifies the desired namespace for the effect class By default, Shazzam uses the namespace configured in the Tools panel settings panel Use the tag to override the default namespace name Provides a description for this effect Shazzam will generate comments in the cs/.vb file from this description 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 tag to override the default target Use the tag to change the default NET type specified for the generated dependency property Table B-2 Shazzam Tags, parameter level Shazzam Tag Description 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 This tag is used by the Tryout tab It provides an initial value for the minimum textbox This tag is used by the Tryout tab It provides an initial value for the maximum textbox This tag is used by the Tryout tab It provides a starting value for the value slider 183 Download from Wow! eBook 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 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 ... 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 © 20 12 ... Visual Studio 20 12 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... 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