Computer Graphics 3 Lecture 5: OpenGL Shading Language (GLSL)

Slides:



Advertisements
Similar presentations
Fragment level programmability in OpenGL Evan Hart
Advertisements

EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 2: Shader Fundamentals (continued)
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
Graphics Pipeline.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 5 : GLSL Shaders Topics: Shader syntax, passing textures into shaders, per-pixel lighting,
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
CIS 565 Fall 2011 Qing Sun
Computing & Information Sciences Kansas State University Lecture 13 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 13 of 42 Wednesday, 20.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Shading CMSC 435/634. RenderMan Light Displacement Surface Volume Imager.
Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 4 Brief Intro to Programmable Shaders
Shading CMSC 435/634.
© Copyright Khronos Group, Page 1 Shaders Go Mobile: An Introduction to OpenGL ES 2.0 Tom Olson, Texas Instruments Inc.
Lecture by: Martin Deschamps CSE 4431
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Shader Basics Chap. 2 of Orange Book. 2 Contents Why write shaders OpenGL programmable processors Language overview System overview.
OpenGL Shading Language Jian Huang CS594, Spring 2005.
GPU Shading and Rendering: OpenGL Shading Language Marc Olano UMBC.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
OpenGL Shader Language Vertex and Fragment Shading Programs.
Wilf Comp Shaders. Wilf Comp 4002 Shaders Shaders are programs that you can download onto the card Can be used.
OpenGL Shading Language Jian Huang Joshua New CS594, Spring 2006.
Shaders in OpenGL Marshall Hahn. Introduction to Shaders in OpenGL In this talk, the basics of OpenGL Shading Language will be covered. This includes.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL Shading Language (GLSL)
GLSL II.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
CS 4363/6353 SHADERS/GLSL. ANOTHER LOOK AT THE PIPELINE Vertex Processing Clipping/Assembly Rasterization Fragment Processing.
OpenGL Shading Language
OpenGL Shading Language (GLSL)
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
OpenGl Shaders Lighthouse3d.com.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Shaders, part 2 alexandri zavodny.
Shader.
CSE 381 – Advanced Game Programming GLSL Syntax
Programmable Pipelines
Chapter 6 GPU, Shaders, and Shading Languages
Objectives Simple Shaders Programming shaders with GLSL
Shading CMSC 435/634.
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Day 05 Shader Basics.
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Shader Basics Chap. 2 of Orange Book.
Programming with OpenGL Part 3: Shaders
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Part 1: Model Loading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Computer Graphics 3 Lecture 5: OpenGL Shading Language (GLSL) Dr. Benjamin Mora University of Wales Swansea 1 Benjamin Mora

University of Wales Swansea Content Introduction. How to include GLSL programs in your code. GLEW, API Variables and Types. Vertex Processor. Fragment Processor. Samplers Built-in functions. Applications. University of Wales Swansea 2 Benjamin Mora

University of Wales Swansea Introduction University of Wales Swansea 3 Benjamin Mora

Vertex and Fragment Programs Vertices Transform And Lighting Vertex Programs: User-Defined Vertex Processing Setup Rasterization Tests (z, stencil…) Texture Fetch, Fragment Shading Fragment Programs: User-Defined Per-Pixel Processing Frame Buffer Blending University of Wales Swansea 4 Benjamin Mora

University of Wales Swansea Introduction Introduced with OpenGL 2.0. High Level Language. Real shaders implementation hidden inside drivers. C/C++ like coding. Some differences. Stronger typing. Language still heavily influenced by current hardware design. Still somehow messy… Compatible with future pipelines. Replaces fixed vertex and pixel pipelines. Geometry shader available as an extension. OpenGL 3.0 adds some functionalities. University of Wales Swansea 5 Benjamin Mora

University of Wales Swansea How to code/debug Understanding of the whole pipeline needed. Thorough analysis of the algorithm/solution first. Favor simple solutions unless big performance issues. Start with a very simple shader that achieves a simple task. Test and iterate your code until program is finalized. Frame rate proportional to code efficiency. Thoroughly analyze your problem again… Check for redundancies, memory access, etc… Use textures for emulating/pre-computing complex functions University of Wales Swansea 6 Benjamin Mora

University of Wales Swansea How to code/debug Debugging: Again difficult. Can test variables/temporary results by returning specific colors. Tools: RenderMonkey (ATI). glslDevil http://www.vis.uni-stuttgart.de/glsldevil/ gDEBugger (30-days trial version). University of Wales Swansea 7 Benjamin Mora

University of Wales Swansea Shader Loading Shaders should be ideally stored in a separate text file. Needs to be loaded into your program as a string (char *) variable, and then sent to the API. Several different shaders can be stored by the API and interchanged during rendering. Cannot be changed between glBegin(…) and glEnd() calls. VertexProgram.shader myProgram.c void main() { gl_Position=gl_ModelviewProjectionMatrix * gl_Vertex; } … Char *myVertexProgram; LoadText(myVertexProgram, “VertexProgram.shader”); //Use now the OpenGL 2.0 API //to compile and enable the program University of Wales Swansea 8 Benjamin Mora

University of Wales Swansea Shader Loading Loading a shader object (vertex or fragment) requires several steps: Create a shader object glCreateShader. Associate the source code to the shader object glShaderSource. Compile the shader. glCompileShader Attach the shader to a program object (container for shaders) glAttachShader Link the compiled shader to a program. glLinkShader Replace the fixed pipeline with the program object. glUseProgram. University of Wales Swansea 9 Benjamin Mora

Shader Loading:Example char *myVertexProgram; char *myFragmentProgram; GLuint vShader, fShader, program; … vShader=glCreateShader(GL_VERTEX_SHADER); fShader=glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(vShader, 1, & myVertexProgram, NULL); glShaderSource(fShader, 1, & myFragmentProgram, NULL); glCompileShader(vShader); glCompileShader(fShader); //Source strings can now be deleted University of Wales Swansea 10 Benjamin Mora

Shader Loading:Example program=glCreateProgram(); //Creates a program object glAttachShader(program, vShader); glAttachShader(program, fShader); glLinkProgram(program); glUseProgram(program); //can come back to a fixed pipeline by passing NULL instead … //Don’t forget : //Objects must be deleted when not needed anymore University of Wales Swansea 11 Benjamin Mora

University of Wales Swansea Variables and Types University of Wales Swansea 12 Benjamin Mora

University of Wales Swansea Types Simple types. Structures (struct keyword) and arrays possible. No Pointer! Implicit conversion generally not possible. Scalar types: float, bool, int int at least in the range [-65535, 65535] Declaration: float f,g=1.0; University of Wales Swansea 13 Benjamin Mora

University of Wales Swansea Types Vector types: vec2, vec3, vec4: Vectors of floats. bvec2, bvec3, bvec4: Vectors of booleans. ivec2, ivec3, ivec4: Vectors of integers. Declaration: vec3 v=vec3(1.0,0.0,3.0); Vector components: .xyzw, for vectors representing positions. .rgba, for vectors representing colors .stqp, for vectors representing texture coordinates. Designation not compulsory. University of Wales Swansea 14 Benjamin Mora

University of Wales Swansea Types Swizzling examples: float f; vec4 v; vec2 v2=v.ww; vec3 v3=v.xzy; v2=vec2(3.0,-1.0); v2=texture1D(sampler,coordinate).xy; v=v+f; //f is added to the 4 components of v! v+=v; //Component-wise addition University of Wales Swansea 15 Benjamin Mora

University of Wales Swansea Types Matrices (of floats, square): mat2, mat3, mat4; mat4 m; vec4 v=m[2]; float f=m[2][2]; Row and columns inverted in OpenGL conventions! m[2] is the third column of the matrix. Don’t use oversized vector and matrices if not required. University of Wales Swansea 16 Benjamin Mora

University of Wales Swansea Types Structure : Struct light { vec3 position; vec3 color; float watt; //could be actually stored with color } light myLight; No typedef! University of Wales Swansea 17 Benjamin Mora

University of Wales Swansea Types Arrays: vec3 vertices[20]; vec3 vertices2[]; //Also possible. Size must be determinable at compilation //time. See manual & specs. Special case: texture coordinate array. Internally declared as: varying vec4 gl_TexCoord[]; University of Wales Swansea 18 Benjamin Mora

University of Wales Swansea Types Samplers Texture variables. sampler1D sampler2D sampler3D samplerCube sampler1DShadow sampler2DShadow Declaration: Uniform sampler2D brick; vec4 col=texture2D(brick, texCoordinate); University of Wales Swansea 19 Benjamin Mora

University of Wales Swansea Types: Samplers Example C/C++ core program: glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, marbleTex); texLoc=glGetUniformLocation(myProgram, “marbleTexture”); glUniform1i(texLoc,0); Vertex Program: varying vec2 coord; … coord = gl_MultiTexCoord0.st; //Get the tex coordinates. University of Wales Swansea 20 Benjamin Mora

University of Wales Swansea Types: Samplers Example Fragment Program: varying vec2 coord; uniform sampler2D marbleTexture; //texture object. … gl_FragColor = texture2D(marbleTexture, coord); University of Wales Swansea 21 Benjamin Mora

University of Wales Swansea Types Qualifiers: attribute For frequently changing variables, typically what would be passed to OpenGL between glBegin(…) and glEnd(). Built-in attributes include gl_Vertex, gl_Normal,… uniform For not-so-frequently changing variables, typically what would be passed to OpenGL outside of a glBegin(…)/glEnd() section. At most changed once per primitive. Read-only. University of Wales Swansea 22 Benjamin Mora

University of Wales Swansea Types Qualifiers: varying For variables passed from the vertex shader to the fragment shader. These variables undergo a linear interpolation. Variable declation must be consistent across the vertex and fragment programs. Perspectively correct. const Variable value fixed at compilation time. Cannot be modifier The first 3 qualifiers must be global variables. No qualifier means a read/write variable local to the shader. University of Wales Swansea 23 Benjamin Mora

University of Wales Swansea Types Functions: Functions can be written locally. Call by value-return. Parameter qualifiers: in out inout const In addition to previous qualifiers Example: float norm(in vec3 v) {… University of Wales Swansea 24 Benjamin Mora

University of Wales Swansea Built-In Variables GLSL pre-declares many (useful) variables. Input/Output variables are used for communication between programs. Additional attributes can also be specified. Implementation dependent. A minimum number defined by OpenGL. glGet(GL_MAX_VERTEX_ATTRIBS); See later. University of Wales Swansea 25 Benjamin Mora

Predefined Vertex Variables attribute vec4 gl_Color; attribute vec4 gl_SecondaryColor; attribute vec3 gl_Normal; attribute vec4 gl_MultiTexCoord0; attribute vec4 gl_MultiTexCoord1; const int gl_MaxTextureCoords; … attribute vec4 gl_FogCoord; University of Wales Swansea 26 Benjamin Mora

Vertex Ouput Variables vec4 gl_Position; vec4 gl_ClipVertex; float gl_PointSize; University of Wales Swansea 27 Benjamin Mora

Vertex Varying Ouput Variables varying vec4 gl_FrontColor; varying vec4 gl_BackColor; varying vec4 gl_FrontSecondary; varying vec4 gl_BackSecondary; varying vec4 gl_TexCoord[]; float gl_FogFragCoord; University of Wales Swansea 28 Benjamin Mora

Special Fragment Input Variables varying vec4 gl_Color; varying vec4 gl_SecondaryColor; varying vec4 gl_TexCoord[]; varying float gl_FogFragCoord; University of Wales Swansea 29 Benjamin Mora

Special Fragment Input Variables bool gl_FrontFacing; vec4 gl_FragCoord; University of Wales Swansea 30 Benjamin Mora

Fragment Output Variables vec4 gl_FragColor; vec4 gl_FragData; float gl_FragDepth; //gl_FragCoord.z by default These variables have a global scope. University of Wales Swansea 31 Benjamin Mora

University of Wales Swansea Built-In Constants const int gl_MaxClipPlanes; const int gl_MaxCombinedTextureImageUnits; const int gl_MaxFragmentUniformComponents; const int gl_MaxVertexAttribs; const int gl_MaxVaryingFloats; const int gl_MaxDrawBuffers; const int gl_MaxTextureCoords; const int gl_MaxTextureUnits; const int gl_MaxTextureImageUnits; const int gl_MaxVertexTextureImageUnits; const int gl_MaxLights; University of Wales Swansea 32 Benjamin Mora

Built-In Uniform Variables uniform mat4 gl_ModelViewMatrix; uniform mat4 gl_ModelViewProjectionMatrix; uniform mat4 gl_ProjectionMatrix; uniform mat4 gl_TextureMatrix[gl_MaxTextureCoords]; uniform mat4 gl_ModelViewMatrixInverse; uniform mat4 gl_ModelViewProjectionMatrixInverse; uniform mat4 gl_ProjectionMatrixInverse; uniform mat4 gl_TextureMatrixInverse[gl_MaxTextureCoords]; University of Wales Swansea 33 Benjamin Mora

Built-In Uniform Variables uniform mat4 gl_ModelViewMatrixTranspose; uniform mat4 gl_ModelViewProjectionMatrixTranspose; uniform mat4 gl_ProjectionMatrixTranspose; uniform mat4 gl_TextureMatrixTranspose[gl_MaxTextureCoords]; uniform mat4 gl_ModelViewMatrixInverseTranspose; uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose; uniform mat4 gl_ProjectionMatrixInverseTranspose; uniform mat4 gl_TextureMatrixInverseTranspose[gl_MaxTextureCoords]; uniform mat3 gl_NormalMatrix; uniform float gl_NormalScale; University of Wales Swansea 34 Benjamin Mora

Built-In Uniform Variables struct gl_LightSourceParameters { vec4 ambient; vec4 diffuse; vec4 specular; vec4 position; vec4 halfVector; vec3 spotDirection; float spotExponent; float spotCutoff; float spotCosCutoff; float constantAttenuation; float linearAttenuation; float quadraticAttenuation; }; uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights]; etc… University of Wales Swansea 35 Benjamin Mora

Vertex and Fragment Processors University of Wales Swansea 36 Benjamin Mora

Vertex and Fragment Processors Replaces the fixed pipeline. Input/Ouput Data: Attribute or Uniform variables. Built-In or User defined. Uses “Varying Data” for the communication of Linearly interpolated Values between the vertex and the fragment program. University of Wales Swansea 37 Benjamin Mora

University of Wales Swansea Vertex Processor Modelview and projection matrices not applied. Normals not transformed to eye-coordinate. Normals not normalized. Texture coordinates not processed. Lighting not performed. Color material computations not performed. … University of Wales Swansea 38 Benjamin Mora

University of Wales Swansea Vertex Processor After the vertex program, the following fixed functionalities are still applied: Color clamping. Perspective division. Viewport mapping. Depth range scaling. Additional Vertex Attributes can be send from the main program. Additional colors, tangents, curvatures… University of Wales Swansea 39 Benjamin Mora

Passing More Vertex Attributes Main C/C++ program: Texture coordinates can be used. Not best. glVertexAttrib function. void glVertexAttrib2dv(GLuint index, const GLdouble *v); void glVertexAttrib4s(GLuint index, GLshort v0, GLshort v1, GLshort v2, GLshort v3) ; void glVertexAttrib4fv(GLuint index, const GLfloat *v); etc… Index at least in the range [0..16] Attrib 0 indicates the completion of a vertex. Version for normalized data available… University of Wales Swansea 40 Benjamin Mora

Passing More Vertex Attributes How to associate a fragment program variable with an attribute index in the C/C++ program? Use glBindAttribLocation function. void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name); glBindAttribLocation(myProgram, 1, “objectTangent”); Must be done before calling the linker. University of Wales Swansea 41 Benjamin Mora

Passing More Vertex Attributes Main C/C++ program: glVertexAttribPointer. void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer); Similar to vertex arrays. Arrays can now be stored in video memory and processed optimally. Vertex attrib arrays possible. Enabling/Disabling Attrib arrays: void glEnableVertexAttribArray(GLuint index); void glDisableVertexAttribArray(GLuint index); Arrays used when making a call to glDrawArrays, glDrawElements, etc… University of Wales Swansea 42 Benjamin Mora

Passing More Vertex Attributes Uniform variables: Setup in a different way than attribute variables. After linking the program, the main application (C/C++) must query the location of the uniform variable, and then set its value. GLint glGetUniformLocation (GLuint program, const GLchar *name) : Look for a specific variable. Returns the location. void glUniform{1|2|3|4}{f|i} (Glint location, TYPE v); Set the uniform value. Should not happen between glBegin/glEnd. University of Wales Swansea 43 Benjamin Mora

University of Wales Swansea Fragment Processor The fragment program mainly processes interpolated information generated from the vertex program. e.g. gl_Color. The fragment program must replace/code: Texture mapping environments & functions. Texture application. Color application/generation. Shading. Fog application. University of Wales Swansea 44 Benjamin Mora

University of Wales Swansea Built-In Functions University of Wales Swansea 45 Benjamin Mora

University of Wales Swansea Built-In Functions Easy Shader Development. Readability. Simplicity. Common functions needed for graphics. Mask the actual hardware implementation. The compiler has to be efficient/clever. No warranty that a function is hardware accelerated. Non-accelerated functions could be slower. Most of them available from both programs. University of Wales Swansea 46 Benjamin Mora

University of Wales Swansea Built-In Functions genType = float | vec2 | vec3 | vec4 Trigonometry Functions. genType sin( genType ); genType cos( genType ); genType tan( genType ); genType asin( genType ); genType acos( genType ); genType atan( genType, genType ); genType atan( genType ); genType radians( genType ); genType degrees( genType ); University of Wales Swansea 47 Benjamin Mora

University of Wales Swansea Built-In Functions Inverse, Exponential and square root functions. genType pow( genType, genType ); genType exp( genType ); genType log( genType ); genType exp2( genType ); genType log2( genType ); genType sqrt( genType ); genType inversesqrt( genType ); University of Wales Swansea 48 Benjamin Mora

University of Wales Swansea Built-In Functions Common functions Min, Max, Clamping, Linear interpolation (Mix), modulo, floor, frac, step functions. genType abs( genType ); genType ceil( genType ); genType clamp( genType, genType, genType ); genType clamp( genType, float, float ); genType floor( genType ); genType fract( genType ); genType max( genType, genType ); genType max( genType, float ); University of Wales Swansea 49 Benjamin Mora

University of Wales Swansea Built-In Functions Common functions genType mix( genType, genType, genType ); genType mix( genType, genType, float ); genType mod( genType, genType ); genType mod( genType, float ); genType sign( genType ); genType smoothstep( genType, genType, genType ); genType smoothstep( float, float, genType ); genType step( genType, genType ); genType step( float, genType ); University of Wales Swansea 50 Benjamin Mora

University of Wales Swansea Built-In Functions 3D functions and Matrix functions. dot product, length, multiplications… vec4 ftransform(); //Vertex ONLY. Same transform as //done with a fixed pipeline. A direct ModelviewProjection //multiplication may lead to a slightly different result. vec3 cross( vec3, vec3 ); float distance( genType, genType ); float dot( genType, genType ); genType faceforward ( genType V, genType I, genType N ); float length( genType ); genType normalize( genType ); genType reflect( genType I, genType N ); genType refract( genType I, genType N, float eta ); mat matrixCompMult( mat, mat ); University of Wales Swansea 51 Benjamin Mora

University of Wales Swansea Built-In Functions Texture Lookup functions //Optional bias term is Fragment ONLY vec4 texture1D( sampler1D, float [,float bias] ); vec4 texture1DProj( sampler1D, vec2 [,float bias] ); vec4 texture1DProj( sampler1D, vec4 [,float bias] ); vec4 texture2D( sampler2D, vec2 [,float bias] ); vec4 texture2DProj( sampler2D, vec3 [,float bias] ); vec4 texture2DProj( sampler2D, vec4 [,float bias] ); University of Wales Swansea 52 Benjamin Mora

University of Wales Swansea Built-In Functions Texture Lookup functions vec4 texture3D( sampler3D, vec3 [,float bias] ); vec4 texture3DProj( sampler3D, vec4 [,float bias] ); vec4 textureCube( samplerCube, vec3 [,float bias] ); vec4 shadow1D( sampler1DShadow, vec3 [,float bias] ); vec4 shadow2D( sampler2DShadow, vec3 [,float bias] ); vec4 shadow1DProj( sampler1DShadow, vec4 [,float bias] ); vec4 shadow2DProj( sampler2DShadow, vec4 [,float bias] ); University of Wales Swansea 53 Benjamin Mora

University of Wales Swansea Built-In Functions Texture Lookup functions //Vertex ONLY; ensure //GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS > 0 vec4 texture1DLod( sampler1D, float, float lod ); vec4 texture1DProjLod( sampler1D, vec2, float lod ); vec4 texture1DProjLod( sampler1D, vec4, float lod ); vec4 texture2DLod( sampler2D, vec2, float lod ); vec4 texture2DProjLod( sampler2D, vec3, float lod ); vec4 texture2DProjLod( sampler2D, vec4, float lod ); University of Wales Swansea 54 Benjamin Mora

University of Wales Swansea Built-In Functions Texture Lookup functions //Vertex ONLY; ensure //GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS > 0 vec4 texture3DProjLod( sampler3D, vec4, float lod ); vec4 textureCubeLod( samplerCube, vec3, float lod ); vec4 shadow1DLod( sampler1DShadow, vec3, float lod ); vec4 shadow2DLod( sampler2DShadow, vec3, float lod ); vec4 shadow1DProjLod( sampler1DShadow, vec4, float lod ); vec4 shadow2DProjLod( sampler2DShadow, vec4, float lod ); University of Wales Swansea 55 Benjamin Mora

University of Wales Swansea Built-In Functions Other functions: float noise1( genType ); vec2 noise2( genType ); vec3 noise3( genType ); vec4 noise4( genType ); genType dFdx( genType ); genType dFdy( genType ); genType fwidth( genType ); … University of Wales Swansea 56 Benjamin Mora

Application: Phong Shading Show an extreme example with a specular lighting. Ian Fergusson, https://www.cis.strath.ac.uk/teaching/ug/classes/52.359/lect13.pdf University of Wales Swansea 57 Benjamin Mora