status – week 278 victor moya. lightning diffuse lightning. diffuse lightning. light sources....

53
Status – Week Status – Week 278 278 Victor Moya Victor Moya

Post on 20-Dec-2015

236 views

Category:

Documents


0 download

TRANSCRIPT

Status – Week Status – Week 278278

Victor MoyaVictor Moya

LightningLightning

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.

Light SourcesLight Sources Ambient Light.Ambient Light. Directional Light SourcesDirectional 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.Kc, Kl and Kq are constant, linear and quadratic attenuation values.U: Direction of the spot light.U: Direction of the spot light.L: Unit direction vector from surface point to light spot.L: Unit direction vector from surface point to light spot.

dKKKC

qlc2

1

dKKK

ULC

qlc2

}0,max{

Diffuse LightingDiffuse Lighting

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

n

i

NLiCiDTDTAdiffuseK1

}0,max{

Specular LightingSpecular Lighting

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

)0(}0,max{1

NLCiSGspecular NHiKmn

i

EmissionEmission

KKemissionemission = EM = EM

E: Surface emission color.E: Surface emission color.

M: Emission map sample.M: Emission map sample.

Gouraud ShadingGouraud Shading

Lighting is calculated at each vertex Lighting is calculated at each vertex and interpolated across the triangle.and interpolated across the triangle.

K = KK = Kprimaryprimary * T * T11 * T * T22 * ... * T * ... * Tkk + K + Ksecondarysecondary

Ti : Color samples for one of k texture maps.Ti : Color samples for one of k texture maps.* : One of several available texture combination operations* : One of several available texture combination operations

n

i

NLiCiDDAEprimaryK1

}0,max{

)0(secondary }0,max{1

NLCiS NHiKmn

i

Phong ShadingPhong Shading

Interpolate vertex normals and evaluates the Interpolate vertex normals and evaluates the lighting formula at each pixel.lighting formula at each pixel.

K = Kemission + Kdiffuse + KspecularK = Kemission + Kdiffuse + Kspecular

Problem: interpolation of normals produce non Problem: interpolation of normals produce non unit vectors. Use normalization cube maps.unit vectors. Use normalization cube maps.

Flat, Gouraud and Phong Flat, Gouraud and Phong ShadingShading

Bump MappingBump Mapping A hardware implementation of Phong A hardware implementation of Phong

Shading.Shading. Uses a texture map to perturb the normal Uses a texture map to perturb the normal

vector at each pixel (not interpolated).vector at each pixel (not interpolated). Bump Map: 2D arrays of 3D vectors. Bump Map: 2D arrays of 3D vectors.

Direction of the normal vector relative to Direction of the normal vector relative to the interpolated normal vector at the pixel.the interpolated normal vector at the pixel.

Uses tangent space for storing the Uses tangent space for storing the perturbations. Object to tanget space perturbations. Object to tanget space transformation (3x3 matrix multiplication).transformation (3x3 matrix multiplication).

Bump MappingBump Mapping

OpenGL LightingOpenGL Lighting

Calculated at vertex, interpolated Calculated at vertex, interpolated inside the triangle (Gouraud).inside the triangle (Gouraud).

Bump mapping supported by Bump mapping supported by propietary extensions.propietary extensions.

Pixel Shaders for programmable Pixel Shaders for programmable per pixel lighting.per pixel lighting.

OpenGL LightingOpenGL Lighting

OpenGL LightingOpenGL Lighting

OpenGL LightingOpenGL Lighting

Rasterization/FragmentsRasterization/Fragments

Calculate the final color value of Calculate the final color value of the fragment:the fragment: Texture Read.Texture Read. Color sum.Color sum. Fog.Fog.

OpenGL RasterizationOpenGL Rasterization

Per fragment (tests)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.

OpenGL per fragmentOpenGL per fragment

TexturesTextures Map from screen space coordinates to Map from screen space coordinates to

object space to texture space.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 Texture read: take a number of texture

samples (texels), filter them and combine samples (texels), filter them and combine the result with other texture results or the result with other texture results or original pixel color.original pixel color. Size pixel > Size texel => minificationSize pixel > Size texel => minification Size pixel = Size texel => copySize pixel = Size texel => copy Size pixel < Size texel => magnificationSize pixel < Size texel => magnification

Level of DetailLevel of Detail

LOD is calculated to determine the LOD is calculated to determine the mipmap level to use and to mipmap level to use and to determine if minification or determine if minification or magnification.magnification.

Level of DetailLevel of Detail

Select sampling mode using Select sampling mode using parameter C (can be 0 or 0.5):parameter C (can be 0 or 0.5): If If λ > c => minificationλ > c => minification If λ <= c => magnificationIf λ <= c => magnification

Scaler factor:Scaler factor:

MinificationMinification Minification:Minification:

Nearest: the texel in the center of the texture Nearest: the texel in the center of the texture coordinates is read.coordinates is read.

Linear: interpolation (bilinear).Linear: interpolation (bilinear).

Minification(2)Minification(2)

MipmappingMipmapping

A texture is formed by a piramidal A texture is formed by a piramidal data structure of max(n,m) images data structure of max(n,m) images from 2from 2nnx2x2mm to 1x1 pixels. to 1x1 pixels.

The proper image is accessed The proper image is accessed using the LOD parameter.using the LOD parameter.

MipmappingMipmapping Use calculated LOD for deciding which level to read Use calculated LOD for deciding which level to read

from.from. Filtering:Filtering:

NEAREST_MIPMAP_NEAREST and NEAREST_MIPMAP_NEAREST and LINEAR_MIPMAP_NEARESTLINEAR_MIPMAP_NEAREST

NEAREST_MIPMAP_LINEAR and NEAREST_MIPMAP_LINEAR and LINEAR_MIPMAP_LINEAR (trilinear filtering)LINEAR_MIPMAP_LINEAR (trilinear filtering)

MagnificationMagnification

LINEAR of NEAREST: similar to LINEAR of NEAREST: similar to mignification.mignification.

CubemapCubemap A cubemap texture is composed by 6 2D A cubemap texture is composed by 6 2D

texture/images for each of the 6 faces of a texture/images for each of the 6 faces of a cube.cube.

The texture coordinates (s, t, r) are used as a The texture coordinates (s, t, r) are used as a direction vector from the center of the cube to direction vector from the center of the cube to one of the sides.one of the sides.

The coordinate with the greatest absolute value The coordinate with the greatest absolute value is used to determine which face to access.is used to determine which face to access.

The other two coordinates are recalculated to The other two coordinates are recalculated to acess the texture in that face as normal 2D acess the texture in that face as normal 2D texture.texture.

CubemapCubemap

Texture environment and Texture environment and texture functionstexture functions

OpenGL 1.4, basic support for register OpenGL 1.4, basic support for register combiners (NV_texture_shaders for GF3 and combiners (NV_texture_shaders for GF3 and beyond, ATI_fragment_shader for R200).beyond, ATI_fragment_shader for R200).

Defines source arguments and functions to Defines source arguments and functions to combine textures and original color.combine textures and original color.

Functions: REPLACE, MODULATE, ADD, Functions: REPLACE, MODULATE, ADD, ADD_SIGNED, INTERPOLATE, SUBSTRACT, ADD_SIGNED, INTERPOLATE, SUBSTRACT, DOT3_RGB, DOT3_RGBA.DOT3_RGB, DOT3_RGBA.

Color channels (RGB) and alpha channel (A) Color channels (RGB) and alpha channel (A) are calculated (and configured) separately are calculated (and configured) separately in parallel.in parallel.

Shadow mapShadow map First pass: write depth buffer to a texture First pass: write depth buffer to a texture

from the point of view of a light.from the point of view of a light. Second pass: compare z value in texture Second pass: compare z value in texture

with current z value (eye). Use stencil with current z value (eye). Use stencil buffer.buffer.

In OpenGL 1.4 use texture internal format In OpenGL 1.4 use texture internal format DEPT_COMPONENT and texture comparision DEPT_COMPONENT and texture comparision mode: TEXTURE_COMPARE_MODE = mode: TEXTURE_COMPARE_MODE = COMPARE_R_TO_TEXTURE. COMPARE_R_TO_TEXTURE. TEXTURE_COMPARE_FUNC = {LEQUAL, TEXTURE_COMPARE_FUNC = {LEQUAL, GEQUAL}.GEQUAL}.

Projected texturesProjected textures

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

Color SumColor Sum

C = Cpri + Csec.C = Cpri + Csec. Combines diffuse and specular Combines diffuse and specular

color. color.

FogFog

Calculate blending factor f (3 modes):Calculate blending factor f (3 modes): c: FRAGMENT_DEPTH (eye to fragment c: FRAGMENT_DEPTH (eye to fragment

distance), FOG_COORDINATE (interpolated).distance), FOG_COORDINATE (interpolated). d: FOG_DENSITYd: FOG_DENSITY s: FOG_STARTs: FOG_START e: FOG_END. e: FOG_END.

Final color:Final color:

Ownership TestOwnership Test

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

Scissor TestScissor Test

void Scissor(int right, int bottom, void Scissor(int right, int bottom, sizei width, sizei height).sizei width, sizei height).

If left <= x < left + width and If left <= x < left + width and bottom <= y < bottom + height bottom <= y < bottom + height the test passes.the test passes.

Otherwisee fails and fragment is Otherwisee fails and fragment is discarded.discarded.

Alpha TestAlpha Test

void AlphaFunc(enum func, clampf void AlphaFunc(enum func, clampf ref)ref)

Compares reference value with Compares reference value with current fragment alpha (A) current fragment alpha (A) componed with a function (NEVER, componed with a function (NEVER, ALWAYS, LESS, LEQUAL, EQUAL, ALWAYS, LESS, LEQUAL, EQUAL, GEQUAL, GREATER, NOTEQUAL).GEQUAL, GREATER, NOTEQUAL).

If test fails fragment is discarded.If test fails fragment is discarded.

Stencil TestStencil 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 Stencil Buffer: a n-bit (uses to be 8-bit) buffer per

pixel in the framebuffer.pixel in the framebuffer. Tests the current stencil buffer value for the Tests the current stencil buffer value for the

fragment against the reference value, applying a fragment against the reference value, applying a binary mask and using a test function.binary mask and using a test function.

If the function fails the fragment is discarded and If the function fails the fragment is discarded and sfail function executed over the stencil entry.sfail function executed over the stencil entry.

The stencil buffer is also updated after depth test. The stencil buffer is also updated after depth test. dpfail function is executed when depth test fails dpfail function is executed when depth test fails and dppass when depth test pass.and dppass when depth test pass.

Stencil TestStencil Test Test functions: NEVER, ALWAYS, LESS, Test functions: NEVER, ALWAYS, LESS,

LEQUAL, GEQUAL, GREATER, NOTEQUAL.LEQUAL, GEQUAL, GREATER, NOTEQUAL.

Update functions: KEEP, ZERO, REPLACE, Update functions: KEEP, ZERO, REPLACE, INCR, DECR, INVERT, INCR_WRAP, INCR, DECR, INVERT, INCR_WRAP, DECR_WRAP. DECR_WRAP.

Applications:Applications: Shadows volumes.Shadows volumes. Shadow maps.Shadow maps. Others?Others?

Depth Buffer TestDepth 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):

NEVERNEVER ALWAYSALWAYS LESSLESS LEQUALLEQUAL EQUALEQUAL GREATERGREATER GEQUALGEQUAL NOTEQUALNOTEQUAL

If test fails fragment is discarded.If test fails fragment is discarded. If enabled stencil update functions are calledIf enabled stencil update functions are called..

BlendingBlending Combine fragment color with framebuffer Combine fragment color with framebuffer

color.color. Blend equations:Blend equations:

FUNC_ADD: C =Cs*S + Cd*DFUNC_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*SFUNC_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 Blend functions: weigth factors for the blend equation.equation.

Blend color: Cc constant color.Blend color: Cc constant color.

DitheringDithering

Approximate a fragment higher Approximate a fragment higher fragment precission color to a fragment precission color to a lower precission framebuffer color.lower precission framebuffer color.

Used?Used?

Logical OperationLogical Operation

From an early OGL extension.From an early OGL extension. Operations:Operations:

Pixel ShadersPixel Shaders

Pixel Shader 1.0, 1.1, 1.2, 1.3: Program Pixel Shader 1.0, 1.1, 1.2, 1.3: Program register combiners stage in NVidia register combiners stage in NVidia GeForce3 (NV20) and GeForce4 (NV25). GeForce3 (NV20) and GeForce4 (NV25). Supported in DX8 and Supported in DX8 and NV_texture_shader/NV_texture_shader2.NV_texture_shader/NV_texture_shader2.

Pixel Shader 1.4: ATI R200 (Radeon Pixel Shader 1.4: ATI R200 (Radeon 8500), extra features but also based in 8500), extra features but also based in register combiner hardware. Supported register combiner hardware. Supported in DX8.1 and ATI_fragment_shader.in DX8.1 and ATI_fragment_shader.

Pixel ShadersPixel Shaders

Pixel Shader 2.0: Programmable Pixel Shader 2.0: Programmable shaders (like vertex shaders) but shaders (like vertex shaders) but without branching. To be supported without branching. To be supported in DX9 and ARB_fragment_shader.in DX9 and ARB_fragment_shader.

Pixel Shader 3.0: Extended pixel Pixel Shader 3.0: Extended pixel shaders, unknown features shaders, unknown features (branching?, NV30 pixel shaders?). (branching?, NV30 pixel shaders?). To be supported in DX9 or DX9.1.To be supported in DX9 or DX9.1.

Pixel ShaderPixel 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 Optional Sampling (Texture read): up to 6 textures.textures.

Address Shader: up to 8 instructions.Address Shader: up to 8 instructions. Optional Sampling: up to 6 textures, can Optional Sampling: up to 6 textures, can

be dependent reads.be dependent reads. Color Shader: up to 8 instructions.Color Shader: up to 8 instructions.

Pixel ShadersPixel Shaders

PS2 pixel shaders are true processors (?). PS2 pixel shaders are true processors (?). Based in Vertex Shaders but without Based in Vertex Shaders but without branching.branching.

Replaces (or complements) the register Replaces (or complements) the register combiner stage (NV30).combiner stage (NV30).

Most instructions of the vertex shader are Most instructions of the vertex shader are present in the pixel shader (but branches).present in the pixel shader (but branches).

Conditional codes, swizzle, negate, absolute Conditional codes, swizzle, negate, absolute value, mask, conditional mask (NV30).value, mask, conditional mask (NV30).

R300 Pixel ShaderR300 Pixel Shader

Pixel ShaderPixel 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 coordinates8 texture coordinates 1 fog coordinate.1 fog coordinate.

Outputs: Outputs: fragment color (RGBA), optionally new fragment color (RGBA), optionally new

fragment depth.fragment depth. In NV30/R300 also to 4 RGBA textures.In NV30/R300 also to 4 RGBA textures.

Pixel ShaderPixel Shader

Temporaries: Temporaries: NV30: 32 32-bit registers (64 16-bit registers).NV30: 32 32-bit registers (64 16-bit registers). R300: R300: 12 temporary registers12 temporary registers

Constants: Constants: NV30: unlimited? (maybe memory?). Accessed NV30: unlimited? (maybe memory?). Accessed

by ‘name’ (label). Also literal constants by ‘name’ (label). Also literal constants (embedded).(embedded).

R300: 32 constants.R300: 32 constants. DX9 (PS 2.0): 16 samplers and 8 texture DX9 (PS 2.0): 16 samplers and 8 texture

coordinates.coordinates.

Pixel ShaderPixel Shader

R300: 64 ALU instructions, 32 texture R300: 64 ALU instructions, 32 texture instructions, 4 levels of dependent read. Up to instructions, 4 levels of dependent read. Up to 96 instructions (?).96 instructions (?).

R300: R300: ALU instructions: ADD, MOV, MUL, MAD, ALU instructions: ADD, MOV, MUL, MAD,

DP3, DP4, FRAC, RCP, RSP, EXD, LOG, CMP.DP3, DP4, FRAC, RCP, RSP, EXD, LOG, CMP. Texture: TEXLD, TEXLDP, TEXLDBIAS, Texture: TEXLD, TEXLDP, TEXLDBIAS,

TEXKILL.TEXKILL.

Pixel ShaderPixel 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, Pack/Unpack: PK2H, PK2US, PK4B, PK4UB,

PK4UBG, UP2H, UP2US, UP4B, UP4UB, PK4UBG, UP2H, UP2US, UP4B, UP4UB, UP4UBG.UP4UBG.

Fragment conditional kill: KIL.Fragment conditional kill: KIL. Extra math: LRP (linear interpolation), X2D Extra math: LRP (linear interpolation), X2D

(2D coordinate transform), RFL (reflection), (2D coordinate transform), RFL (reflection), POW (exponentation).POW (exponentation).

OthersOthers

AntialiasingAntialiasing Anisotropic Filtering (textures).Anisotropic Filtering (textures). Line Antialiasing.Line Antialiasing. Edge AntialiasingEdge Antialiasing Full Screen Antialiasing (FSA).Full Screen Antialiasing (FSA). Supersampling.Supersampling. MultiSampling.MultiSampling.