04.shaders - clarkson university!usual method of passing a shader is as a null-terminated string...

51
CS452/552; EE465/505 More on Shaders Intro to Interaction 1-20-15

Upload: others

Post on 19-Mar-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

CS452/552; EE465/505

More on Shaders Intro to Interaction

1-20-15

Page 2: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!More on Shaders ✦creating a shader program

! Introduction to Interaction & Animation

Read: Angel, Chapters 2 & 3 ✦ run all the sample programs in these two chapters ✦ be sure you understand the programs

Lab1 is posted on github, due: Friday, 1/30, midnight ✦ create 3 2D shapes, draw one at a time ✦ left mouse click advances to display the next shape

Outline

Page 3: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Lab1

left click

Page 4: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Download, run and study example code from Angel, Chapters 2 & 3, and Angel CLASS directory ■ sierpinski gasket, both 2D and 3D ■ rotating square, with and without interaction

! Lab assignments will be submitted via github ■ create a github account ■ My github account is jetsza ■ fork CS452-Spring2015-Lab1 ■ the first line of each file must contain, at a minimum, a comment containing your name and the date

■ use webgl-utils.js, initShaders.js and MV.js from Angel

Notes on assignments

Page 5: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

how?

Example: draw a square

Page 6: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

// Four Vertices

var vertices = [ vec2( -0.5, -0.5 ), vec2( -0.5, 0.5 ), vec2( 0.5, 0.5 ), vec2( 0.5, -0.5) ];

// Load the data into the GPU var bufferId = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, bufferId ); gl.bufferData( gl.ARRAY_BUFFER, flatten(vertices), gl.STATIC_DRAW );

// Associate shader variables with our data buffer var vPosition = gl.getAttribLocation( program, "vPosition" ); gl.vertexAttribPointer( vPosition, 2, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( vPosition );

First method: square.js

Page 7: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

function render() { gl.clear( gl.COLOR_BUFFER_BIT ); gl.drawArrays( gl.TRIANGLE_FAN, 0, 4 ); }

7

First method: square.js, cont.

0

1 2

3

Page 8: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Triangles, Fans or Strips

gl.drawArrays( gl.TRIANGLES, 0, 6 ); // 0, 1, 2, 0, 2, 3

0

1 2

3

gl.drawArrays( gl.TRIANGLE_STRIP, 0, 4 ); // 0, 1, 3, 2

gl.drawArrays( gl.TRIANGLE_FAN, 0, 4 ); // 0, 1 , 2, 3

0

1 2

3

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 9: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

// Four Vertices

var vertices = [ -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5 ];

// Load the data into the GPU var bufferId = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, bufferId ); gl.bufferData( gl.ARRAY_BUFFER, flatten(vertices), gl.STATIC_DRAW );

// Associate shader variables with our data buffer var vPosition = gl.getAttribLocation( program, "vPosition" ); gl.vertexAttribPointer( vPosition, 2, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( vPosition );

Second method: square2.js

Page 10: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!Moving vertices ✦Morphing ✦Wave motion ✦Fractals

! Lighting ✦More realistic models ✦Cartoon shaders

Vertex Shader Applications

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 11: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Per fragment lighting calculations

Fragment Shader Applications

per vertex lighting per fragment lighting

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 12: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Texture mapping

Fragment Shader Applications

smooth shading environment mapping

bump mapping

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 13: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! First programmable shaders were programmed in an assembly-like manner

!OpenGL extensions added functions for vertex and fragment shaders

!Cg (C for graphics) C-like language for programming shaders ✦Works with both OpenGL and DirectX ✦ Interface to OpenGL complex

!OpenGL Shading Language (GLSL)

Writing Shaders

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 14: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!OpenGL Shading Language ! Part of OpenGL 2.0 and up !High level C-like language !New data types

✦Matrices ✦Vectors ✦Samplers

! As of OpenGL 3.1, application must provide shaders

GLSL

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 15: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

attribute vec4 vPosition; void main(void) { gl_Position = vPosition; }

Simple Vertex Shader

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 16: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Execution Model

Vertex Shader

GPU

Primitive Assembly

Application Program

gl.drawArrays Vertex

Vertex data Shader Program

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 17: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

precision mediump float; void main(void) { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Simple Fragment Program

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 18: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Execution Model

Fragment Shader

Application

Frame BufferRasterizer

Fragment Fragment Color

Shader Program

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 19: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!C types: int, float, bool ! Vectors:

✦ float vec2, vec3, vec4 ✦Also int (ivec) and boolean (bvec)

!Matrices: mat2, mat3, mat4 ✦Stored by columns ✦Standard referencing m[row][column]

!C++ style constructors ✦vec3 a =vec3(1.0, 2.0, 3.0) ✦vec2 b = vec2(a)

Data Types

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 20: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! There are no pointers in GLSL !We can use C structs which can be copied back from functions ! Because matrices and vectors are basic types they can be passed into and output from GLSL functions, e.g.

mat3 func(mat3 a) ! variables passed by copying

No Pointers

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 21: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! GLSL has many of the same qualifiers such as const as C/C++

! Need others due to the nature of the execution model

! Variables can change ✦ Once per primitive ✦ Once per vertex ✦ Once per fragment ✦ At any time in the application

! Vertex attributes are interpolated by the rasterizer into fragment attributes

Qualifiers

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 22: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Attribute-qualified variables can change at most once per vertex

! There are a few built in variables such as gl_Position but most have been deprecated

! User defined (in application program) ✦attribute float temperature ✦attribute vec3 velocity ✦ recent versions of GLSL use in and out qualifiers to get to and from shaders

Attribute Qualifier

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 23: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Variables that are constant for an entire primitive

!Can be changed in application and sent to shaders

!Cannot be changed in shader !Used to pass information to shader such as the time or a bounding box of a primitive or transformation matrices

Uniform Qualified

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 24: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Variables that are passed from vertex shader to fragment shader

! Automatically interpolated by the rasterizer !With WebGL, GLSL uses the varying qualifier in both shaders varying vec4 color;

! More recent versions of WebGL use out in vertex shader and in in the fragment shader out vec4 color; //vertex shader in vec4 color; // fragment shader

Varying Qualified

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 25: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! attributes passed to vertex shader have names beginning with v (v Position, vColor) in both the application and the shader ✦Note that these are different entities with the same name

! Variable variables begin with f (fColor) in both shaders ✦must have same name

! Uniform variables are unadorned and can have the same name in application and shaders

Our Naming Convention

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 26: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

attribute vec4 vColor; varying vec4 fColor; void main() { gl_Position = vPosition; fColor = vColor; }

Example: Vertex Shader

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 27: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

precision mediump float;

varying vec3 fColor; void main() { gl_FragColor = fColor; }

Corresponding Fragment Shader

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 28: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Sending Colors from Application

var cBuffer = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, cBuffer ); gl.bufferData( gl.ARRAY_BUFFER, flatten(colors), gl.STATIC_DRAW );

var vColor = gl.getAttribLocation( program, "vColor" ); gl.vertexAttribPointer( vColor, 3, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( vColor );

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 29: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Sending a Uniform Variable // in application

vec4 color = vec4(1.0, 0.0, 0.0, 1.0); colorLoc = gl.getUniformLocation( program, ”color" ); gl.uniform4f( colorLoc, color);

// in fragment shader (similar in vertex shader)

uniform vec4 color;

void main() { gl_FragColor = color; }

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 30: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Standard C functions ✦Trigonometric ✦Arithmetic ✦Normalize, reflect, length

! Overloading of vector and matrix types mat4 a; vec4 b, c, d; c = b*a; // a column vector stored as a 1d array d = a*b; // a row vector stored as a 1d array

Operators and Functions

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 31: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Can refer to array elements by element using [] or selection (.) operator with ✦ x, y, z, w ✦ r, g, b, a ✦ s, t, p, q ✦a[2], a.b, a.z, a.p are the same

! Swizzling operator lets us manipulate components vec4 a, b; a.yz = vec2(1.0, 2.0, 3.0, 4.0); b = a.yxzw;

Swizzling and Selection

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 32: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

WebGLPrimitives

GL_TRIANGLE_STRIP GL_TRIANGLE_FAN

GL_POINTS GL_LINES

GL_LINE_LOOPGL_LINE_STRIP

GL_TRIANGLES

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 33: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!WebGL will only display triangles ✦ Simple: edges cannot cross ✦ Convex: All points on line segment between two points in a polygon are also in the polygon

✦ Flat: all vertices are in the same plane ! Application program must tessellate a polygon into triangles (triangulation)

! OpenGL 4.1 contains a tessellator but not WebGL

Polygon Issues

nonsimple polygon nonconvex polygon

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 34: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!Conceptually simple to test for simplicity and convexity

! Time consuming ! Earlier versions assumed both and left testing to the application

! Present version only renders triangles !Need algorithm to triangulate an arbitrary polygon

Polygon Testing

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 35: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Long thin triangles render badly

! Equilateral triangles render well !Maximize minimum angle !Delaunay triangulation for unstructured points

Good and Bad Triangles

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 36: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!Convex polygon

! Start with abc, remove b, then acd, ….

Triangularization

a

c

b

d

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 37: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Non-convex (concave)

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 38: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Find leftmost vertex and split

Recursive Division

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 39: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Attributes determine the appearance of objects ✦Color (points, lines, polygons) ✦Size and width (points, lines) ✦Stipple pattern (lines, polygons) ✦ Polygon mode

✤Display as filled: solid color or stipple pattern ✤Display edges ✤Display vertices

! Only a few (gl_PointSize) are supported by WebGL functions

Attributes

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 40: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Each color component is stored separately in the frame buffer

! Usually 8 bits per component in buffer ! Color values can range from 0.0 (none) to 1.0 (all) using floats or over the range from 0 to 255 using unsigned bytes

RGB color

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 41: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!Colors are indices into tables of RGB values ! Requires less memory

✦ indices usually 8 bits ✦not as important now

✤ Memory inexpensive ✤ Need more colors for shading

Indexed Color

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 42: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Default is smooth shading ✦Rasterizer interpolates vertex colors across visible polygons

! Alternative is flat shading ✦Color of first vertex determines fill color ✦Handle in shader

Smooth Color

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 43: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!Coupling shaders to applications ✦Reading ✦Compiling ✦Linking

! Vertex Attributes ! Setting up uniform variables ! Example applications

More GLSL

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 44: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Read shaders !Compile shaders !Create a program object ! Link everything together ! Link variables in application with variables in shaders ✦Vertex attributes ✦Uniform variables

Linking Shaders with Application

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 45: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

!Container for shaders ✦Can contain multiple shaders ✦Other GLSL functions

Program Object

var program = gl.createProgram();

gl.attachShader( program, vertShdr ); gl.attachShader( program, fragShdr ); gl.linkProgram( program );

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 46: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Shaders are added to the program object and compiled

!Usual method of passing a shader is as a null-terminated string using the function

! gl.shaderSource( fragShdr, fragElem.text ); ! If shader is in HTML file, we can get it into application by getElementById method

! If the shader is in a file, we can write a reader to convert the file to a string

Reading a Shader

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 47: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Adding a Vertex Shadervar vertShdr; var vertElem = document.getElementById( vertexShaderId );

vertShdr = gl.createShader( gl.VERTEX_SHADER );

gl.shaderSource( vertShdr, vertElem.text ); gl.compileShader( vertShdr );

// after program object created gl.attachShader( program, vertShdr );

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 48: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Following code may be a security issue with some browsers if you try to run it locally

Shader Reader

function getShader(gl, shaderName, type) { var shader = gl.createShader(type); shaderScript = loadFileAJAX(shaderName); if (!shaderScript) { alert("Could not find shader source: "+shaderName); } }

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 49: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! In GLSL for WebGL we must specify desired precision in fragment shaders ✦ artifact inherited from OpenGL ES ✦ ES must run on very simple embedded devices that may not support 32-bit floating point

✦All implementations must support mediump ✦No default for float in fragment shader

! Can use preprocessor directives (#ifdef) to check if highp supported and, if not, default to mediump

Precision Declaration

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 50: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

Pass Through Fragment Shader

#ifdef GL_FRAGMENT_SHADER_PRECISION_HIGH precision highp float; #else precision mediump float; #endif

varying vec4 fcolor; void main(void) { gl_FragColor = fcolor; }

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Page 51: 04.shaders - Clarkson University!Usual method of passing a shader is as a null-terminated string using the function ! gl.shaderSource( fragShdr, fragElem.text ); !If shader is in HTML

! Introduce the basic input devices ✦Physical Devices ✦Logical Devices ✦ Input Modes

! Event-driven input ! Introduce double buffering for smooth animations

! Programming event input with WebGL

Next Topic: Interaction

Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015