1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Opengl shading language third edition

10 0 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 151,8 KB

Nội dung

OpenGL Shading Language ® Third Edition Randi J Rost Bill Licea-Kane With contributions by Dan Ginsburg, John M Kessenich, Barthold Lichtenbelt, Hugh Malan, and Mike Weiblen Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Capetown • Sydney • Tokyo • Singapore • Mexico City From the Library of STEPHEN EISEMAN 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 the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests For more information, please contact: U.S Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside the United States, please contact: International Sales international@pearsoned.com Visit us on the Web: informit.com/aw Library of Congress Cataloging-in-Publication Data Rost, Randi J., 1960OpenGL shading language / Randi J Rost, Bill Licea-Kane ; with contributions by Dan Ginsburg [et al.] — 3rd ed p cm Includes bibliographical references and index ISBN 978-0-321-63763-5 (pbk : alk paper) Computer graphics I Licea-Kane, Bill II Title T385.R665 2009 006.6'86—dc22 2009019529 Copyright © 2010 Pearson Education, Inc Chapter © 2003 John M Kessenich Portions of Chapter © 2003 Barthold Lichtenbelt All rights reserved Printed in the United States of America This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise For information regarding permissions, write to: Pearson Education, Inc Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax (617) 671-3447 ISBN-13: 978-0-321-63763-5 ISBN-10: 0-321-63763-1 Text printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, Michigan First printing, July 2009 From the Library of STEPHEN EISEMAN To Baby Cakes, Baby Doll, Love Bug, and Little Zooka—thanks for your love and support To Mom and Pop—my first and best teachers From the Library of STEPHEN EISEMAN This page intentionally left blank From the Library of STEPHEN EISEMAN 0.Contents Foreword to the Second Edition xxi Foreword to the First Edition xxv Preface xxix About the Authors xxxv About the Contributors xxxvii Acknowledgments xxxix Chapter Review of OpenGL Basics 1.1 1.2 1.3 1.4 1.5 1.6 1.7 OpenGL History OpenGL Evolution Execution Model The Framebuffer State Processing Pipeline Drawing Geometry 11 1.7.1 Geometry Specification 11 1.7.2 Per-Vertex Operations 13 1.7.3 Primitive Assembly 15 1.7.4 Primitive Processing 15 1.7.5 Rasterization 16 1.7.6 Fragment Processing 17 1.7.7 Per-Fragment Operations 18 1.7.8 Framebuffer Operations 18 1.8 Drawing Images 19 1.8.1 Pixel Unpacking 20 ix From the Library of STEPHEN EISEMAN x Contents 1.8.2 Pixel Transfer 1.8.3 Rasterization and Back-End Processing 1.8.4 Read Control 1.9 Coordinate Transforms 1.10 Texturing 1.11 Summary 1.12 Further Information 20 21 22 22 27 33 33 Chapter Basics 35 2.1 Introduction to the OpenGL Shading Language 2.2 Why Write Shaders? 2.3 OpenGL Programmable Processors 2.3.1 Vertex Processor 2.3.2 Fragment Processor 2.4 Language Overview 2.4.1 Language Design Considerations 2.4.2 C Basis 2.4.3 Additions to C 2.4.4 Additions from C++ 2.4.5 C Features Not Supported 2.4.6 Other Differences 2.5 System Overview 2.5.1 Driver Model 2.5.2 OpenGL Shading Language Compiler/Linker 2.5.3 OpenGL Shading Language API 2.6 Key Benefits 2.7 Summary 2.8 Further Information 35 37 38 40 43 47 47 50 50 52 53 53 54 54 56 57 59 61 63 Chapter Language Definition 65 3.1 Example Shader Pair 3.2 Data Types 3.2.1 Scalars 3.2.2 Vectors 3.2.3 Matrices 3.2.4 Samplers 3.2.5 Structures 3.2.6 Arrays 3.2.7 Void 65 67 68 69 70 71 73 74 75 From the Library of STEPHEN EISEMAN Contents 3.2.8 Declarations and Scope 3.2.9 Type Matching and Promotion 3.3 Initializers and Constructors 3.4 Type Conversions 3.5 Qualifiers and Interface to a Shader 3.5.1 Uniform Qualifiers 3.5.2 Uniform Blocks 3.5.3 In Qualifiers (Vertex Shader) 3.5.4 Out Qualifiers (Vertex Shader) 3.5.5 In Qualifiers (Fragment Shader) 3.5.6 Out Qualifiers (Fragment Shader) 3.5.7 Constant Qualifiers 3.5.8 Absent Qualifier 3.6 Flow Control 3.6.1 Functions 3.6.2 Calling Conventions 3.6.3 Built-in Functions 3.7 Operations 3.7.1 Indexing 3.7.2 Swizzling 3.7.3 Component-wise Operation 3.8 Preprocessor 3.9 Preprocessor Expressions 3.10 Error Handling 3.11 Summary 3.12 Further Information xi 75 76 76 78 79 80 81 82 82 83 83 83 84 84 85 86 87 88 89 90 90 93 96 97 98 98 Chapter The OpenGL Programmable Pipeline 101 4.1 The Vertex Processor 4.1.1 Vertex Attributes 4.1.2 Special Input Variables 4.1.3 Uniform Variables 4.1.4 User-Defined Out Variables 4.1.5 Special Output Variables 4.2 The Fragment Processor 4.2.1 User-Defined In Variables 4.2.2 Special Input Variables 4.2.3 Uniform Variables 4.2.4 User-Defined Out Variables 4.2.5 Special Output Variables 102 103 104 104 104 105 106 107 107 108 108 109 From the Library of STEPHEN EISEMAN xii Contents 4.3 Built-in Uniform Variables 4.4 Built-in Constants 4.5 Interaction with OpenGL Fixed Functionality 4.5.1 Point Size Mode 4.5.2 Clipping 4.5.3 Position Invariance 4.5.4 Texturing 4.6 Summary 4.7 Further Information 110 110 111 111 112 113 113 115 115 Chapter Built-in Functions 117 5.1 Angle and Trigonometry Functions 5.2 Exponential Functions 5.3 Common Functions 5.4 Geometric Functions 5.5 Matrix Functions 5.6 Vector Relational Functions 5.7 Texture Access Functions 5.8 Fragment Processing Functions 5.9 Noise Functions 5.10 Summary 5.11 Further Information 118 121 122 134 136 138 140 176 177 178 178 Chapter Simple Shading Example 181 6.1 6.2 6.3 6.4 6.5 6.6 Brick Shader Overview Vertex Shader Fragment Shader Observations Summary Further Information 182 183 189 196 197 197 Chapter OpenGL Shading Language API 199 7.1 7.2 7.3 7.4 7.5 7.6 7.7 Obtaining Version Information Creating Shader Objects Compiling Shader Objects Linking and Using Shaders Cleaning Up Query Functions Specifying Vertex Attributes 200 203 204 205 210 211 217 From the Library of STEPHEN EISEMAN Contents 7.8 Specifying Uniform Variables 7.8.1 Default Uniform Block 7.8.2 Named Uniform Blocks 7.9 Samplers 7.10 Multiple Render Targets 7.11 Development Aids 7.12 Implementation-Dependent API Values 7.13 Application Code for Brick Shaders 7.14 Summary 7.15 Further Information xiii 226 227 234 238 239 240 241 242 247 248 Chapter Shader Development 251 8.1 General Principles 8.1.1 Understand the Problem 8.1.2 Add Complexity Progressively 8.1.3 Test and Iterate 8.1.4 Strive for Simplicity 8.1.5 Exploit Modularity 8.2 Performance Considerations 8.2.1 Consider Computational Frequency 8.2.2 Analyze Your Algorithm 8.2.3 Use the Built-in Functions 8.2.4 Use Vectors 8.2.5 Use Textures to Encode Complex Functions 8.2.6 Review the Information Logs 8.3 Shader Debugging 8.3.1 Use the Vertex Shader Output 8.3.2 Use the Fragment Shader Output 8.3.3 Use Simple Geometry 8.4 Shader Development Tools 8.4.1 RenderMonkey 8.4.2 Apple GLSLEditorSample 8.4.3 Graphic Remedy gDEBugger 8.4.4 OpenGL Shading Language Compiler Front End 8.5 Scene Graphs 8.6 Summary 8.7 Further Information 251 252 252 253 253 253 254 254 255 255 255 256 256 256 256 257 258 258 258 261 261 261 263 266 266 From the Library of STEPHEN EISEMAN ... 2.5.1 Driver Model 2.5.2 OpenGL Shading Language Compiler/Linker 2.5.3 OpenGL Shading Language API 2.6 Key Benefits .. .OpenGL Shading Language ® Third Edition Randi J Rost Bill Licea-Kane With contributions by Dan Ginsburg, John M... 35 2.1 Introduction to the OpenGL Shading Language 2.2 Why Write Shaders? 2.3 OpenGL Programmable Processors

Ngày đăng: 22/10/2022, 08:51

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN