Presentation is loading. Please wait.

Presentation is loading. Please wait.

Status – Week 278 Victor Moya. Lightning Diffuse Lightning. Diffuse Lightning. Light Sources. Light Sources. Specular Lightning. Specular Lightning. Emission.

Similar presentations


Presentation on theme: "Status – Week 278 Victor Moya. Lightning Diffuse Lightning. Diffuse Lightning. Light Sources. Light Sources. Specular Lightning. Specular Lightning. Emission."— Presentation transcript:

1 Status – Week 278 Victor Moya

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

3 Light Sources Ambient Light. Ambient Light. Directional Light Sources Directional Light Sources Infinite light source (parallel rays). Infinite light source (parallel rays). No attenuation. No attenuation. Point Light Sources. Point Light Sources. All directions. All directions. Attenuation. Attenuation. Spot Light Sources. Spot Light Sources. Cone of light. Cone of light. Attenuation. 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 K emission = EM E: Surface emission color. M: Emission map sample.

7 Gouraud Shading Lighting is calculated at each vertex and interpolated across the triangle. Lighting is calculated at each vertex and interpolated across the triangle. K = K primary * T 1 * T 2 *... * T k + K secondary 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. 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. 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. A hardware implementation of Phong Shading. Uses a texture map to perturb the normal vector at each pixel (not interpolated). 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. 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). 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). Calculated at vertex, interpolated inside the triangle (Gouraud). Bump mapping supported by propietary extensions. Bump mapping supported by propietary extensions. Pixel Shaders for programmable per pixel lighting. Pixel Shaders for programmable per pixel lighting.

13 OpenGL Lighting

14

15

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

17 OpenGL Rasterization

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

19 OpenGL per fragment

20 Textures Map from screen space coordinates to object space to texture space. Map from screen space coordinates to object space to texture space. Texture formats: 1D, 2D, 3D and cubemap. 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. 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 => minification Size pixel = Size texel => copy Size pixel = Size texel => copy Size pixel magnification Size pixel magnification

21 Level of Detail LOD is calculated to determine the mipmap level to use and to determine if minification or magnification. 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): Select sampling mode using parameter C (can be 0 or 0.5): If λ > c => minification If λ > c => minification If λ magnification If λ magnification Scaler factor: Scaler factor:

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

24 Minification(2)

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

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

27 Magnification LINEAR of NEAREST: similar to mignification. 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. 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 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 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. 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). 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. Defines source arguments and functions to combine textures and original color. Functions: REPLACE, MODULATE, ADD, ADD_SIGNED, INTERPOLATE, SUBSTRACT, DOT3_RGB, DOT3_RGBA. 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. 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. 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. 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}. 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). Divide by fourth component (s, t, r, q) and access the texture (s/q, t/q, r/q).

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

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

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

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

37 Alpha Test void AlphaFunc(enum func, clampf ref) 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). 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. If test fails fragment is discarded.

38 Stencil Test void StencilFunc(enum func, int ref, uint mask). void StencilFunc(enum func, int ref, uint mask). Void StencilOp(enum sfail, dpfail, enum dppass). Void StencilOp(enum sfail, dpfail, enum dppass). Stencil Buffer: a n-bit (uses to be 8-bit) buffer per pixel in the framebuffer. 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. 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. 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. 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. Test functions: NEVER, ALWAYS, LESS, LEQUAL, GEQUAL, GREATER, NOTEQUAL. Update functions: KEEP, ZERO, REPLACE, INCR, DECR, INVERT, INCR_WRAP, DECR_WRAP. Update functions: KEEP, ZERO, REPLACE, INCR, DECR, INVERT, INCR_WRAP, DECR_WRAP. Applications: Applications: Shadows volumes. Shadows volumes. Shadow maps. Shadow maps. Others? Others?

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

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

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

43 Logical Operation From an early OGL extension. From an early OGL extension. Operations: 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.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. 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 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. 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: Pixel Shader 1.4: 8 constants. 8 constants. Two phases divided in 4 parts: Two phases divided in 4 parts: Optional Sampling (Texture read): up to 6 textures. Optional Sampling (Texture read): up to 6 textures. Address Shader: up to 8 instructions. Address Shader: up to 8 instructions. Optional Sampling: up to 6 textures, can be dependent reads. Optional Sampling: up to 6 textures, can be dependent reads. Color Shader: up to 8 instructions. Color Shader: up to 8 instructions.

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

48 R300 Pixel Shader

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

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

51 Pixel Shader R300: 64 ALU instructions, 32 texture instructions, 4 levels of dependent read. Up to 96 instructions (?). R300: 64 ALU instructions, 32 texture instructions, 4 levels of dependent read. Up to 96 instructions (?). R300: R300: ALU instructions: ADD, MOV, MUL, MAD, DP3, DP4, FRAC, RCP, RSP, EXD, LOG, CMP. ALU instructions: ADD, MOV, MUL, MAD, DP3, DP4, FRAC, RCP, RSP, EXD, LOG, CMP. Texture: TEXLD, TEXLDP, TEXLDBIAS, TEXKILL. Texture: TEXLD, TEXLDP, TEXLDBIAS, TEXKILL.

52 Pixel Shader NV30: up to 1024 instructions. NV30: up to 1024 instructions. Additional instructions (NV30): Additional instructions (NV30): Texture read: TEX, TEXP, TXD. Texture read: TEX, TEXP, TXD. Partial derivarives: DDX, DDY. Partial derivarives: DDX, DDY. Pack/Unpack: PK2H, PK2US, PK4B, PK4UB, PK4UBG, UP2H, UP2US, UP4B, UP4UB, UP4UBG. Pack/Unpack: PK2H, PK2US, PK4B, PK4UB, PK4UBG, UP2H, UP2US, UP4B, UP4UB, UP4UBG. Fragment conditional kill: KIL. Fragment conditional kill: KIL. Extra math: LRP (linear interpolation), X2D (2D coordinate transform), RFL (reflection), POW (exponentation). Extra math: LRP (linear interpolation), X2D (2D coordinate transform), RFL (reflection), POW (exponentation).

53 Others Antialiasing Antialiasing Anisotropic Filtering (textures). Anisotropic Filtering (textures). Line Antialiasing. Line Antialiasing. Edge Antialiasing Edge Antialiasing Full Screen Antialiasing (FSA). Full Screen Antialiasing (FSA). Supersampling. Supersampling. MultiSampling. MultiSampling.


Download ppt "Status – Week 278 Victor Moya. Lightning Diffuse Lightning. Diffuse Lightning. Light Sources. Light Sources. Specular Lightning. Specular Lightning. Emission."

Similar presentations


Ads by Google