final exam effects final exam effects
play

Final exam effects Final exam effects Lighting Neon lights - PDF document

Announcement Lots of CS Scholarship opportunities Textures I Deadline: April 15, 2008. Final exam effects Final exam effects Lighting Neon lights Textures / refelction Strawberry Snapple bottle Water surface CD


  1. Announcement  Lots of CS Scholarship opportunities Textures I  Deadline: April 15, 2008. Final exam effects Final exam effects  Lighting  Neon lights  Textures / refelction  Strawberry  Snapple bottle  Water surface  CD surface  Volumetric  PET scan visualization  Postprocessing  “Classic” film look  Impressionistic painting Final exam effects Final exam effects  Grads  Please register your preference  Research and implementation plan  Mycourses quiz.  Teams  Implementation  RenderMan  GLSL  Documentations 1

  2. Notes for Lab 1 Notes for Lab 1  GLSL coordinate spaces  In Renderman, premultiply opacity…I.e. world eye clip Os = Oi; object Model View Projection Cs = Ci * Os; transformation gl_ModelViewMatrix gl_ModelViewProjection Plan Texture Mapping Define surface characteristics of  Textures  an object using an image  This week Basic concept: associate value texture space (u,v)  at some coordinates in texture  Texture mapping (from files) with pixel at some coordinates in parameterization  Bump Mapping geometry Coordinate spaces used in  Environment Mapping object space (x o ,y o , z o )  texture mapping:  Simple Toon Shading Texture space (u, v) projection   Next week Object space (x o ,y o ,z o )  Screen space (x, y) screen space (x,y)  Procedural shading  Texture Mapping Texture Mapping y z x geometry screen v image u 2

  3. Textures in shaders Texture pipeline  Textures are just data  Texture coordinates available to the shader  Global variable / semantic Akenine-Moller / Haines  Actual mapping determined by underlying scene model. Texture pipeline example Textures in shaders  Tasks:  Make texture data available to rendering  Grab texture data for a given point  Use texture coord from shading point  Indexed by some other means  Apply texture data as appropriate  Color, normal, opacity, whatever. Akenine-Moller / Haines Textures in RenderMan Texture mapping in RenderMan  Texture coordinates range from 0-1 in  Access texture values from file using the texture() function texture space  texture (filename, q, r) -- Return  Values of texture coords corresponding value(s) at texture coords (q,r) to P given in global parameters s and  texture (filename) -- Return value(s) t . at standard texture coords (s, t).  Filtered texture lookup  Free antialiasing. 3

  4. Textures in RenderMan Textures in RenderMan  texture() function provides manual  Can access color or floating point values control over filtering from file  Blur  f = float texture (“foo.tex”);  Filter width  c = color texture (“bar.tex”);  Type of filter  Can access specific channels from file  Fill data (for missing channels)  f = texture (“foo.tex” [1]);  See Section 8.1.4 in text. Texture format Textures in RenderMan  prman has a proprietary format for textures. surface paintedplastic ( float Ka = 1, Kd = .5, Ks = .5, roughness = .1;  txmake [args] infile outfile color speccolor = 1; string texname = “”;)  Converts images into this format {  Args: color Ct = Cs; if (texname != “”)  -mode [black clamp periodic] Ct *= color texture (texname);  -smode, -tmode normal Nf = faceforward (normalize(N), I);  -short, -float vector V = -normalize (I);  -resize up- Ci = Ct * (Ka*ambient() + Kd*diffuse(Nf)) + speccolor * Ks * specular (Nf, V, roughness); Oi = Os; Ci *= Oi; } Textures in RenderMan Textures in GLSL  Questions?  Texture access in GLSL is almost as easy  EXCEPT…  Texture state must be set up in OpenGL program!  Places texture into texture memory for use by shaders 4

  5. Setting up OpenGL Texture Setting up the OpenGL texture state state  Select a texture unit and make it active  Notes: ( glActiveTexture())  No need to enable texture (glEnable()) or  Create a tecture object and bind to the set the up the texture function active texture ( glBindTexture()). (glTexEnv())  Set texture parameters (wrapping,  Texture data must be read in by aux filtering etc) ( glTexParam()). functions.  Define the texture ( glTexImage()) Sample setup code Sample code setup  Initializing the texture  Using the texture glActiveTexture (GL_TEXTURE0) glBindTexture (GL_TEXTURE_2D, myTexName); Sample code setup On the shader side  Textures are grabbed from texture  Passing texture to a shader memory by use of samplers  sampler1D - 1D texture texLoc = glGetUniformLocation (myProgram,  sampler2D - 2D texture “paramname);  sampler3D - 3D texture glUniform1i (texLoc, 0);  samplerCube - cube map texture  samplerShadow1D/2D - shadow maps 5

  6. Shader texture functions Texture access in GLSL  Access to texture values: use  texture1D  textureNNNN[proj/Lod] () functions  texture2D  shadowNNNN[proj/Lod] () functions  NNNN =  texture3D  1D / 2D / 3D - using texture coords (0-1)  textureCube  Cube - for environment mapping  [proj] - projective texture map  shadow1D  Proj = As if projected by slide projector/Useful in shadowing  Lod = Use of textures in vertex shaders  shadow2D  See section 5.7 for complete list Textures in GLSL Simple example  Projective texture mapping varying float Intensity; Uniform sampler2D myTexture; void main() { vec3 light = vec3 (texture2D (myTexture, glTexCoord [0].st; glFragColor = vec4 (light * Intensity, 1.0); } What you can do with texture Textures in GLSL maps  Textures are data  Color  Can be used as values  Bump Mapping  Individual components can be accessed via  Environment Mapping swizzling / masking  Toon Shading.  Questions / Break 6

  7. Texture Mapping- Bump Mapping Texture Mapping- Bump Mapping  Perturbing surface normal  Adds roughness to surfaces  Texture map represents displacements from the  Quick way to add detail to normal an object  Use perturbed normal in illumination model  Polygon remains physically flat, but appears bumpy Jim Blinn Texture mapping – Bump Mapping Issues with Bump Mapping  How much to perturb  Common coordinate system  Using eye or even object may be cumbersome.  Normal map defined on object Tangent Space Bump mapping in RenderMan  Build a local coordinate system around  Performed using the displacement shader: the normal at a point  Modifies global variables P and N P+= bumpheight * normalize(N); N = calculatenormal (P);  Recall that displacement shaders are executed before surface shaders.  bumpheight can be read from a texture file, or generated procedurally, or both… 7

  8. Bump mapping in RenderMan Bump vs displacement mapping  Displacement mapping  Bump mapping calculations should be done in “shader” space  Moves actual point P+= bumpheight * normalize(N); Coordinate Description N = calculatenormal (P); System  Bump mapping "shader" The coordinate system in which the shader was defined. This is the "object" coordinate  Just changes normal system when the shader is defined. N = calculatenormal (P + amp*normalize(N)); "current" The coordinate system in which the shading calculations are being performed. This is normally the "camera" or "world" coordinate system. Bump Mapping in Renderman Bump Mapping in GLSL vector Nshad = vtransform (“shader”, N);  No convenient displacement shader point Pshad = transform (“shader”, P);  Just vertex and fragment shaders Pshad += amp * normalize (Nshad); P = transform (“shader”, “current”, Pshad); N = calculatenormal (P);  Must be done in fragment shader  Works just as well (see Section 8.2.3 in text for derivation) vector Nn = normalize (N); P += Nn * (amp / length (vtransform(“shader”, Nn)); Phong as a Vertex Shader - Phong as a Vertex Shader - diffuse specular Lighthouse3d.com 8

  9. Issues with Bump Mapping Tangent Space  How much to perturb  Build a local coordinate system around the normal at a point  Common coordinate system  Using eye or even object may be cumbersome.  Normal map defined on object GLSL does not have a calculatenormal() function Tangent Space Matrix Multiplication  Converting to tangent space � � � � � � S x T x T y T z O x � � � � � � S y = B x B y B z O y � � � � � � � � S x T x T y T z O x � � � � � � � � � � � � � S z � N x N y N z � O z � � � � � � � S y = B x B y B z O y � � � � � � � S z � � N x N y N z � � O z � � � � � S x = T x O x + T y O y + T z O z � � S - vector in tangent space  T - tangent vector   S x = T • O N - normal vector  B - binormal vector  S y = B • O  O - vector in object space   S z = N • O Bump Mapping Bump Mapping  For a modified Phong  For a modified Phong:  Vertex shader takes as args:  Fragment Shader will:  Normal (built-in)  Modify normal  Tangent (user defined)  Do lighting calculation.  Bi-normal (can be calculated)  Will pass to fragment:  Set fragment color.  Light vector  Eye position  BOTH IN Tangent Space 9

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend