GLSL. OpenGL Shading Language. OpenGL 1.5 Logical Diagram. OpenGL 2.0 Logical Diagram

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "GLSL. OpenGL Shading Language. OpenGL 1.5 Logical Diagram. OpenGL 2.0 Logical Diagram"

Transcription

1 OpenGL Shading Language GLSL Is a high level shading language based on the C programming language. It was created by the OpenGL ARB to give developers more direct control of the graphics pipeline without having to use assembly language or hardware-specific languages. Originally introduced as an extension to OpenGL 1.4, the OpenGL ARB formally included GLSL into the OpenGL 2.0 core. OpenGL 2.0 is the first major revision to OpenGL since the creation of OpenGL 1.0 in OpenGL 4.0 has just been announced! OpenGL 1.5 Logical Diagram OpenGL 2.0 Logical Diagram

2 Vertex Processor Capabilities Lighting, material and geometry flexibility Vertex processor can do general processing, including things like: Vertex transformation Normal transformation, normalization and rescaling Lighting Colour material application Clamping of colours Texture co-ordinate generation Texture co-ordinate transformation Vertex Processor Overview Fragment Processor Capabilities Fragment Processor Overview Fragment processor can do general processing, including things like: Operations on interpolated values!pixel zoom Texture access :- Scale and bias Texture application :- Colour table lookup Fog! Convolution Colour sum!colour matrix

3 Vertex Processor Input Vertex shader is executed once each time a vertex position is specified Via glvertex or gldrawarrays or other vertex array calls Per-vertex input values are called attributes E.g., colour, normal, position, arbitrary values Change every vertex Passed through normal OpenGL mechanisms (per-vertex API or vertex arrays) More persistent input values are called uniforms E.g., lights, material properties, arbitrary values Can come from OpenGL state or from the application Constant across at least one primitive, typically constant for many primitives Passed through new OpenGL API calls Vertex Processor Output Vertex shader uses input values to compute output values Vertex shader must compute gl_position Mandatory, needed by the rasterizer Can use built-in function ftransform() to get invariance with fixed functionality Vertex shader may compute: gl_clipvertex (if user clipping is to be performed) gl_pointsize (if point parameters are to be used) Vertex Processor Output Other output values are called varying variables E.g., colour, texture co-ordinates, arbitrary data Will be interpolated in a perspective-correct fashion across the primitives Defined by the vertex shader Can be of type float, vec2, vec3, vec4, mat2, mat3, mat4, or arrays of these Output of vertex processor feeds into OpenGL fixed functionality If a fragment shader is active, output of vertex shader must match input of fragment shader If no fragment shader is active, output of vertex shader must match the needs of fixed functionality fragment processing Vertex Processor Definition The vertex processor executes the vertex shader The vertex processor has knowledge of only the current vertex An implementation may have multiple vertex processors operating in parallel

4 Fragment Processor Input Output of vertex shader is the input to the fragment shader Compatibility is checked when linking occurs Compatibility between the two is based on varying variables that are defined in both shaders and that match in type and name Fragment shader is executed for each fragment produced by rasterization For each fragment, fragment shader has access to the interpolated value for each varying variable Colour, normal, texture coordinates, arbitrary values Fragment Processor Input Fragment shader may access: gl_frontfacing contains facingness of primitive that produced the fragment gl_fragcoord contains computed window relative coordinates x, y, z, 1/w Uniform variables are also available OpenGL state or supplied by the application, same as for vertex shader If no vertex shader is active, fragment shader get the results of OpenGL fixed functionality Fragment Processor Output Output of the fragment processor goes on to the fixed function fragment operations and frame buffer operations using built-in variables gl_fragcolor computed R, G, B, A for the fragment gl_fragdepth computed depth value for the fragment Both values are destined for writing into the frame buffer if back end tests all pass Clamping or format conversion to the target buffer is done automatically outside of the fragment shader Fragment Processor Definition The fragment processor executes the fragment shader The fragment processor has knowledge of only the current fragment An implementation may have multiple fragment processors operating in parallel

5 GLSL Language Syntax GLSL Language syntax is very similar to that of Renderman SL Most of the usual data types are present Other elements are available to fit into the GL pipeline marble.vertex 1 uniform vec3 LightPosition; 2 varying vec3 vpos; 3 varying float LightIntensity; 4 5 const float SpecularContribution = 0.3; 6 const float DiffuseContribution = SpecularContribution; 7 8 void main() 9 { 10 vec3 ecposition = vec3(gl_modelviewmatrix * gl_vertex); 11 vec3 tnorm = normalize(gl_normalmatrix * gl_normal); 12 vec3 lightvec = normalize(lightposition - ecposition); 13 vec3 reflectvec = reflect(-lightvec, tnorm); 14 vec3 viewvec = normalize(-ecposition); 15 float diffuse = max(dot(lightvec, tnorm), 0.0); 16 float spec = 0.0; if (diffuse > 0.0) { 19 spec = dot(reflectvec, viewvec); 20 spec = pow(spec, 16.0); 21 } LightIntensity = DiffuseContribution * diffuse + 24 SpecularContribution * spec; gl_position = ftransform(); 27 vpos = gl_vertex.xyz; gl_frontcolor = vec4(lightintensity, LightIntensity, LightIntensity, 1.0); } marble.fragment 1 uniform vec3 stretch; 2 uniform vec3 color_a, color_b; 3 varying vec3 vpos; 4 varying float LightIntensity; 5 6 void main() { 7 float f; 8 vec3 color; 9 10 f = float(noise3(vpos * stretch)); 11 f = abs(f) + 0.8; 12 f = pow(f, 7.0); 13 f = clamp(f, 0.0, 1.0); 14 color = mix(color_a, color_b, f); 15 color *= LightIntensity; gl_fragcolor = vec4(color, 1); 18 }

6 Source Code When Using GLSL the Shader source code is loaded into the program One for each Fragment and Vertex Shader required. We can load as many as we need. This is then compiled and sent to the graphics card. We then load the appropriate shader at render time to do the drawing. Source Code The source code for a shader consists of an array of strings Each string may contain multiple lines of source code, separated by new-lines A line of source code may be made of multiple strings Compiler diagnostic messages identify the source string and the line within the string that caused the error Source strings are numbered starting from 0 When parsing, current line number is number of new-lines processed plus 1 Loading Shader Code 1 bool ReadShader( 2 const std::string &_fname, 3 char **io_sourcebuffer 4 ) 5 { 6 std::fstream FileIn; 7 FileIn.open(_fname.c_str(),std::ios::in); 8 if (!FileIn.is_open()) 9 { 10 std::cout <<"File : "<<_fname<<" Not found"<<std::endl; 11 return false; 12 } 13 // grab the file lenght 14 FileIn.seekg (0, std::ios::end); 15 int length = FileIn.tellg(); 16 FileIn.seekg (0, std::ios::beg); // allocate memory: 19 *io_sourcebuffer = new char [length]; // read data as a block: 22 FileIn.read (*io_sourcebuffer,length); FileIn.close(); return true; 27 } Checking to see if GLSL available 1 void InitGLSL(void) 2 { 3 4 glewinit(); 5 if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) 6 printf("ready for GLSL\n"); 7 else { 8 printf("no GLSL support\n"); 9 exit(1); 10 } }

7 1 GLhandleARB InstallShaders( 2 const std::string &_vertexshader, 3 const std::string &_fragmentshader 4 ) 5 { 6 GLhandleARB vertex; 7 GLhandleARB fragment; 8 GLhandleARB shaderprog; 9 GLint vertcompiled; 10 GLint fragcompiled; // status values 11 GLint linked; // Create a vertex shader object and a fragment shader object 14 vertex = glcreateshaderobjectarb(gl_vertex_shader_arb); 15 fragment = glcreateshaderobjectarb(gl_fragment_shader_arb); 16 std::cout <<"Shader ID's VS="<<vertex<<" FS="<<fragment<<std::endl; 17 // Load source code strings into shaders 18 char *shadersource; 19 ReadShader(_fragmentShader,&shadersource); 20 glshadersourcearb(fragment, 1, (const GLcharARB**)&shadersource, NULL); 21 glcompileshaderarb(fragment); 22 PrintOpenGLError(); // Check for OpenGL errors 23 glgetobjectparameterivarb(fragment,gl_object_compile_status_arb, &fragcompiled); 24 PrintInfoLog(fragment); 25 delete [] shadersource; ReadShader(_vertexShader,&shadersource); 28 glshadersourcearb(vertex, 1, (const GLcharARB**)&shadersource, NULL); 29 glcompileshaderarb(vertex); 30 PrintOpenGLError(); // Check for OpenGL errors 31 glgetobjectparameterivarb(vertex,gl_object_compile_status_arb, &vertcompiled); 32 PrintInfoLog(vertex); delete [] shadersource; // compile the shader and print out the results 37 if (!vertcompiled!fragcompiled) 38 { 39 std::cout << "Compilation error"<<" Vert = "<<vertcompiled<<" Frag = "<<fragcompiled<< std::endl; return 0; } 42 // Create a program object and attach the two compiled shaders shaderprog = glcreateprogramobjectarb(); 45 glattachobjectarb(shaderprog, vertex); 46 glattachobjectarb(shaderprog, fragment); 47 // Link the program object and print out the info log 48 gllinkprogramarb(shaderprog); 49 PrintOpenGLError(); // Check for OpenGL errors glgetobjectparameterivarb(shaderprog,gl_object_link_status_arb, &linked); 52 PrintInfoLog(shaderProg); if (!linked) 55 { 56 std::cout << "link error"<<std::endl; 57 return false; 58 } // Install program object as part of current state gluseprogramobjectarb(shaderprog); 63 return shaderprog; 64 } Using the Shaders Once the shader is loaded and made active it replaces the Fixed Function OpenGL Pipeline 1 void LoadShaders( 2 GLhandleARB &_currentshader 3 ) 4 { 5 _currentshader=installshaders("../shaders/marble.vertex","../shaders/marble.fragment"); 6 gluniform3farb(getuniloc(_currentshader, "LightPosition"), 0.0, 1.0, 0.0); 7 gluniform3farb(getuniloc(_currentshader, "color_a"), 1.0, 0.3, 0.1); 8 gluniform3farb(getuniloc(_currentshader, "color_b"), 0.2, 0.3, 0.2); 9 gluniform3farb(getuniloc(_currentshader, "stretch"),2, 2, 2); 10 } 1 case SDLK_1 : gluseprogramobjectarb(currentshader); break; 2 case SDLK_2 : gluseprogramobjectarb(null); break; 3 4 case SDLK_EQUALS : 5 Stretch+=0.5; 6 gluniform3farb(getuniloc(currentshader, "stretch"),stretch,stretch,stretch); 7 break; 8 9 case SDLK_MINUS : 10 Stretch-=0.5; 11 gluniform3farb(getuniloc(currentshader, "stretch"),stretch,stretch,stretch); 12 break; minimal Shaders Using Multiple Shaders 1 // Min Fragment Shader 2 3 void main() 4 { 5 // set to red 6 gl_fragcolor=vec4(1.0,0.0,0.0,1.0); 7 } 8 9 // min vertex shader void main() 12 { 13 // set the position using built in 14 gl_position= ftransform(); 15 } For each shader we need to load, compile and link We then store the Handle to the shader Object. When we wish to use the shader object we use a call to gluseprogramobjectarb

8 Setting Shader Parameters To Set parameters to a shader we use the following code to get access to the shader Object and Parameter Setting Shader Parameters Depending Upon the Parameter to be set we use the following 1 GLint getuniloc(glhandlearb program, const GLcharARB *name) 2 { 3 GLint loc; 4 5 loc = glgetuniformlocationarb(program, name); 6 7 if (loc == -1) 8 printf("no such uniform named \"%s\"\n", name); 9 10 return loc; 11 } 1 p[2] = LoadShaders("../Shaders/brick.vert","../Shaders/brick.frag"); 2 gluseprogramobjectarb(p[2]); 3 4 gluniform3farb(getuniloc(p[2], "BrickColor"), 1.0, 0.3, 0.2); 5 gluniform3farb(getuniloc(p[2], "MortarColor"), 0.85, 0.86, 0.84); 6 gluniform2farb(getuniloc(p[2], "BrickSize"), 0.30, 0.15); 7 gluniform2farb(getuniloc(p[2], "BrickPct"), 0.90, 0.85); 8 gluniform3farb(getuniloc(p[2], "LightPosition"), 0.0, 2.0, 4.0); Brick Fragment Shader 1 // See 3Dlabs-License.txt for license information 2 uniform vec3 BrickColor, MortarColor; 3 uniform vec2 BrickSize; 4 uniform vec2 BrickPct; 5 6 varying vec2 MCposition; 7 varying float LightIntensity; 8 9 void main(void) 10 { 11 vec3 color; 12 vec2 position, usebrick; position = MCposition / BrickSize; if (fract(position.y * 0.5) > 0.5) 17 position.x += 0.5; position = fract(position); usebrick = step(position, BrickPct); color = mix(mortarcolor, BrickColor, usebrick.x * usebrick.y ); 24 color *= LightIntensity; 25 gl_fragcolor = vec4 (color, 1.0); 26 } Brick Vertex Shader 1 // Copyright (c) Dlabs Inc. Ltd. 2 uniform vec3 LightPosition; 3 4 const float SpecularContribution = 0.7; 5 const float DiffuseContribution = SpecularContribution; 6 7 varying float LightIntensity; 8 varying vec2 MCposition; 9 10 void main(void) 11 { 12 vec3 ecposition = vec3 (gl_modelviewmatrix * gl_vertex); 13 vec3 tnorm = normalize(gl_normalmatrix * gl_normal); 14 vec3 lightvec = normalize(lightposition - ecposition); 15 vec3 reflectvec = reflect(-lightvec, tnorm); 16 vec3 viewvec = normalize(-ecposition); 17 float diffuse = max(dot(lightvec, tnorm), 0.0); 18 float spec = 0.0; if (diffuse > 0.0) 21 { 22 spec = max(dot(reflectvec, viewvec), 0.0); 23 spec = pow(spec, 16.0); 24 } LightIntensity = DiffuseContribution * diffuse + 27 SpecularContribution * spec; MCposition = gl_vertex.xy; 30 gl_position = ftransform(); 31 }

9 Shader Basic Structure A shader is a sequence of declarations and function bodies Curly braces are used to group sequences of statements A shader must have a main function Statements end with a semi-colon Basic Types float, vec2, vec3, vec4 1, 2, 3, or 4 floating point values Preferred data types for most processing int, ivec2, ivec3, ivec4 1, 2, 3, or 4 integer values Integer for loops and array index bool, bvec2, bvec3, bvec4 1, 2, 3, or 4 boolean values As in C++, contains true or false mat2, mat3, mat4 Floating point square matrix Used to perform transformation operations Basic Types void Used for functions that do not return a value sampler1d, sampler2d, sampler3d Handles for accessing 1D, 2D, and 3D textures samplercube Handle for accessing a cube map texture sampler1dshadow, sampler2dshadow Handles for accessing 1D or 2D depth textures with an implicit comparison operation All Used in conjunction with texture access functions 1 float ramp[10]; 2 vec4 colors[4]; 3 bool results[3]; Arrays structures can be aggregated into arrays Only 1D arrays are supported Size of array can be expressed as an integral constant expression within square brackets ([ ]) Arrays can be declared without a size, and then re-declared later with the same type and a size Using an index that goes beyond an array s bounds results in undefined behavior

10 structs 1 struct surfacematerial 2 { 3 float ambient; 4 float diffuse; 5 float specular; 6 vec3 basecolor; 7 } surf; 8 9 surfmaterial surf1, surf2; User-defined types can be created using struct with previously defined types Creates a new type called surfacematerial Defines variables of this type called surf, surf1, and surf2 Structures can include arrays Fields are selected using the period (. ) Structure Constructors Constructor for a structure is available once structure is defined Example: 1 struct light 2 { 3 float intensity; 4 vec3 position; 5 }; 6 7 light newlight = light(3.0, vec3(1.0, 2.0, 3.0)); Type Qualifiers const variable is a constant and can only be written during its declaration attribute per-vertex data values provided to the vertex shader uniform (relatively) constant data provided by the application or by OpenGL for use in the shader varying a perspective-correct interpolated value output for vertex shader input for fragment shader in for function parameters copied into a function, but not copied out out for function parameters copied out of a function, but not copied in inout for function parameters copied into and out of a function Vector Components Vector components can be referred to using array syntax or a single letter: [0], [1], [2], [3] r, g, b, a x, y, z, w s, t, p, q This syntax can be used to extract, duplicate, or swizzle components 1 vec4 pos = vec4(1.0, 2.0, 3.0, 4.0); 2 vec4 swiz= pos.wzyx; // swiz = (4.0, 3.0, 2.0, 1.0) 3 vec4 dup = pos.xxyy; // dup = (1.0, 1.0, 2.0, 2.0) 4 5 pos.xw = vec2(5.0, 6.0); // pos = (5.0, 2.0, 3.0, 6.0) 6 pos.wx = vec2(7.0, 8.0); // pos = (8.0, 2.0, 3.0, 7.0) 7 pos.xx = vec2(3.0, 4.0); // illegal - 'x' used twice

11 Matrix Components Matrix components can be accessed using array subscripting syntax A single subscript selects a single column A second subscript selects a component within a column 1 mat4 m; 2 m[1] = vec4(2.0); // sets the second column to all m[0][0] = 1.0; // sets the upper left element to m[2][3] = 2.0; // sets the 4th element of the third 5 // column to 2.0 Declaration Function Examples 1 vec3 computecolor (in vec3 c1, in vec3 c2); 2 float radians (float degrees); Definition 1 float myfunc (in float f1, // f1 is copied in 2 inout float f2) // f2 is copied in and out 3 { 4 float myresult; 5 6 // do computations 7 8 return myresult; 9 } Vertex Shader Built-in Variables The following special variables are available in a vertex shader: 1 vec4 gl_position; // must be written to 2 float gl_pointsize; // may be written to 3 vec4 gl_clipvertex; // may be written to Every execution of a vertex shader must write the homogeneous vertex position into gl_position Can use the built-in function ftransform() to achieve invariance with fixed functionality Vertex shaders may write the size of points to be rasterized (measured in pixels) into the built-in variable gl_pointsize Vertex shaders may write the transformed coordinate to be used in conjunction with user clipping planes into gl_clipvertex Vertex Shader Built-in Attributes The following are available from a vertex shader for accessing standard OpenGL vertex attributes: 1 attribute vec4 gl_color; 2 attribute vec4 gl_secondarycolor; 3 attribute vec3 gl_normal; 4 attribute vec4 gl_vertex; 5 attribute vec4 gl_multitexcoord0; 6 attribute vec4 gl_multitexcoord1; 7 attribute vec4 gl_multitexcoord2; 8 attribute vec4 gl_multitexcoord3; 9 attribute vec4 gl_multitexcoord4; 10 attribute vec4 gl_multitexcoord5; 11 attribute vec4 gl_multitexcoord6; 12 attribute vec4 gl_multitexcoord7; 13 attribute float gl_fogcoord;

12 Built-in Functions Trigonometry/angle radians, degrees, sin, cos, tan, asin, acos, atan Exponential pow, exp2, log2, sqrt, inversesqrt Common abs, sign, floor, ceil, fract, mod, min, max, clamp, mix, step, smoothstep Geometric and matrix length, distance, dot, cross, normalize, ftransform, faceforward, reflect, matrixcompmult Vector relational lessthan, lessthanequal, greaterthan, greaterthanequal, equal, any, all Texture lookup texture1d/2d/3d, texture1d/2d/3dproj, texturecube, texture1d/2dshadow, texture1d/2dshadowproj Fragment shader only dfdx, dfdy, fwidth Noise noise1/2/3/4 Accessing Built In Pipeline GLSL has the ability to access the built in Light and Material Properties Two main structures for this are gl_frontmaterial gl_lightsource[gl_maxlights] The parameters for these (and others) are show in the following slide 1 the vertex normal 2 varying vec3 v_n; 3 4 the number of active lights to evaluate 5 /// this must be set before the shader is used. 6 uniform int numlights; 7 8 void main () 9 { Blinn Shader 10 // set the output colour to black 11 vec4 colour= vec4(0.0); 12 // normalize the vertex normal 13 vec3 N = normalize(v_n); 14 // The Light source vector 15 vec3 L; 16 // the Halfway vector (used for speed) 17 vec3 H; 18 // pre declare the colour contribution values 19 vec4 ambient; 20 vec4 diffuse; 21 vec4 specular; // now loop for active lights for (int i=0; i<numlights; ++i) 26 { 27 // get the Light vector 28 L = normalize(gl_lightsource[i].position.xyz); 29 // get the halfway vector 30 H = normalize(gl_lightsource[i].halfvector.xyz); 31 // ambient just added 32 ambient = gl_frontmaterial.ambient *gl_lightsource[i].ambient; 33 // calculate diffuse based on Lambert's law (L.N) 34 diffuse = gl_frontmaterial.diffuse *gl_lightsource[i].diffuse * max(dot(l, N), 0.0); 35 // calculate specular based on H.NˆShininess 36 specular = gl_frontmaterial.specular *gl_lightsource[i].specular * pow(max(dot(h, N), 0.0), gl_frontmaterial.shininess); combine contribution for the light 37 // 38 colour+=ambient+diffuse+specular; 39 } 40 // finally set the colour clamping between 0 and 1 41 gl_fragcolor = clamp(vec4(colour),0.0,1.0); }

13 References OpenGL Shading Language Addison-Wesley R J Rost 3DLabs OpenGL Shading Language Master Class Lecture Notes Apple GLSL Shader Examples

Tuesday, 23 March OpenGL Shading Language

Tuesday, 23 March OpenGL Shading Language OpenGL Shading Language GLSL Is a high level shading language based on the C programming language. It was created by the OpenGL ARB to give developers more direct control of the graphics pipeline without

More information

Vertex & Fragment shaders

Vertex & Fragment shaders Vertex & Fragment shaders The next big step in graphics hardware Adds programmability to the previously fixed rendering pipeline The OpenGL Shading Language (a.k.a. GLSL, glslang) Vertex shaders: programs

More information

The OpenGL Shading Language

The OpenGL Shading Language The OpenGL Shading Language GLSL In the previous lecture we looked at the process of loading shaders into the programmable hardware (GPU) The actual language syntax of GLSL and the principles behind it

More information

Design Focus. GLSL Language Details. Additions from C++ Additions for Graphics

Design Focus. GLSL Language Details. Additions from C++ Additions for Graphics GLSL Language Details Design Focus Based on syntax of ANSI C Some additions to support graphics functionality Some additions from C++ Some differences for a cleaner language design 41 December 9, 2005

More information

GLSL Language Details

GLSL Language Details GLSL Language Details 41 Design Focus Based on syntax of ANSI C Some additions to support graphics functionality Some additions from C++ Some differences for a cleaner language design December 9, 2005

More information

Programmable Graphics Hardware

Programmable Graphics Hardware CSCI 480 Computer Graphics Lecture 14 Programmable Graphics Hardware [Ch. 9] March 2, 2011 Jernej Barbic University of Southern California OpenGL Extensions Shading Languages Vertex Program Fragment Program

More information

12.2 Programmable Graphics Hardware

12.2 Programmable Graphics Hardware Fall 2018 CSCI 420: Computer Graphics 12.2 Programmable Graphics Hardware Kyle Morgenroth http://cs420.hao-li.com 1 Introduction Recent major advance in real time graphics is the programmable pipeline:

More information

Introduction to the OpenGL Shading Language

Introduction to the OpenGL Shading Language Introduction to the OpenGL Shading Language Randi Rost Director of Developer Relations, 3Dlabs 08-Dec-2005 1 Why use graphics programmability? Graphics hardware has changed radically Fixed functionality

More information

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people GLSL Introduction Fu-Chung Huang Thanks for materials from many other people Shader Languages Currently 3 major shader languages Cg (Nvidia) HLSL (Microsoft) Derived from Cg GLSL (OpenGL) Main influences

More information

Introduction to the OpenGL Shading Language

Introduction to the OpenGL Shading Language Introduction to the OpenGL Shading Language Randi Rost Director of Developer Relations, 3Dlabs 08-Dec-2005 1 Why use graphics programmability? Graphics hardware has changed radically Fixed functionality

More information

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011 Shader Programs Lecture 30 Subsections 2.8.2, 2.8.3 Robb T. Koether Hampden-Sydney College Wed, Nov 16, 2011 Robb T. Koether (Hampden-Sydney College) Shader Programs Wed, Nov 16, 2011 1 / 43 Outline 1

More information

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)! ! The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)! Gordon Wetzstein! Stanford University! EE 267 Virtual Reality! Lecture 4! stanford.edu/class/ee267/! Updates! for 24h lab access:

More information

Supplement to Lecture 22

Supplement to Lecture 22 Supplement to Lecture 22 Programmable GPUs Programmable Pipelines Introduce programmable pipelines - Vertex shaders - Fragment shaders Introduce shading languages - Needed to describe shaders - RenderMan

More information

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Straight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)! ! The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)! Gordon Wetzstein! Stanford University! EE 267 Virtual Reality! Lecture 4! stanford.edu/class/ee267/! Lecture Overview! Review

More information

Lecture 09: Shaders (Part 1)

Lecture 09: Shaders (Part 1) Lecture 09: Shaders (Part 1) CSE 40166 Computer Graphics Peter Bui University of Notre Dame, IN, USA November 9, 2010 OpenGL Rendering Pipeline OpenGL Rendering Pipeline (Pseudo-Code) 1 f o r gl_vertex

More information

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples Shader Programming Daniel Wesslén, dwn@hig.se Stefan Seipel, ssl@hig.se Examples 1 Per-pixel lighting Texture convolution filtering 2 Post-processing, animated procedural textures Vertex displacement mapping

More information

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people GLSL Introduction Fu-Chung Huang Thanks for materials from many other people Programmable Shaders //per vertex inputs from main attribute aposition; attribute anormal; //outputs to frag. program varying

More information

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 Objectives Simple Shaders - Vertex shader - Fragment shaders Programming shaders with

More information

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

The Transition from RenderMan to the OpenGL Shading Language (GLSL) 1 The Transition from RenderMan to the OpenGL Shading Language (GLSL) Mike Bailey mjb@cs.oregonstate.edu This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International

More information

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation Lecture 5 Vertex and Fragment Shaders-1 CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives The rendering pipeline and the shaders Data

More information

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 CSE 167: Introduction to Computer Graphics Lecture #7: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016 Announcements Project 2 due Friday 4/22 at 2pm Midterm #1 on

More information

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015 CSE 167: Introduction to Computer Graphics Lecture #13: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015 Announcements Project 6 due Friday Next Thursday: Midterm #2

More information

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++. GLSL OpenGL Shading Language Language with syntax similar to C Syntax somewhere between C och C++ No classes. Stranight ans simple code. Remarkably understandable and obvious! Avoids most of the bad things

More information

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects CSCI 420 Computer Graphics Lecture 4 Shaders Jernej Barbic University of Southern California Shading Languages GLSL Vertex Array Objects Vertex Shader Fragment Shader [Angel Ch. 1, 2, A] Introduction The

More information

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

GLSL 1: Basics. J.Tumblin-Modified SLIDES from: GLSL 1: Basics J.Tumblin-Modified SLIDES from: Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico and

More information

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise CMPS160 Shader-based OpenGL Programming All slides originally from Prabath Gunawardane, et al. unless noted otherwise Shader gallery I Above: Demo of Microsoft s XNA game platform Right: Product demos

More information

0.Features of the OpenGL Shading Language

0.Features of the OpenGL Shading Language 0.Features of the OpenGL Shading Language by John Kessenich 3Dlabs Inc. Ltd. 19-April-2004 Copyright 2003-2004 John Kessenich In this white paper, we present the language features of the OpenGL Shading

More information

0.Features of the OpenGL Shading Language

0.Features of the OpenGL Shading Language 0.Features of the OpenGL Shading Language by John Kessenich 3Dlabs Inc. Ltd. 03-May-2005 Copyright 2003-2005 John Kessenich In this white paper, we present the language features of the OpenGL Shading Language.

More information

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline Introduction to Shaders for Visualization Mike Bailey The Basic Computer Graphics Pipeline Model Transform View Transform Per-vertex Lighting Projection Transform Homogeneous Division Viewport Transform

More information

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics Shader Programming Technical Game Development II Professor Charles Rich Computer Science Department rich@wpi.edu Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS

More information

GLSL v1.20. Scott MacHaffie Schrödinger, Inc.

GLSL v1.20. Scott MacHaffie Schrödinger, Inc. 1 GLSL v1.20 Scott MacHaffie Schrödinger, Inc. http://www.schrodinger.com Table of Contents Introduction...2 Example 01: Trivial shader...2 Syntax...3 Types of variables...3 Example 02: Materials vertex

More information

Introduction to the OpenGL Shading Language (GLSL)

Introduction to the OpenGL Shading Language (GLSL) 1 Introduction to the OpenGL Shading Language (GLSL) This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License Mike Bailey mjb@cs.oregonstate.edu

More information

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Shaders I Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico 0 Objectives Shader Basics Simple Shaders Vertex shader Fragment shaders 1 Vertex

More information

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL) Introduction to the OpenGL Shading Language (GLSL) 1 The Basic Pipeline, OpenGL-style Vertex, Normal, Color ModelViewMatrix, ProjectionMatrix, ModelViewProjectionMatrix 2 MC Model WC View Per-vertex Projection

More information

Programmable Graphics Hardware

Programmable Graphics Hardware Programmable Graphics Hardware Outline 2/ 49 A brief Introduction into Programmable Graphics Hardware Hardware Graphics Pipeline Shading Languages Tools GPGPU Resources Hardware Graphics Pipeline 3/ 49

More information

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures Shader Programming 1 Examples Daniel Wesslén, dwn@hig.se Per-pixel lighting Texture convolution filtering Post-processing, animated procedural textures Vertex displacement mapping Daniel Wesslén 1 Fragment

More information

Programmable shader. Hanyang University

Programmable shader. Hanyang University Programmable shader Hanyang University Objective API references (will be skipped) Examples Simple shader Phong shading shader INTRODUCTION GLSL(OPENGL SHADING LANGUAGE) Scalar Data types Structure Structures

More information

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics Shader Programming Technical Game Development II Professor Charles Rich Computer Science Department rich@wpi.edu Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS

More information

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Programming with OpenGL Shaders I Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico Objectives Shader Programming Basics Simple Shaders Vertex shader Fragment shaders

More information

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel, EDAF80 Introduction to Computer Graphics Seminar 3 Shaders Michael Doggett 2017 Slides by Carl Johan Gribel, 2010-13 Today OpenGL Shader Language (GLSL) Shading theory Assignment 3: (you guessed it) writing

More information

Objectives. Open GL Shading Language (GLSL)

Objectives. Open GL Shading Language (GLSL) Open GL Shading Language (GLSL) Objectives Shader applications Vertex shaders Fragment shaders Programming shaders Cg GLSL Coupling GLSL to Applications Example applications 1 Vertex Shader Applications

More information

Mobile Application Programing: Android. OpenGL Operation

Mobile Application Programing: Android. OpenGL Operation Mobile Application Programing: Android OpenGL Operation Activities Apps are composed of activities Activities are self-contained tasks made up of one screen-full of information Activities start one another

More information

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1 Programmable GPUs Real Time Graphics Virtua Fighter 1995 (SEGA Corporation) NV1 Dead or Alive 3 2001 (Tecmo Corporation) Xbox (NV2A) Nalu 2004 (NVIDIA Corporation) GeForce 6 Human Head 2006 (NVIDIA Corporation)

More information

Programming shaders & GPUs Christian Miller CS Fall 2011

Programming shaders & GPUs Christian Miller CS Fall 2011 Programming shaders & GPUs Christian Miller CS 354 - Fall 2011 Fixed-function vs. programmable Up until 2001, graphics cards implemented the whole pipeline for you Fixed functionality but configurable

More information

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd Advanced Graphics The Shader knows Alex Benton, University of Cambridge A.Benton@damtp.cam.ac.uk Supported in part by Google UK, Ltd What is the shader? Local space World space Viewing space Local space

More information

CMPS160 Shader-based OpenGL Programming

CMPS160 Shader-based OpenGL Programming CMPS160 Shader-based OpenGL Programming Shader gallery I Above: Demo of Microsoft s XNA game platform Right: Product demos by nvidia (top) and Radeon (bottom) Shader gallery II Above: Kevin Boulanger (PhD

More information

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL Today Rendering - III CS148, Summer 2010 Graphics Pipeline and Programmable Shaders Artist Workflow Siddhartha Chaudhuri 1 2 Outline Texturing: The 10,000m View Intro to textures The fixed-function graphics

More information

Stored Texture Shaders

Stored Texture Shaders Stored Texture Shaders 157 Preparing for Texture Access These steps are the same when using a shader as when using fixed functionality Make a specific texture unit active by calling glactivetexture Create

More information

Renaissance: a functional shading language. Chad Anthony Austin. A thesis submitted to the graduate faculty

Renaissance: a functional shading language. Chad Anthony Austin. A thesis submitted to the graduate faculty Renaissance: a functional shading language by Chad Anthony Austin A thesis submitted to the graduate faculty in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE Major: Human

More information

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D 10) 1

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D 10) 1 Shader Programming Technical Game Development II Professor Charles Rich Computer Science Department rich@wpi.edu Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D

More information

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012 CSE 167: Introduction to Computer Graphics Lecture #8: GLSL Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012 Announcements Homework project #4 due Friday, November 2 nd Introduction:

More information

Introduction to GLSL. Announcements. Agenda. Course Contents. Patrick Cozzi University of Pennsylvania CIS Fall 2012

Introduction to GLSL. Announcements. Agenda. Course Contents. Patrick Cozzi University of Pennsylvania CIS Fall 2012 Announcements Introduction to GLSL Patrick Cozzi University of Pennsylvania CIS 565 - Fall 2012 Game career advice Grades Project 3 due Monday, 10/05 Project 4 Released Monday, 10/05 Due Wednesday, 10/07

More information

2D graphics with WebGL

2D graphics with WebGL 2D graphics with WebGL Some material contained here is adapted from the book s slides. September 7, 2015 (Dr. Mihail) 2D graphics September 7, 2015 1 / 22 Graphics Pipeline (Dr. Mihail) 2D graphics September

More information

GLSL Programming. Nicolas Holzschuch

GLSL Programming. Nicolas Holzschuch GLSL Programming Nicolas Holzschuch GLSL programming C-like language structure: int i, j; i = 2; j = 0; j += i; Functions, loops, branches... Reading your first GSL shader is easy Differences with C New

More information

Mobile Application Programing: Android. OpenGL Operation

Mobile Application Programing: Android. OpenGL Operation Mobile Application Programing: Android OpenGL Operation Activities Apps are composed of activities Activities are self-contained tasks made up of one screen-full of information Activities start one another

More information

An Overview GLUT GLSL GLEW

An Overview GLUT GLSL GLEW OpenGL, GLUT, GLEW, GLSL An Overview GLUT GLEW GLSL Objectives Give you an overview of the software that you will be using this semester OpenGL, GLUT, GLEW, GLSL What are they? How do you use them? What

More information

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL Today s Agenda Shaders fundamentals Programming with shader-based OpenGL Shaders Like a function call data are passed in, processed, and passed back out -- Shreiner et al, OpenGL Programming Guide GLSL

More information

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access Stored Texture Shaders Preparing for Texture Access These steps are the same when using a shader as when using fixed functionality Make a specific texture unit active by calling glactivetexture Create

More information

Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI

Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI Talk Summary Topic Coverage Define Shading Languages (loosely) High Level View of GPU Functional Aspects of GPU Example

More information

Shading Languages. Ari Silvennoinen Apri 12, 2004

Shading Languages. Ari Silvennoinen Apri 12, 2004 Shading Languages Ari Silvennoinen Apri 12, 2004 Introduction The recent trend in graphics hardware has been to replace fixed functionality in vertex and fragment processing with programmability [1], [2],

More information

Jitter Shaders. Fig 1. The opengl pipeline (simplified).

Jitter Shaders. Fig 1. The opengl pipeline (simplified). Shaders in Jitter Powerful as Jitter is, simple appearing patches often run up against the performance limitations of the computer, especially if we are trying for high resolution. You can't do very many

More information

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming SHADER PROGRAMMING Based on Jian Huang s lecture on Shader Programming What OpenGL 15 years ago could do http://www.neilturner.me.uk/shots/opengl-big.jpg What OpenGL can do now What s Changed? 15 years

More information

Lab 9 - Metal and Glass

Lab 9 - Metal and Glass Lab 9 - Metal and Glass Let the form of an object be what it may, light, shade, and perspective will always make it beautiful. -John Constable Prologue Support code: /course/cs1230/src/labs/lab09 This

More information

Stripes, Rings, and Dots!

Stripes, Rings, and Dots! 1 Stripes, Rings, and Dots! Mike Bailey mjb@cs.oregonstate.edu This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License stripesringsanddots.pptx

More information

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation Lecture 17: Shading in OpenGL CITS3003 Graphics & Animation E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012 Objectives Introduce the OpenGL shading methods - per vertex shading

More information

Mobile Application Programming: Android. OpenGL Operation

Mobile Application Programming: Android. OpenGL Operation Mobile Application Programming: Android OpenGL Operation OpenGL ES C-Based Performance-Oriented Graphics Library Wrapper libraries provided for Java, C#, etc. Produces 2D images from 2D or 3D geometric

More information

1 of 5 9/10/ :11 PM

1 of 5 9/10/ :11 PM Shader programs Summary: This tutorial shows how to write a simple shader in X3D. Shader program definition Keywords: tutorial, X3D, world, rendering Author(s): Yvonne Jung Date: 2007-02-05 First an example

More information

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016 Computergrafik Matthias Zwicker Universität Bern Herbst 2016 Today More shading Environment maps Reflection mapping Irradiance environment maps Ambient occlusion Reflection and refraction Toon shading

More information

Introduction to Shaders.

Introduction to Shaders. Introduction to Shaders Marco Benvegnù hiforce@gmx.it www.benve.org Summer 2005 Overview Rendering pipeline Shaders concepts Shading Languages Shading Tools Effects showcase Setup of a Shader in OpenGL

More information

1)Write a shader program that renders a regular pentagon with textured image like the one shown below.

1)Write a shader program that renders a regular pentagon with textured image like the one shown below. Andrew Yenalavitch CSE520 Winter 2015 Quiz 2 Report 1)Write a shader program that renders a regular pentagon with textured image like the one shown below. Use the following provided image for the texture:

More information

Introduction to Computer Graphics. Hardware Acceleration Review

Introduction to Computer Graphics. Hardware Acceleration Review Introduction to Computer Graphics Hardware Acceleration Review OpenGL Project Setup Create a command-line style project in Xcode 4 Select the project file and click Build Phases tab Add OpenGL.framework

More information

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL CS4621/5621 Fall 2015 Computer Graphics Practicum Intro to OpenGL/GLSL Professor: Kavita Bala Instructor: Nicolas Savva with slides from Balazs Kovacs, Eston Schweickart, Daniel Schroeder, Jiang Huang

More information

Sign up for crits! Announcments

Sign up for crits! Announcments Sign up for crits! Announcments Reading for Next Week FvD 16.1-16.3 local lighting models GL 5 lighting GL 9 (skim) texture mapping Modern Game Techniques CS248 Lecture Nov 13 Andrew Adams Overview The

More information

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE UGRAD.CS.UBC.C A/~CS314 Mikhail Bessmeltsev 1 WHAT IS RENDERING? Generating image from a 3D scene 2 WHAT IS RENDERING? Generating image

More information

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015 WebGL and GLSL Basics CS559 Fall 2015 Lecture 10 October 6, 2015 Last time Hardware Rasterization For each point: Compute barycentric coords Decide if in or out.7,.7, -.4 1.1, 0, -.1.9,.05,.05.33,.33,.33

More information

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST CS 380 - GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1 Markus Hadwiger, KAUST Reading Assignment #4 (until Feb. 23) Read (required): Programming Massively Parallel Processors book, Chapter

More information

Shaders (some slides taken from David M. course)

Shaders (some slides taken from David M. course) Shaders (some slides taken from David M. course) Doron Nussbaum Doron Nussbaum COMP 3501 - Shaders 1 Traditional Rendering Pipeline Traditional pipeline (older graphics cards) restricts developer to texture

More information

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc.

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc. COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2 Randi J. Rost 3Dlabs, Inc. SIGGRAPH 2002 Course Notes 05-August-2002 SIGGRAPH 2002 6-1 State of the Art in Shading

More information

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading Objectives Shading in OpenGL Introduce the OpenGL shading methods - per vertex shading vs per fragment shading - Where to carry out Discuss polygonal shading - Flat - Smooth - Gouraud CITS3003 Graphics

More information

Graphics Processing Units (GPUs) V1.2 (January 2010) Outline. High-Level Pipeline. 1. GPU Pipeline:

Graphics Processing Units (GPUs) V1.2 (January 2010) Outline. High-Level Pipeline. 1. GPU Pipeline: Graphics Processing Units (GPUs) V1.2 (January 2010) Anthony Steed Based on slides from Jan Kautz (v1.0) Outline 1. GPU Pipeline: s Lighting Rasterization Fragment Operations 2. Vertex Shaders 3. Pixel

More information

Lecture 11 Shaders and WebGL. October 8, 2015

Lecture 11 Shaders and WebGL. October 8, 2015 Lecture 11 Shaders and WebGL October 8, 2015 Review Graphics Pipeline (all the machinery) Program Vertex and Fragment Shaders WebGL to set things up Key Shader Concepts Fragment Processing and Vertex

More information

COMP371 COMPUTER GRAPHICS

COMP371 COMPUTER GRAPHICS COMP371 COMPUTER GRAPHICS SESSION 12 PROGRAMMABLE SHADERS Announcement Programming Assignment #2 deadline next week: Session #7 Review of project proposals 2 Lecture Overview GPU programming 3 GPU Pipeline

More information

Programming Graphics Hardware

Programming Graphics Hardware Programming Graphics Hardware Computer Graphics, VT 2013 Lecture 10 Johan Nysjö Centre for Image analysis Swedish University of Agricultural Sciences Uppsala University Recap: The fixed-function OpenGL

More information

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY 1(84) Information Coding / Computer Graphics, ISY, LiTH TSBK 07 Computer Graphics Ingemar Ragnemalm, ISY 1(84) Lecture 5 3D graphics part 3 Illumination Illumination applied: Shading Surface detail: Mappings

More information

glviewport(0, 0, w, h); h = 1;

glviewport(0, 0, w, h); h = 1; /* hello1.txt Simple Demo for GLSL www.lighthouse3d.com */ #include #include #include #include #include "textfile.h" GLhandleARB v,f,f2,p; float lpos[4] = 1,0.5,1,0;

More information

Waves, Displacement, Reflections. Arun Rao CS 594

Waves, Displacement, Reflections. Arun Rao CS 594 Waves, Displacement, Reflections Arun Rao CS 594 Goals Simple looking waves Waves displace and change orientation of things on top Reflections on surface Partially see through How do we create the Waves?

More information

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system GRAPHICS PIPELINE 1 OUTLINE Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system 2 IMAGE FORMATION REVISITED Can we mimic the synthetic

More information

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October WebGL and GLSL Basics CS559 Fall 2016 Lecture 14 October 24 2016 Review Hardware Rasterization For each point: Compute barycentric coords Decide if in or out.7,.7, -.4 1.1, 0, -.1.9,.05,.05.33,.33,.33

More information

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders Comp 410/510 Computer Graphics Spring 2018 Programming with OpenGL Part 3: Shaders Objectives Basic shaders - Vertex shader - Fragment shader Programming shaders with GLSL Finish first program void init(void)

More information

Shading Language Update

Shading Language Update 3 Shading Language Update Bill Licea-Kane Copyright Khronos Group, 2007 - Page 1 About this talk - Caveat BOFor Contributions to arb-glsl workgroup - NOT final, subject to (minor?) changes Not exhaustive

More information

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics CS4621/5621 Fall 2015 Basics of OpenGL/GLSL Textures Basics Professor: Kavita Bala Instructor: Nicolas Savva with slides from Balazs Kovacs, Eston Schweickart, Daniel Schroeder, Jiang Huang and Pramook

More information

Shaders. Slide credit to Prof. Zwicker

Shaders. Slide credit to Prof. Zwicker Shaders Slide credit to Prof. Zwicker 2 Today Shader programming 3 Complete model Blinn model with several light sources i diffuse specular ambient How is this implemented on the graphics processor (GPU)?

More information

OPENGL RENDERING PIPELINE

OPENGL RENDERING PIPELINE CPSC 314 03 SHADERS, OPENGL, & JS UGRAD.CS.UBC.CA/~CS314 Textbook: Appendix A* (helpful, but different version of OpenGL) Alla Sheffer Sep 2016 OPENGL RENDERING PIPELINE 1 OPENGL RENDERING PIPELINE Javascript

More information

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders Prateek Shrivastava CS12S008 shrvstv@cse.iitm.ac.in 1 GLSL Data types Scalar types: float, int, bool Vector

More information

Computer Graphics Coursework 1

Computer Graphics Coursework 1 Computer Graphics Coursework 1 Deadline Deadline: 4pm, 24/10/2016 4pm 23/10/2015 Outline The aim of the coursework is to modify the vertex and fragment shaders in the provided OpenGL framework to implement

More information