Lesson 2 – Workflow, Tools PV227 – GPU Rendering Jiˇrí Chmelík, Jan ˇCejka Fakulta informatiky Masarykovy univerzity 29. 9. 2015 PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 1 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 2 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 3 / 71 Workflow The same operation exactly once for every vertex/patch/primitive/fragment. Independent states, no communication. Program is for the entire pipeline. Data can be passed between shaders. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 4 / 71 Workflow – Shaders Which type of shader to use for a given task? Depends on the modified data: per vertex → vertex shader, per patch → tessellation shader, per primitive → geometry shader, per fragment → fragment shader, no idea → compute shader. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 5 / 71 Workflow – Shaders (cont.) Which type of shader to use for a given task? May also depend on special properties of the processors: need of cancel computation → fragment or geometry shader, some build-in functions are defined only for certain processors. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 6 / 71 Workflow – Properties Shaders replace entire fixed pipeline. If we want to modify the vertex transformation behaviour, we also have to write code for lighting, texture generation, . . . This may be tedious when small changes are desired. In bigger projects you usually rewrite it anyway ;-). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 7 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 8 / 71 Vertex Processor Replaces the following fixed functionality: Vertex transformation by modelview and projection matix. Texture coordinates transformation by texture matrices. Transformation of normals to eye coordinates. Rescaling and normalization of normals. Texture coordinate generation. Per vertex lighting computations. Color material computations. Point size distance attenuation. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 9 / 71 Vertex Processor – Example Figure: Taken from: cs.utah.edu Figure: Taken from: cs.utah.edu PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 10 / 71 Vertex Processor – Fixed Functionality Fixed functionality applied to the result: Perspective division on clip coordinates. Viewport mapping. Depth range scaling. View frustum clipping. Front face determination. Culling. Flat-shading. Associated data clipping. Final color processing. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 11 / 71 Vertex Processor – Input and Output Figure: Scan from OpenGL Shading Language 3rd edition PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 12 / 71 Vertex Processor – Inputs Types of Input Data uniforms (built-in, user-defined), vertex attributes: user-defined (mostly), built-in variables (very few in core), textures. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 13 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 14 / 71 Uniforms user-defined: read-only in all shaders, constant per draw call, changed per primitive at most (not recommended for performance), can be initialized inside the shader, location indices are assigned during link, limited number of uniforms (both build-in and user-defined), uniforms can be grouped into named blocks. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 15 / 71 Uniforms – Blocks all variables outside named block are in default block, sampler variables must be in default block, cannot be used for another program, advantageous for variables tied to an individual shader/program. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 16 / 71 Uniforms – Location GLint glGetUniformLocation(GLuint program, const GLchar ∗name); program − the handler to the program. name − string containing the name of uniform variable to be queried. Returns the memory location of a uniform variable. Must be called after linking the program (location may change with each link). Not usable for structures, arrays, subcomponents of vectors and matrices. For structures and arrays, its elements can be set with “.” and “[]”. For non-existent uniforms or reserved names (gl_*) −1 is returned. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 17 / 71 Uniforms – Lifetime during link uniforms are set to 0, their value can be modified only when their program is used, the values are preserved when the program is switched off and on, uniforms are set with glUniform family of functions. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 18 / 71 Uniforms – Data void glUniform{1|2|3|4}{ f | i | ui }(GLint location , TYPE v); location − the location of the uniform variable. v − 1|2|3|4 component value of the uniform. void glUniform{1|2|3|4}{ f | i | ui}v(GLint location , GLsizei count, const TYPE∗ v); location − the location of the uniform variable. count − number of array elements to be specified. v − array of values to be loaded. void glUniformMatrix{2|3|4|2x3|3x2|2x4|4x2|3x4|4x3}fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat∗ v); location − the location of the uniform variable. count − number of matrices to be specified. transpose − load from row major order? v − array of values to be loaded. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 19 / 71 Uniforms – Properties types and sizes of the uniform variables must match the functions, locations for array elements and other variables cannot be computed: loc("A[n]") != loc("A")+n. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 20 / 71 Uniforms – Example 1 uniform s t r u c t 2 { 3 s t r u c t 4 { 5 f l o a t a ; 6 f l o a t b [ 1 0 ] ; 7 } c [ 2 ] ; 8 vec2 d ; 9 } e ; 1 loc1 = glGetUniformLocation ( prog , "e . d" ) ; / / v a l i d : vec2 2 loc2 = glGetUniformLocation ( prog , "e . c [ 0 ] " ) ; / / i n v a l i d : s t r u c t 3 loc3 = glGetUniformLocation ( prog , "e . c [ 0 ] . b" ) ; / / v a l i d : array 4 loc4 = glGetUniformLocation ( prog , "e . c [ 0 ] . b [ 2 ] " ) ; / / v a l i d : array element 5 6 glUniform2f ( loc1 , 1.0 f , 2.0 f ) ; / / v a l i d : vec2 7 glUniform2i ( loc1 , 1 , 2) ; / / i n v a l i d : not ivec2 8 glUniform2f ( loc1 , 1.0 f ) ; / / i n v a l i d : not f l o a t 9 glUniform2fv ( loc3 , 10 , &f ) ; / / v a l i d : b [ 0 ] (+10) 10 glUniform2fv ( loc4 , 10 , &f ) ; / / i n v a l i d : out of range 11 glUniform2fv ( loc4 , 8 , &f ) ; / / v a l i d : b [ 2 ] (+8) PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 21 / 71 Uniforms – Samplers Sampler represents a single texture of a particular texture type. only glUniform1i and glUniform1iv can be used to load samplers, the loaded value is the index of the texture unit to be used, the same unit cannot be loaded into samplers of different types. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 22 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 23 / 71 Vertex Attributes user-defined per vertex data, consist of a number of indexed locations called current vertex state, number of attributes is limited (by HW), attributes are set with glVertexAttrib family of functions, one indexed location can hold a quadruple, matrix attributes are stored in column-major order in succesive attribute locations, the same value can be set for all vertices (that do not have it otherwise specified). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 24 / 71 Vertex Attributes – Binding Binding: associates the name of the variable with an index. void glBindAttribLocation(GLuint program, GLuint index, const GLchar ∗name); program − the handler to the program. index − index of the generic vertex attribute to be bound. name − string containing the name of the vertex shader attribute variable to which index is to be bound. For example: glBindAttribLocation(ProgramObject, 10, "myAttrib") would bind the attribute "myAttrib" to index 10. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 25 / 71 Vertex Attributes – Binding (cont.) Used before linking to set the attribute name-index pairing. Automatic assignment of index+1, [index+2, [index+3]] for matrix name. Reserved variables (gl_*) must not be bound this way. May set the pairing of attributes from the same array for different shaders consistently. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 26 / 71 Vertex Attributes – Binding (cont.) GLint glGetAttribLocation(GLuint program, const GLchar ∗name); program − the handler to the program. name − string containing the name of the vertex shader attribute variable to be queried. Used after linking to get the attribute name-index pairing. For matrix name the returned index is for the first column (index+1, [index+2, [index+3]]). For non-existent attributes or reserved variables (gl_*) −1 is returned. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 27 / 71 Vertex Attributes – Enable void glEnableVertexAttribArray(GLuint index); void glDisableVertexAttribArray(GLuint index); index − index of the generic vertex attribute to be enabled/disabled. Enabled/disable vertex attributes for use in the draw calls. By default all generic attributes are disabled. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 28 / 71 Vertex Attributes – Data void glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid ∗pointer); void glVertexAttribIPointer (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid ∗ pointer); index − index of the generic vertex attribute to be modified. size − the number of components of the generic attribute (1|2|3|4) . type − the type of each component. normalized − whether fixed−point data should be normalized. stride − byte offset between consecutive vertex attributes. pointer − offset of the first attribute in the buffer bound to GL_ARRAY_BUFFER target. Specifies the location and format of vertex attributes. The I variant passes integer attributes unchanged. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 29 / 71 Vertex Arrays and Buffers All attributes are bound to a single vertex array object (VAO). This VAO consists of a number of buffers holding the individual attributes. The VAO holds all the information for the draw call e.g. glDrawArrays or glDrawElements. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 30 / 71 Vertex Arrays and Buffers – Example I 1 GLuint vao ; 2 3 / / Create the VAO 4 glGenVertexArrays (1 , &vao ) ; 5 glBindVertexArray ( vao ) ; 6 7 / / Create buffers f o r our vertex data 8 GLuint buffers [ 2 ] ; 9 glGenBuffers (2 , buffers ) ; 10 11 / / Vertex coordinates buffer 12 glBindBuffer (GL_ARRAY_BUFFER, buffers [ 0 ] ) ; 13 glBufferData (GL_ARRAY_BUFFER, sizeof ( v e rt ic es ) , vertices , GL_STATIC_DRAW) ; 14 glEnableVertexAttribArray (VERTEX_COORD_ATTRIB) ; 15 g l V e r t e x A t t r i b P o i n t e r (VERTEX_COORD_ATTRIB, 4 , GL_FLOAT, 0 ,0 ,0) ; 16 17 / / Index buffer 18 glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, buffers [ 1 ] ) ; 19 glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof ( faceIndex ) , faceIndex , GL_STATIC_DRAW) ; 20 PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 31 / 71 Vertex Arrays and Buffers – Example II 21 / / Unbind the VAO 22 glBindVertexArray (0) ; 23 24 . . . 25 26 / / Render VAO 27 glBindVertexArray ( vao ) ; 28 glDrawElements (GL_TRIANGLES, faceCount ∗3 , GL_UNSIGNED_INT, 0) ; PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 32 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 33 / 71 Special Built-in Variables gl_VertexID – implicit vertex index passed by e.g. DrawArrays, gl_InstanceID – implicit primitive index passed by instanced draw calls e.g. glDrawArraysInstanced, PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 34 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 35 / 71 Output Data special built-in variables (very few in core), varying variables (user-defined), PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 36 / 71 Special Built-in Variables in vec4 gl_Position; homogeneous position in clip space (modelview, projection), must be set, used by the rest of the pipeline, in float gl_PointSize; size of the rasterized points, must be set if points are rasterized, in float gl_ClipDistance []; array of distances to user clipping planes, must be set if user clipping is enabled. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 37 / 71 Varying Variables passed from vertex processor to rasterizer, values of varying variable will be interpolated, more variables can be outputed than used by follow-up shader, interpolation type can be set, limited number of interpolated values. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 38 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 39 / 71 Geometry Processor everything geometry shaders can do can be accomplished in other ways Has ability to generate geometry from a small amount of input data, that allows you to reduce CPU → GPU bandwidth usage. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 40 / 71 Geometry Processor – example Single draw call: glDrawArrays(GL_POINTS, 0, 4); can produce (without geometry shader): Figure: Four red dots. Taken from: https://open.gl/geometry PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 41 / 71 Geometry Processor – example Single draw call: glDrawArrays(GL_POINTS, 0, 4); or this (using geometry shader): Figure: Taken from: https://open.gl/geometry PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 42 / 71 Geometry Processor Optional (no fixed pipeline equivalent). Receives assembled primitives, outputs zero (culling) or more primitives. May receive adjacency information. The type of input and output primitives need not match (triangles → points). Designed for moderate geometry amplification, not tessellation. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 43 / 71 Geometry Processor – Primitives Input primitives: points, lines, lines_adjacency, triangles, triangles_adjacency. Output primitives: points, line_strip, triangles_strip. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 44 / 71 Input Data varying variables (built-in, user-defined), uniforms (built-in, user-defined), textures, special built-in variables (very few in core). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 45 / 71 Varying Variables build-in and user-defined varying variables for each vertex, in the form of array of structures (user-defined or gl_PerVertex), definition must match vertex shader. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 46 / 71 Uniforms defined the same way as for vertex shader, can be the same set of variables as in vertex shader, no need to setup uniforms for each shader, limited number of uniforms (both build-in and user-defined). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 47 / 71 Output Data same output as the vertex shader, definition of primitives, special built-in variables (very few in core), varying variables (user-defined). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 48 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 49 / 71 Fragment Processor Replaces the following fixed functionality: Texture environments and texture functions. Texture application. Color sum. Fog. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 50 / 71 Fragment Processor – Fixed Functionality Fragment shader does not change the following operations: Texture image specification. Alternate texture image specification. Compressed texture image specification. Texture parameters that behave as specified even when a texture is accessed from within a fragment shader. Texture state and proxy state. Texture object specification. Texture comparison modes. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 51 / 71 Fragment Processor – Input and Output Figure: Scan from OpenGL Shading Language 3rd edition PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 52 / 71 Input Data interpolated varying variables (built-in, user-defined), uniforms (built-in, user-defined), textures, special built-in variables (very few in core). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 53 / 71 Varying Variables in vec4 gl_FragCoord; window coordinate position (xy), fragment depth (z), in bool gl_FrontFacing; whether the fragment originated from front facing primitive, in vec2 gl_PointCoord; position of the fragment (only for point primitives), user defined varying variables, definition must match vertex/geometry shader. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 54 / 71 Uniforms defined the same way as for vertex/geometry shader, can be the same set of variables as in vertex/geometry shader, no need to setup uniforms for each shader, limited number of uniforms (both build-in and user-defined). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 55 / 71 Output Data special built-in variables (very few in core), user-defined output, PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 56 / 71 Special Built-in Variables out float gl_FragDepth; replaces fragment depth (can be also discarded), fragments x,y position cannot be changed, PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 57 / 71 User-defined Output output color or discard fragment, multiple buffers may be updated. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 58 / 71 User-defined Output – Rendering Targets void glDrawBuffers(GLsizei n, const GLenum ∗bufs); n − number of render targets. bufs − array of output buffers . sets the output rendering targets, void glBindFragDataLocation(GLuint program, GLuint colorNum, const char ∗name); program − the handler to the program. colorNum − the color number to bind the user−defined varying out variable to. name − the name of the varying out variable whose binding to modify. the index of the target as specified in glDrawBuffers, also possible to set from shader code. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 59 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 60 / 71 Tools shaders are just strings → any editor you desire, RenderMonkey (http://developer.amd.com/resources/ archive/archived-tools/gpu-tools-archive/ rendermonkey-toolsuite/), FX Composer (https://developer.nvidia.com/fx-composer), OpenGL Shader Designer (http://www.opengl.org/sdk/tools/ShaderDesigner/), and many more, mostly discontinued, shader programming got diverse, only IDEs for specialized tasks. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 61 / 71 Debuggers & Profilers NVIDIA NSight, for Registered developers, AMD CodeXL, directly downloadable, gDEBugger (http://www.gremedy.com/), directly downloadable, up to OpenGL 3.2 VS2010 or newer, use what is already there, syntax highlighting, IntelliSense. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 62 / 71 Recommended Setup create folder H:\PV227 (not Desktop, Documents, . . . ), unzip the Assignments-setup.zip into PV227 folder, unzip given assignment into Assignments folder, launch the projects with Ctrl-F5 (keeps the console open). PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 63 / 71 Manual setup – GLUT multiplatform windowing system for OpenGL, not updated, alternatives exist: FreeGLUT (http://freeglut.sourceforge.net/), download built libraries at http://www.transmissionzero. co.uk/software/freeglut-devel/. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 64 / 71 Manual setup – GLEW library for accessing OpenGL core and extension functionality, download built libraries at http://glew.sourceforge.net/, Recommended version (2015): 1.13.0. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 65 / 71 Manual setup – Visual Studio Paths Project properties → Set All Configurations: VC++ Directories, Include Directories: \freeglut\include;\glew\include; Library Directories: \freeglut\lib;\glew\lib\Release\Win32; Debugging, Environment: PATH=\freeglut\bin;\glew\bin\Release\Win32; PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 66 / 71 Visual Studio Editor Improving of syntax highlighting: 1 Tools → Options, 2 Text Editor → File Extension, 3 add ‘ vert’, ‘geom’, ‘frag’ with Microsoft Visual C++ syntax, 4 update usertype.dat in the VS2013 directory: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 67 / 71 Outline 1 Workflow 2 Vertex Processor Uniforms Vertex Attributes Built-in Variables Output Data 3 Geometry Processor 4 Fragment Processor 5 Tools & Set-up 6 Assignments PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 68 / 71 Assignment – Intro\Triangle TODO: Complete the CPU calls. Vertex Shader: Project the triangle! Fragment Shader: Shade triangle! PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 69 / 71 “Advanced” Assignment Rotate triangle on the CPU. Vertex Shader: Rotate triangle, set varying attribute (color). Fragment Shader: Draw inverse color. PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 70 / 71 Build-in Constants values accessible from OpenGL API by glGet, give minumum value for OpenGL conforming implementation. 1 const i n t gl_MaxVertexAttribs = 16; 2 const i n t gl_MaxVertexUniformComponents = 1024; 3 const i n t gl_MaxFragmentUniformComponents = 1024; 4 . . . glGetIntegerv(GL_MAX_{VERTEX|GEOMETRY|FRAGMENT} _UNIFORM_COMPONENTS, &nComponents); glGetIntegerv(GL_MAX_VARYING_FLOATS, &nFloats); glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nAttribs); glGetIntegerv(GL_MAX_DRAW_BUFFERS, &nBuffers); PV227 – GPU Rendering (FI MUNI) Lesson 2 – Workflow, Tools 29. 9. 2015 71 / 71