Download presentation

Presentation is loading. Please wait.

Published byBailee Montford Modified over 2 years ago

1
Topics in Computer Graphics Spring 2010

2
Application

3
Shading

4
Maps Base texture (RGB) Height map (Grey scale) Normal map (normal encoded RGB)

5
Normal Map & Height Field

6
Normal Map Normal vector encoded as rgb [-1,1] 3 [0,1] 3 : rgb = n*0.5 + 0.5 RGB decoding in fragment shaders vec3 n = texture2D(NormalMap, texcoord.st).xyz * 2.0 – 1.0 In tangent space, the default (unit) normal points in the +z direction. Hence the RGB color for the straight up normal is (0.5, 0.5, 1.0). This is why normal maps are a blueish color Normals are then used for shading computation Diffuse: nl Specular: (nh) shininess Computations done in tangent space

7
In order to build this Tangent Space, we need to define an orthonormal (per vertex) basis, which will define our tangent space. Tangent space is composed of 3 orthogonal vectors (T, B, N) Tangent (S Tangent) Bitangent (T Tangent) Normal One has to calculate a tangent space matrix for every single vertex Tangent Space

8
Suppose a point p i in world coordinate system for whose texture coordinates are (u i, v i ) Writing this equation for the points p1, p2 and p3, defining the triangle : p 1 = u 1.T + v 1.B p 2 = u 2.T + v 2.B p 3 = u 3.T + v 3.B

9
Tangent Space p 2 - p 1 = (u 2 - u 1 ).T + (v 2 - v 1 ).B p 3 - p 1 = (u 3 - u 1 ).T + (v 3 - v 1 ).B (v 3 - v 1 ).(p 2 - p 1 ) = (v 3 - v 1 ).(u 2 - u 1 ).T + (v 3 - v 1 ).(v 2 - v 1 ).B - (v 2 - v 1 ).(p 3 - p 1 ) - (v 2 - v 1 ).(u 3 - u 1 ).T - (v 2 - v 1 ).(v 3 - v 1 ).B (u 3 - u 1 ).(p 2 - p 1 ) = (u 3 - u 1 ).(u 2 - u 1 ).T + (u 3 - u 1 ).(v 2 - v 1 ).B - (u 2 - u 1 ).(p 3 - p 1 ) - (u 2 - u 1 ).(u 3 - u 1 ).T - (u 2 - u 1 ).(v 3 - v 1 ).B (v 3 - v 1 ).(p 2 - p 1 ) - (v 2 - v 1 ).(p 3 - p 1 ) T = --------------------------------------- (u 2 - u 1 ).(v 3 - v 1 ) - (v 2 - v 1 ).(u 3 - u 1 ) (u 3 - u 1 ).(p 2 - p 1 ) - (u 2 - u 1 ).(p 3 - p 1 ) B = --------------------------------------- (v 2 - v 1 ).(u 3 - u 1 ) - (u 2 - u 1 ).(v 3 - v 1 ) 6 eqns, 6 unknowns T,B: (unit) vectors in object space

10
TBN Matrix Per Vertex Use the averaged face normal as the vertex normal Do the same for tangent and bitangent vectors Note that the T, B vectors might not be orthogonal to the normal vector Use Gram-Schmidt to make sure they are orthonormal

11
Coordinate Transformation Tangent space to object space Object space to tangent space This reference (http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php) is correcthttp://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php TyphoonLabs is not right.

12
What is mat3 (v1,v2,v3)?! It turns out to be “blue” This is the matrix that converts object space to tangent space

13
Reference http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/Chapt er_4.pdf http://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/Chapt er_4.pdf http://www.ozone3d.net/tutorials/bump_mapping.php http://www.paulsprojects.net/tutorials/simplebump/simplebum p.html http://www.paulsprojects.net/tutorials/simplebump/simplebum p.html http://www.terathon.com/code/tangent.html http://www.blacksmith- studios.dk/projects/downloads/tangent_matrix_derivation.php http://www.blacksmith- studios.dk/projects/downloads/tangent_matrix_derivation.php http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson8.php

Similar presentations

OK

Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.

Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google