Advanced Texture Mapping

Slides:



Advertisements
Similar presentations
Bump Mapping CSE 781 Roger Crawfis.
Advertisements

CS4395: Computer Graphics 1 Bump Mapping Mohan Sridharan Based on slides created by Edward Angel.
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.
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.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.
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.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
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.
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.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
Bump Map 1. High Field Function: H(u, v) New Normal : N’
Introduction to Computer Graphics with WebGL
Shading. For Further Reading Angel 7 th Ed: ­Chapter 6 2.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
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.
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.
2 3D Viewing Process  3D viewing process MC Model Space Model Transformation Model Transformation WC World Space Viewing Transformation Viewing Transformation.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
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.
Environment Maps Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programmable Pipelines
A complete pipeline for 3D graphics
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Objectives Simple Shaders Programming shaders with GLSL
Introduction to Computer Graphics with WebGL
Shading II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive Computer.
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 3: Shaders
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실.
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics GLSL Overview.
CS 480/680 Computer Graphics Shading.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics Shading in OpenGL
Textures in WebGL.
Adding Surface Detail 고려대학교 컴퓨터 그래픽스 연구실.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Shading II Ed Angel Professor Emeritus of Computer Science
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)

For Further Reading Angel 7th Ed: Chapter 7: 7.7 ~ 7.9

Per-Pixel Lighting (Phong Shading)

Per-Pixel Lighting (HTML code) <script id="vertex-shader" type="x-shader/x-vertex"> precision mediump float; ... varying vec4 fPosition; varying vec4 fColor; varying vec4 fNormal; void main() { vec4 N = normalize( modelingMatrix * vNormal ); fPosition = modelingMatrix * vPosition; fColor = vColor; fNormal = N; gl_Position = projectionMatrix * viewingMatrix * modelingMatrix * vPosition; } </script>

<script id="fragment-shader" type="x-shader/x-fragment"> <script id="fragment-shader" type="x-shader/x-fragment"> ... vec4 L = normalize( lightPosition - fPosition ); vec4 N = normalize( fNormal ); vec4 V = normalize( eye - fPosition ); vec4 H = normalize( L + V ); // Compute terms in the illumination equation float Ks = pow( max(dot(N, H), 0.0), shininess ); vec4 specular = Ks * materialSpecular; gl_FragColor = (ambient + diffuse) * fColor + specular; } </script>

Changes in GLSL Shaders Phong lighting moved to the fragment shader: New varying variables for positon and normal. Modeling, viewing, projection matrices in both shaders.  need consistent float precision “precision mediump float” added to both shaders to guarantee consistent float precision.

OpenGL Coordinate Systems This is where we do the lighting!

3D Viewing Process 3D viewing process VC WC MC NC PC DC Viewing Transformation VC View Space Model Transformation WC World Space MC Model Space Normalization & Clipping NC Normalize Space Projection Transformation PC Projection (Clip) Viewport Transformation DC Display Space

Mapping Variations smooth shading environment mapping bump mapping Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Bump Mapping (Blinn) Consider a smooth surface n p Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Rougher Version n’ p’ p Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Tangent Plane pv n pu Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Tangent, Normal, Binormal Pu, N, Pv are also known as Tangent, Normal, and Binormal (TNB) vectors.

Equations p(u,v) = [x(u,v), y(u,v), z(u,v)]T pu=[ ∂x/ ∂u, ∂y/ ∂u, ∂z/ ∂u]T pv=[ ∂x/ ∂v, ∂y/ ∂v, ∂z/ ∂v]T n = (pu  pv ) / | pu  pv | Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Displacement Function p’ = p + d(u,v) n d(u,v) is the bump or displacement function |d(u,v)| << 1 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Bump Map Example Storing the normal perturbation in RGB channels. Changes of normal vector are stored in R and G channels as [dX, dY]. Range of [0, 1] must be converted to [-1,1]

Bump Mapped Cube

Bump Mapped Cube (HTML code) <script id="fragment-shader" type="x-shader/x-fragment"> ... void main() { // Normal variation stored in the texture is within [0,1]. // Convert it to [-1, 1] vec4 texel = texture2D( texture, fTexCoord ) * 2.0 - 1.0; N.xy += texel.xy; N = normalize( N ); gl_FragColor = (ambient + diffuse) * fColor + specular; } </script>

Lab Time! Download cube3_bump_lab.html and .js Task #1: Fix the JS code that is missing the array buffer and vertex attribute for the texture coordinates. Task #2: Modify the normal vector in the fragment shader so the bump map influence the lighting. Task #3: Do you think the shader is 100% correct? If not, then what is wrong?

Tangent, Normal, Binormal What does the (dX, dY) in bump map mean?

texel.xy should be applied to the tangent plane spanned by T and B. N.xy += texel.xy is correct only if N is along the Z direction. i.e. N=(0,0,1) or (0,0,-1). texel.xy should be applied to the tangent plane spanned by T and B. But where do we get T and B in the shaders? Needs tangent vector (T) as a new vertex attribute, just like the normal vector (N).