3D Illustrations Programming.


76 views
Uploaded on:
Description
Programmable Pipelines. 3D Illustrations Programming. Targets. Present programmable pipelines Vertex shaders Part shaders Acquaint shading dialects Required with portray shaders RenderMan. Presentation. Late significant development progressively design is programmable pipeline
Transcripts
Slide 1

Programmable Pipelines 3D Graphics Programming

Slide 2

Objectives Introduce programmable pipelines Vertex shaders Fragment shaders Introduce shading dialects Needed to portray shaders RenderMan Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 3

Introduction Recent significant development continuously design is programmable pipeline First presented by NVIDIA GForce 3 Supported by top of the line thing cards NVIDIA, ATI, 3D Labs Software Support Direct X 8 , 9, 10 OpenGL Extensions OpenGL Shading Language (GLSL) Cg Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 4

Background Two parts Vertex programs (shaders) Fragment programs (shaders) Requires definite comprehension of two apparently conflicting apporachs OpenGL pipeline Real time RenderMan thoughts disconnected from the net Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 5

CPU Frame Buffer Fragment Processor Geometry Processor Rasterizer Black Box View sections pieces vertices Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 6

Geometric Calculations Geometric information: set of vertices + sort Can originate from system, evaluator, showcase rundown sort: point, line, polygon Vertex information can be (x,y,z,w) directions of a vertex (glVertex) Normal vector Texture Coordinates RGBA shading Other information: shading records, edge banners Additional client characterized information in GLSL Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 7

Per-Vertex Operations Vertex areas are changed by the model-view network into eye organizes Normals must be changed with the backwards transpose of the model-view lattice so that v · n=v’ · n’ in both spaces Assumes there is no scaling May need to utilize autonormalization Textures directions are produced if autotexture empowered and the composition framework is connected Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 8

Lighting Calculations Consider a for each vertex premise Phong model Phong model obliges calculation of r and v at each vertex I =k d I d l · n + k s I s ( v · r ) a + k an I an Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 9

Calculating the Reflection Term edge of rate = edge of reflection cos q i = cos q r or r · n = l · n r , n , and l are coplanar r = a l + b n standardize 1 = r · r = n · n = l · l settling: r = 2( l · n ) n - l Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 10

OpenGL Lighting Modified Phong demonstrate Halfway vector Global encompassing term Specified in standard Supported by equipment Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 11

Halfway Vector Blinn proposed supplanting v · r by n · h where h = ( l + v )/| l + v | ( l + v )/2 is somewhere between l and v If n , l , and v are coplanar: y = f/2 Must then modify example so that ( n · h) e’ ≈ (r.v) e Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 12

Primitive Assembly Vertices are next amassed into articles Polygons Line Segements Points Transformation by projection network Clipping Against client characterized planes View volume, x= ± w, y= ± w, z= ± w Polygon cut-out can make new vertices Perspective Division Viewport mapping Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 13

Rasterization Geometric substances are rasterized into parts Each section relates to a point on a whole number matrix: a showed pixel Hence every section is a potential pixel Each part has A shading Possibly a profundity esteem Texture facilitates Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 14

Fragment Operations Texture era Fog Antialiasing Scissoring Alpha test Blending Dithering Logical Operation Masking Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 15

Vertex Processor Takes in vertices Position trait Possibly shading OpenGL state Produces Position in clasp arranges Vertex shading Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 16

Fragment Processor Takes in yield of rasterizer (pieces) Vertex qualities have been added over primitive by rasterizer Outputs a piece Color Texture Fragments still experience section tests Hidden-surface evacuation alpha Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 17

Programmable Shaders Replace altered capacity vertex and section handling by programmable processors called shaders Can supplant either or both If we utilize a programmable shader we must do every single obliged capacity of the altered capacity processor Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 18

Development RenderMan Shading Language Offline rendering Hardware Shading Languages UNC, Stanford NVIDIA OpenGL Vertex Program Extension OpenGL Shading Language Cg OpenGL Microsoft HLSL Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 19

Renderer Modeler RenderMan Developed by Pixar S. Upstill, The RenderMan Companion , Addison-Wesley, 1989. Model interface record (RIB) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 20

Modeling versus Rendering Modeler yields geometric model in addition to data for the renderer Specifications of camera Materials Lights May have various types of renderers Ray tracer Radiosity How would we indicate a shader? Holy messenger: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 21

Mesa http://www.mesa3d.org/Software actualize OpenGL opengl32.dll fabricate by plateau 7.2 In glsl.zip \chapt15\shaders

Slide 22

Build plateau lib utilizing mingw set path=C:\Dev-Cpp\bin;%PATH% set LIBRARY_PATH=C:\Dev-Cpp\lib set C_INCLUDE_PATH=C:\Dev-Cpp\include set CPLUS_INCLUDE_PATH=C:\Dev-Cpp\include\c++\3.4.2;C:\Dev-Cpp\include\c++\3.4.2\backward;C:\Dev-Cpp\include\c++\mingw32;C:\Dev-Cpp\include mingw32-make - f Makefile.mgw

Slide 23

Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico GLSL I

Slide 24

Objectives Shader applications Vertex shaders Fragment shaders Programming shaders Cg GLSL Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 25

Vertex Shader Applications Moving vertices Morphing Wave movement Fractals Lighting More practical models Cartoon shaders Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 26

Fragment Shader Applications Per piece lighting computations per vertex lighting per section lighting Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 27

Fragment Shader Applications Texture mapping smooth shading environment mapping knock mapping Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 28

Writing Shaders First programmable shaders were modified in a get together like way OpenGL expansions included for vertex and section shaders Cg (C for design) C-like dialect for programming shaders Works with both OpenGL and DirectX Interface to OpenGL complex OpenGL Shading Language (GLSL) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 29

GLSL OpenGL Shading Language Part of OpenGL 2.0 High level C-like dialect New information sorts Matrices Vectors Samplers OpenGL state accessible through inherent variables Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 30

Simple Vertex Shader const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); void main(void) { gl_Position = gl_ProjectionMatrix *gl_ModelViewMartrix*gl_Vertex; gl_FrontColor = red; } Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 31

Execution Model Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 32

Simple Fragment Program void main(void) { gl_FragColor = gl_Color; } Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 33

Execution Model Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 34

Data Types C sorts: int, skim, bool Vectors: coast vec2, vec 3, vec4 Also int (ivec) and boolean (bvec) Matrices: mat2, mat3, mat4 Stored by segments Standard referencing m[row][column] C++ style constructors vec3 a =vec3(1.0, 2.0, 3.0) vec2 b = vec2(a) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 35

Pointers There are no pointers in GLSL We can utilize C structs which can be duplicated once more from capacities Because frameworks and vectors are essential sorts they can be gone into and yield from GLSL capacities, e.g. matrix3 func(matrix3 an) Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 36

Qualifiers GLSL has a large portion of the same qualifiers, for example, const as C/C++ Need others because of the execution\'s way show Variables can change Once per primitive Once per vertex Once per section At whenever in the application Vertex properties are introduced by the rasterizer into piece traits Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 37

Attribute Qualifier Attribute-qualified variables can change at most once per vertex Cannot be utilized as a part of section shaders Built in (OpenGL state variables) gl_Color gl_ModelViewMatrix User characterized (in application project) property drift temperature characteristic vec3 speed Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

Slide 38

Uniform Qualified Variables that are consistent for a whole primitive Can be changed in application outside extent of glBegin and glEnd Cannot be changed in shader Used to pass data to shader, for example, the bouncing box of a primitive A

Recommended
View more...