CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.

Slides:



Advertisements
Similar presentations
16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.
Advertisements

Lecture 8 Transparency, Mirroring
Michael I. Gold NVIDIA Corporation
03/16/2009Dinesh Manocha, COMP770 Texturing Surface’s texture: its look & feel Graphics: a process that takes a surface and modifies its appearance using.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
CS4395: Computer Graphics 1 Bump Mapping Mohan Sridharan Based on slides created by Edward Angel.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
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.
TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
CSE Real Time Rendering Week 11, 12, 13. Texture Mapping Courtesy: Ed Angel 2.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
CSE Real Time Rendering Week 11, 12, 13. Texture Mapping Courtesy: Ed Angel 2.
CSE Real Time Rendering Week 11, 12, 13. Texture Mapping Courtesy: Ed Angel 2.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shader Applications Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
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.
Bump Map 1. High Field Function: H(u, v) New Normal : N’
GLSL II.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Programmable Pipelines. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Black Box View Geometry Processor Frame Buffer Fragment Processor.
CS 480/680 Computer Graphics Programming with Open GL Part 5: Putting it all together Dr. Frederick C Harris, Jr. Fall 2011.
GLSL I.
Programming with OpenGL Part 5: More GLSL Isaac Gang University of Mary Hardin-Baylor E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley.
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.
OpenGL Shading Language
3D Objects in WebGL Loading 3D model files. Announcement Midterm exam on 12/2 –No Internet connection. –Example code and exam questions will be on USB.
Bump Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of.
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.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
MP3.. Start at the very beginning. Almost. Either start from nothing yourself, or use the empty template for this MP. Run through the provided files are.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Environment Maps Ed Angel Professor Emeritus of Computer Science
Shaders, part 2 alexandri zavodny.
Introduction to Computer Graphics with WebGL
Computer Graphics Texture Mapping
CSE Real Time Rendering
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
Tips for Environment Mapping
Texture Mapping Part II
Introduction to Computer Graphics with WebGL
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Chapter IX Bump Mapping
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 3: Shaders
Programming with OpenGL Part 5: More GLSL
Advanced Texture Mapping
Programming with OpenGL Part 5: More GLSL
CS 480/680 Computer Graphics GLSL Overview.
CS 480/680 Part 1: Model Loading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Programmable Pipelines
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011

Objectives Shader Applications Texture Mapping Applications Reflection Maps Bump Maps

Vertex Shader Applications Moving vertices –Morphing –Wave motion –Fractals Lighting –More realistic models –Cartoon shaders

Wave Motion Vertex Shader uniform float time; uniform float xs, zs, // frequencies uniform float h; // height scale uniform mat4 ModelView, Projection; in vec4 vPosition; void main() { vec4 t =vPosition; t.y = vPosition.y + h*sin(time + xs*vPosition.x) + h*sin(time + zs*vPosition.z); gl_Position = Projection*ModelView*t; }

Particle System uniform vec3 init_vel; uniform float g, m, t; uniform mat4 Projection, ModelView; in vPosition; void main(){ vec3 object_pos; object_pos.x = vPosition.x + vel.x*t; object_pos.y = vPosition.y + vel.y*t + g/(2.0*m)*t*t; object_pos.z = vPosition.z + vel.z*t; gl_Position = Projection* ModelView*vec4(object_pos,1); }

Fragment Shader Applications Texture mapping smooth shadingenvironment mapping bump mapping

Cube Maps We can form a cube map texture by defining six 2D texture maps that correspond to the sides of a box Supported by OpenGL Also supported in GLSL through cubemap sampler vec4 texColor = textureCube(mycube, texcoord); Texture coordinates must be 3D

Environment Map Use reflection vector to locate texture in cube map

Environment Maps with Shaders Environment map usually computed in world coordinates which can differ from object coordinates because of modeling matrix –May have to keep track of modeling matrix and pass it shader as a uniform variable Can also use reflection map or refraction map (for example to simulate water)

Reflection Map Vertex Shader uniform mat4 Projection, ModelView, NormalMatrix; in vec4 vPosition; in vec4 normal; out vec3 R; void main(void) { gl_Position = Projection*ModelView*vPosition; vec3 N = normalize(NormalMatrix*normal); vec4 eyePos = ModelView*gvPosition; R = reflect(-eyePos.xyz, N); }

Refelction Map Fragment Shader in vec3 R; uniform samplerCube texMap; void main(void) { gl_FragColor = textureCube(texMap, R); }

Bump Mapping Perturb normal for each fragment Store perturbation as textures

Normalization Maps Cube maps can be viewed as lookup tables 1-4 dimensional variables Vector from origin is pointer into table Example: store normalized value of vector in the map –Same for all points on that vector –Use “normalization map” instead of normalization function –Lookup replaces sqrt, mults and adds

Introduction Let’s consider an example for which a fragment program might make sense Mapping methods –Texture mapping –Environmental (reflection) mapping Variant of texture mapping –Bump mapping Solves flatness problem of texture mapping

Modeling an Orange Consider modeling an orange Texture map a photo of an orange onto a surface –Captures dimples –Will not be correct if we move viewer or light –We have shades of dimples rather than their correct orientation Ideally we need to perturb normal across surface of object and compute a new color at each interior point

Bump Mapping (Blinn) Consider a smooth surface n p

Rougher Version n’n’ p p’

Equations p u =[ ∂x/ ∂u, ∂y/ ∂u, ∂z/ ∂u] T p(u,v) = [x(u,v), y(u,v), z(u,v)] T p v =[ ∂x/ ∂v, ∂y/ ∂v, ∂z/ ∂v] T n = (p u  p v ) / | p u  p v |

Tangent Plane pupu pvpv n

Displacement Function p’ = p + d(u,v) n d(u,v) is the bump or displacement function |d(u,v)| << 1

Perturbed Normal n’ = p’ u  p’ v p’ u = p u + (∂d/∂u)n + d(u,v)n u p’ v = p v + (∂d/∂v)n + d(u,v)n v If d is small, we can neglect last term

Approximating the Normal n’ = p’ u  p’ v ≈ n + (∂d/∂u)n  p v + (∂d/∂v)n  p u The vectors n  p v and n  p u lie in the tangent plane Hence the normal is displaced in the tangent plane Must precompute the arrays ∂d/ ∂u and ∂d/ ∂v Finally, we perturb the normal during shading

Image Processing Suppose that we start with a function d(u,v) We can sample it to form an array D=[d ij ] Then ∂d/ ∂u ≈ d ij – d i-1,j and ∂d/ ∂v ≈ d ij – d i,j-1 Embossing: multipass approach using floating point buffer

Example Single Polygon and a Rotating Light Source

How to do this? The problem is that we want to apply the perturbation at all points on the surface Cannot solve by vertex lighting (unless polygons are very small) Really want to apply to every fragment Can’t do that in fixed function pipeline But can do with a fragment program!!