1 / 53

Status – Week 278

Status – Week 278. Victor Moya. Lightning. Diffuse Lightning. Light Sources. Specular Lightning. Emission. Gouraud Shading. Phong Shading. Bump Mapping. OpenGL Lightning. Light Sources. Ambient Light. Directional Light Sources Infinite light source (parallel rays). No attenuation.

wpillow
Télécharger la présentation

Status – Week 278

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Status – Week 278 Victor Moya

  2. Lightning • Diffuse Lightning. • Light Sources. • Specular Lightning. • Emission. • Gouraud Shading. • Phong Shading. • Bump Mapping. • OpenGL Lightning.

  3. Light Sources • Ambient Light. • Directional Light Sources • Infinite light source (parallel rays). • No attenuation. • Point Light Sources. • All directions. • Attenuation. • Spot Light Sources. • Cone of light. • Attenuation. Kc, Kl and Kq are constant, linear and quadratic attenuation values. U: Direction of the spot light. L: Unit direction vector from surface point to light spot.

  4. Diffuse Lighting A: Ambient light T: Texture sample. D: Surface diffuse reflection color. Ci: Intensity of the i light at the surface point. N: Normal vector of the surface. Li: Unit direction vector to the light source I.

  5. Specular Lighting S: Surface specular color. Ci: Intensity of the incident light. m: specular exponent (larger, sharper hightlight). G: Gloss map sample. N: Normal vector at the surface. L: Unit direction to light vector. Hi: Halfway vector (V + L). V: Unit direction to viewer vector.

  6. Emission Kemission = EM E: Surface emission color. M: Emission map sample.

  7. Gouraud Shading • Lighting is calculated at each vertex and interpolated across the triangle. K = Kprimary * T1 * T2 * ... * Tk + Ksecondary Ti : Color samples for one of k texture maps. * : One of several available texture combination operations

  8. Phong Shading • Interpolate vertex normals and evaluates the lighting formula at each pixel. K = Kemission + Kdiffuse + Kspecular • Problem: interpolation of normals produce non unit vectors. Use normalization cube maps.

  9. Flat, Gouraud and Phong Shading

  10. Bump Mapping • A hardware implementation of Phong Shading. • Uses a texture map to perturb the normal vector at each pixel (not interpolated). • Bump Map: 2D arrays of 3D vectors. Direction of the normal vector relative to the interpolated normal vector at the pixel. • Uses tangent space for storing the perturbations. Object to tanget space transformation (3x3 matrix multiplication).

  11. Bump Mapping

  12. OpenGL Lighting • Calculated at vertex, interpolated inside the triangle (Gouraud). • Bump mapping supported by propietary extensions. • Pixel Shaders for programmable per pixel lighting.

  13. OpenGL Lighting

  14. OpenGL Lighting

  15. OpenGL Lighting

  16. Rasterization/Fragments • Calculate the final color value of the fragment: • Texture Read. • Color sum. • Fog.

  17. OpenGL Rasterization

  18. Per fragment (tests) • Determine the vissibility of the fragment: • Ownership test. • Scissor test. • Alpha test. • Stencil test. • Depth Buffer test. • Final pixel color: • Blending. • Dithering. • Logic Operation.

  19. OpenGL per fragment

  20. Textures • Map from screen space coordinates to object space to texture space. • Texture formats: 1D, 2D, 3D and cubemap. • Texture read: take a number of texture samples (texels), filter them and combine the result with other texture results or original pixel color. • Size pixel > Size texel => minification • Size pixel = Size texel => copy • Size pixel < Size texel => magnification

  21. Level of Detail • LOD is calculated to determine the mipmap level to use and to determine if minification or magnification.

  22. Level of Detail • Select sampling mode using parameter C (can be 0 or 0.5): • If λ > c => minification • If λ <= c => magnification • Scaler factor:

  23. Minification • Minification: • Nearest: the texel in the center of the texture coordinates is read. • Linear: interpolation (bilinear).

  24. Minification(2)

  25. Mipmapping • A texture is formed by a piramidal data structure of max(n,m) images from 2nx2m to 1x1 pixels. • The proper image is accessed using the LOD parameter.

  26. Mipmapping • Use calculated LOD for deciding which level to read from. • Filtering: • NEAREST_MIPMAP_NEAREST and LINEAR_MIPMAP_NEAREST • NEAREST_MIPMAP_LINEAR and LINEAR_MIPMAP_LINEAR (trilinear filtering)

  27. Magnification • LINEAR of NEAREST: similar to mignification.

  28. Cubemap • A cubemap texture is composed by 6 2D texture/images for each of the 6 faces of a cube. • The texture coordinates (s, t, r) are used as a direction vector from the center of the cube to one of the sides. • The coordinate with the greatest absolute value is used to determine which face to access. • The other two coordinates are recalculated to acess the texture in that face as normal 2D texture.

  29. Cubemap

  30. Texture environment and texture functions • OpenGL 1.4, basic support for register combiners (NV_texture_shaders for GF3 and beyond, ATI_fragment_shader for R200). • Defines source arguments and functions to combine textures and original color. • Functions: REPLACE, MODULATE, ADD, ADD_SIGNED, INTERPOLATE, SUBSTRACT, DOT3_RGB, DOT3_RGBA. • Color channels (RGB) and alpha channel (A) are calculated (and configured) separately in parallel.

  31. Shadow map • First pass: write depth buffer to a texture from the point of view of a light. • Second pass: compare z value in texture with current z value (eye). Use stencil buffer. • In OpenGL 1.4 use texture internal format DEPT_COMPONENT and texture comparision mode: TEXTURE_COMPARE_MODE = COMPARE_R_TO_TEXTURE. TEXTURE_COMPARE_FUNC = {LEQUAL, GEQUAL}.

  32. Projected textures • Divide by fourth component (s, t, r, q) and access the texture (s/q, t/q, r/q).

  33. Color Sum • C = Cpri + Csec. • Combines diffuse and specular color.

  34. Fog • Calculate blending factor f (3 modes): • c: FRAGMENT_DEPTH (eye to fragment distance), FOG_COORDINATE (interpolated). • d: FOG_DENSITY • s: FOG_START • e: FOG_END. • Final color:

  35. Ownership Test • Current pixel (x, y) is owned by the current OGL context?

  36. Scissor Test • void Scissor(int right, int bottom, sizei width, sizei height). • If left <= x < left + width and bottom <= y < bottom + height the test passes. • Otherwisee fails and fragment is discarded.

  37. Alpha Test • void AlphaFunc(enum func, clampf ref) • Compares reference value with current fragment alpha (A) componed with a function (NEVER, ALWAYS, LESS, LEQUAL, EQUAL, GEQUAL, GREATER, NOTEQUAL). • If test fails fragment is discarded.

  38. Stencil Test • void StencilFunc(enum func, int ref, uint mask). • Void StencilOp(enum sfail, dpfail, enum dppass). • Stencil Buffer: a n-bit (uses to be 8-bit) buffer per pixel in the framebuffer. • Tests the current stencil buffer value for the fragment against the reference value, applying a binary mask and using a test function. • If the function fails the fragment is discarded and sfail function executed over the stencil entry. • The stencil buffer is also updated after depth test. dpfail function is executed when depth test fails and dppass when depth test pass.

  39. Stencil Test • Test functions: NEVER, ALWAYS, LESS, LEQUAL, GEQUAL, GREATER, NOTEQUAL. • Update functions: KEEP, ZERO, REPLACE, INCR, DECR, INVERT, INCR_WRAP, DECR_WRAP. • Applications: • Shadows volumes. • Shadow maps. • Others?

  40. Depth Buffer Test • void DepthFunc(enum func) • Test functions (fragment z value with framebuffer z value): • NEVER • ALWAYS • LESS • LEQUAL • EQUAL • GREATER • GEQUAL • NOTEQUAL • If test fails fragment is discarded. • If enabled stencil update functions are called.

  41. Blending • Combine fragment color with framebuffer color. • Blend equations: • FUNC_ADD: C =Cs*S + Cd*D • FUNC_SUBTRACT: C = Cs*S + Cd* • FUNC_REVERSE_SUBTRACT: C = Cd*D – Cs*S • MIN: C = min(Cs, Cd) • MA: C = max(Cs, CD) • Blend functions: weigth factors for the blend equation. • Blend color: Cc constant color.

  42. Dithering • Approximate a fragment higher fragment precission color to a lower precission framebuffer color. • Used?

  43. Logical Operation • From an early OGL extension. • Operations:

  44. Pixel Shaders • Pixel Shader 1.0, 1.1, 1.2, 1.3: Program register combiners stage in NVidia GeForce3 (NV20) and GeForce4 (NV25). Supported in DX8 and NV_texture_shader/NV_texture_shader2. • Pixel Shader 1.4: ATI R200 (Radeon 8500), extra features but also based in register combiner hardware. Supported in DX8.1 and ATI_fragment_shader.

  45. Pixel Shaders • Pixel Shader 2.0: Programmable shaders (like vertex shaders) but without branching. To be supported in DX9 and ARB_fragment_shader. • Pixel Shader 3.0: Extended pixel shaders, unknown features (branching?, NV30 pixel shaders?). To be supported in DX9 or DX9.1.

  46. Pixel Shader • Pixel Shader 1.4: • 8 constants. • Two phases divided in 4 parts: • Optional Sampling (Texture read): up to 6 textures. • Address Shader: up to 8 instructions. • Optional Sampling: up to 6 textures, can be dependent reads. • Color Shader: up to 8 instructions.

  47. Pixel Shaders • PS2 pixel shaders are true processors (?). Based in Vertex Shaders but without branching. • Replaces (or complements) the register combiner stage (NV30). • Most instructions of the vertex shader are present in the pixel shader (but branches). • Conditional codes, swizzle, negate, absolute value, mask, conditional mask (NV30).

  48. R300 Pixel Shader

  49. Pixel Shader • Inputs: • 1 position (x, y, z, 1/w) • 2 colors (4 compenent vector RGBA) • 8 texture coordinates • 1 fog coordinate. • Outputs: • fragment color (RGBA), optionally new fragment depth. • In NV30/R300 also to 4 RGBA textures.

  50. Pixel Shader • Temporaries: • NV30: 32 32-bit registers (64 16-bit registers). • R300: 12 temporary registers • Constants: • NV30: unlimited? (maybe memory?). Accessed by ‘name’ (label). Also literal constants (embedded). • R300: 32 constants. • DX9 (PS 2.0): 16 samplers and 8 texture coordinates.

More Related