Unformatted text preview:

Zeyang LiCarnegie Mellon University Recap: Texture Mapping Programmable Graphics Pipeline Bump MappingDisplacement MappingDisplacement Mapping Environment Mapping GLSL Overview Perlin Noise GPGPU Map reflectance over a piece of geometry 2D texture mapping steps: f(x, y, z) mapping function: 3D points to u, v coordinatescoordinates g(u, v) sampling function: u, v coordinates to color. The mapping function Easy for simple geometries: cubes, spheres… Not so easy for human body, plant, alien…▪ So it’s usually done manually The mapping function Easy for simple geometries: cubes, spheres… Not so easy for human body, plant, alien…▪ So it’s usually done manually The mapping function Easy for simple geometries: cubes, spheres… Not so easy for human body, plant, alien…▪ So it’s usually done manually The mapping function Easy for simple geometries: cubes, spheres… Not so easy for human body, plant, alien…▪ So it’s usually done manually The mapping function Easy for simple geometries: cubes, spheres… Not so easy for human body, plant, alien…▪ So it’s usually done manually The mapping function Easy for simple geometries: cubes, spheres… Not so easy for human body, plant, alien…▪ So it’s usually done manually You will texture map spheres in project 2(P247) The sampling function (P242) Nearest-neighbor Bilinear▪ Linear interpolation on two directions Hermite▪ Similar to bilinear interpolation, weighting neighbor points differently. Programmable Pipeline Vertex processors Fragment processors Programmable Pipeline Vertex processors fragment processors Vertex shader operates on incoming vertices and associated data(normals, uv coordinates).operates on one vertex at a timeoperates on one vertex at a time replaces vertex program in the pipeline must compute the vertex position Fragment shader/pixel shader  operates on each fragment fragment: smallest unit being shaded replaces pixel program in the pipeline must compute a color Programmable Pipeline Vertex processors Fragment processors What you can do with it? Anything you can do with fixed function pipeline And a few million more… Texture mapping by itself does not produce very satisfying result. What can we do to fix it? Texture mapping by itself does not produce very satisfying result. What can we do to fix it?Normal mappingNormal mapping Texture mapping by itself does not produce very satisfying result. What can we do to fix it?perturb the normalsperturb the normals How? Two textures, color map and normal map How? Two textures, color map and normal map Normal map usually uses tangent space, while other vectors are in eye spaceother vectors are in eye space How? Two textures, color map and normal map Normal map usually uses tangent space, while other vectors are in eye spaceother vectors are in eye space Eye space to tangent spacetransformation Eye space to tangent space transformationGoal: find basis vectors for tangent space.We need vertices v1,v2,v3 on a plane, and their (u,v) coordinates c1,c2,c3.v2v1: 3D(x,y,z) vector from v1 to v2. v2v1: 3D(x,y,z) vector from v1 to v2. c2c1: 2D(u,v) vector from c1 to c2.Write v2v1 and v3v1 as a linearly combination of the basis vectors T and B.v2v1 = c2c1.u * T + c2c1.v * Bv3v1 = c3c1.u * T + c3c1.v * BSolve this linear system, we can get T and B.N is trivial to compute from T and B. I’m sure you can construct a matrix from T, B and N to transform vectors from eye space to tangent space. Bump mapping is not good enough Bumps do not cast shadow or affect sihouette(they don’t officially exist…)The hard way to do it, add more geometric The hard way to do it, add more geometric details. heightmap: displacement in the direction of normals. vertex displacement – possible in vertex shader subvertex displacement▪ Shader model 4.0(DirectX 10), supported only on epic graphics cards(geforce 8800 and above)▪ Requires subdivison, need to generate new vertices How? p’ = p + f(p)*nf(p): height value from height mapp: point position p: point position n: normal Sometimes Phong shading is not good enough A spaceship traveling in some exotic star system, light sources include 2 suns, 5 planets and a light sources include 2 suns, 5 planets and a million stars. How many lights we need? Sometimes Phong shading is not good enough A spaceship traveling in some exotic star system, light sources include 2 suns, 5 planets and a light sources include 2 suns, 5 planets and a million stars. How many lights we need? Environment map is a texture used as “lights”. Good when lighting conditions are static, ex. all light sources are very far away Basic Idea Convert reflected eye vector to uv coordinates(again, 3D -> 2D, except this time, for real)real) Different mapping schemes, depending on what environment map you use. Basic Idea Convert reflected eye vector to uvcoordinates(again, 3D -> 2D, except this time, for real)real) Different mapping schemes, depending on what environment map you use. Sphere mapping m = 2*sqrt(x^2 + y^2 + (z+1)^2)u = x/m + 0.5v = y/m + 0.5 C-like shading language// vertex shadervoid main(void){float shift = 2.0;gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex*shift;}// fragment shadervoid main(void){gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);} C-like shading language// vertex shadervoid main(void){float shift = 2.0;gl_Position= gl_ModelViewProjectionMatrix*gl_Vertex*shift; More primitives: vec[2-4], mat[2-4], …… special types of variables: uniform, varying, attributegl_Position= gl_ModelViewProjectionMatrix*gl_Vertex*shift;}// fragment shadervoid main(void){gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);} In GLSL, you can access OpenGL states: lighting, materials, modelview matrix, projection matrix, textures, vertex data, ext. Vertex shader cannot access texture, or has to suffer a performance penalty. Neither shaders can generate new vertices. Fragment shader cannot change its screen coordinates. Uniform Variables Read-only Accessible in both shadersuniform vec3 diffuse;varying vec3 normal;attribute vec3 tangent;…void main(void){… Initialized externally GLint diffuse_loc = glGetUniformLocationARB(program,


View Full Document

CMU CS 15462 - lecture

Download lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?