Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image ...

26
Multi-pass Rendering

Transcript of Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image ...

Page 1: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

Multi-pass Rendering

Page 2: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek2

Multi-pass Rendering• Repeat: image Repeat: image Rendering pass Rendering pass result image result image

• Final image = combination of the result imagesFinal image = combination of the result images

• Example: final image = texture map + light map + fog mapExample: final image = texture map + light map + fog map

ReasonReason

• Speed : faster to separate passes, supported by hardwareSpeed : faster to separate passes, supported by hardware

• Lower algorithm complexityLower algorithm complexity

• Many effects possible by different combinations of passesMany effects possible by different combinations of passes

• Repeat: image Repeat: image Rendering pass Rendering pass result image result image

• Final image = combination of the result imagesFinal image = combination of the result images

• Example: final image = texture map + light map + fog mapExample: final image = texture map + light map + fog map

ReasonReason

• Speed : faster to separate passes, supported by hardwareSpeed : faster to separate passes, supported by hardware

• Lower algorithm complexityLower algorithm complexity

• Many effects possible by different combinations of passesMany effects possible by different combinations of passes

Page 3: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek3

Combining rendered images• Porter and Duff, “Composing digital images”, Porter and Duff, “Composing digital images”, Computer Computer

GraphicsGraphics, 18(3):253~259, (1984)., 18(3):253~259, (1984).

• Duff, “Compositing 3D rendered images”, Duff, “Compositing 3D rendered images”, Computer GraphicsComputer Graphics, , 19(3):41~44, (1985).19(3):41~44, (1985).

• Possible to combine images with Z-valuesPossible to combine images with Z-values

• Pixel represented by up to 5 channels: R G B Pixel represented by up to 5 channels: R G B Z Z

(alpha channel) : usually blending ratio(alpha channel) : usually blending ratio

• Z : depth informationZ : depth information

• Porter and Duff, “Composing digital images”, Porter and Duff, “Composing digital images”, Computer Computer GraphicsGraphics, 18(3):253~259, (1984)., 18(3):253~259, (1984).

• Duff, “Compositing 3D rendered images”, Duff, “Compositing 3D rendered images”, Computer GraphicsComputer Graphics, , 19(3):41~44, (1985).19(3):41~44, (1985).

• Possible to combine images with Z-valuesPossible to combine images with Z-values

• Pixel represented by up to 5 channels: R G B Pixel represented by up to 5 channels: R G B Z Z

(alpha channel) : usually blending ratio(alpha channel) : usually blending ratio

• Z : depth informationZ : depth information

Page 4: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek4

Combining rendered images• Basic binary operator:Basic binary operator: cc = = ff opop bb

• ZZminmin operator : combine images using Z channel operator : combine images using Z channel

– RGBRGBcc = (if Z = (if Zff < Z < Zbb then RGB then RGBff else RGB else RGBb b ))

– ZZcc = = minmin(Z(Zff, Z, Zbb))

• overover operator : combine images using alpha channel operator : combine images using alpha channel

– RGBRGBcc = RGB = RGBff + (1 – + (1 – ff) RGB) RGBbb

cc = = ff + (1 – + (1 – ff) ) bb

• Basic binary operator:Basic binary operator: cc = = ff opop bb

• ZZminmin operator : combine images using Z channel operator : combine images using Z channel

– RGBRGBcc = (if Z = (if Zff < Z < Zbb then RGB then RGBff else RGB else RGBb b ))

– ZZcc = = minmin(Z(Zff, Z, Zbb))

• overover operator : combine images using alpha channel operator : combine images using alpha channel

– RGBRGBcc = RGB = RGBff + (1 – + (1 – ff) RGB) RGBbb

cc = = ff + (1 – + (1 – ff) ) bb

Page 5: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek5

• compcomposition operator: combine both of above osition operator: combine both of above operatorsoperators

– RGBRGBcc = = (f (f overover b) + (1 – b) + (1 – ) (b ) (b overover f) f)

area of pixel where f is in front of barea of pixel where f is in front of b

• compcomposition operator: combine both of above osition operator: combine both of above operatorsoperators

– RGBRGBcc = = (f (f overover b) + (1 – b) + (1 – ) (b ) (b overover f) f)

area of pixel where f is in front of barea of pixel where f is in front of b

Page 6: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek6

Blending (OpenGL)• Alpha blending (OpenGL: dst is in frame buffer, src is Alpha blending (OpenGL: dst is in frame buffer, src is

incoming)incoming)

– (RGB(RGB))newnew = (RGB = (RGB))srcsrc * blend * blendsrcsrc + (RGB + (RGB))dstdst * blend * blenddstdst

– Depending on blendDepending on blendsrcsrc and blend and blenddstdst different effect different effect

• Standard renderStandard render

– (RGB(RGB))newnew=(RGB=(RGB))srcsrc**srcsrc+(RGB+(RGB))dstdst*(1-*(1-))srcsrc

• Light map (src is light map)Light map (src is light map)

– (RGB(RGB))new new = (RGB= (RGB))src src * 0 + (RGB* 0 + (RGB))dst dst * (RGB* (RGB))srcsrc

• Alpha blending (OpenGL: dst is in frame buffer, src is Alpha blending (OpenGL: dst is in frame buffer, src is incoming)incoming)

– (RGB(RGB))newnew = (RGB = (RGB))srcsrc * blend * blendsrcsrc + (RGB + (RGB))dstdst * blend * blenddstdst

– Depending on blendDepending on blendsrcsrc and blend and blenddstdst different effect different effect

• Standard renderStandard render

– (RGB(RGB))newnew=(RGB=(RGB))srcsrc**srcsrc+(RGB+(RGB))dstdst*(1-*(1-))srcsrc

• Light map (src is light map)Light map (src is light map)

– (RGB(RGB))new new = (RGB= (RGB))src src * 0 + (RGB* 0 + (RGB))dst dst * (RGB* (RGB))srcsrc

Page 7: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek7

Z-buffer (OpenGL)• Original Z-buffer : update when Z value is lessOriginal Z-buffer : update when Z value is less

• Generalized in OpenGLGeneralized in OpenGL

– Z comparison: <, <=, >, >=, ==, !=, always, neverZ comparison: <, <=, >, >=, ==, !=, always, never

– Depth testing and z-value updating separatedDepth testing and z-value updating separated

• Original Z-buffer : update when Z value is lessOriginal Z-buffer : update when Z value is less

• Generalized in OpenGLGeneralized in OpenGL

– Z comparison: <, <=, >, >=, ==, !=, always, neverZ comparison: <, <=, >, >=, ==, !=, always, never

– Depth testing and z-value updating separatedDepth testing and z-value updating separated

ZstoredZincoming

Page 8: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek8

Accumulation buffer (OpenGL)• accumaccum

– (RGB(RGB))fb fb == (RGB(RGB))fb fb + value * (RGB+ value * (RGB))newnew

• loadload

– (RGB(RGB))fb fb == value * (RGBvalue * (RGB))newnew

• addadd

– (RGB(RGB))fb fb == value + (RGBvalue + (RGB))fbfb

• multmult

– (RGB(RGB))fb fb = value * (RGB= value * (RGB))fbfb

• accumaccum

– (RGB(RGB))fb fb == (RGB(RGB))fb fb + value * (RGB+ value * (RGB))newnew

• loadload

– (RGB(RGB))fb fb == value * (RGBvalue * (RGB))newnew

• addadd

– (RGB(RGB))fb fb == value + (RGBvalue + (RGB))fbfb

• multmult

– (RGB(RGB))fb fb = value * (RGB= value * (RGB))fbfb

Page 9: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek9

Stencil Buffer (OpenGL)• Frame buffer over-written only if both stencil test and depth Frame buffer over-written only if both stencil test and depth

test passtest pass

• Stencil test:Stencil test:

– ifif ( (refref & & mask)mask) opop ( (stencilstencil & & mask)mask)op: <, <=, >, >=, ==, !=, always, neverop: <, <=, >, >=, ==, !=, always, neverref: reference value for testref: reference value for testmask: bit maskmask: bit mask

– Stencil buffer updated as: increase, decrease, invert, zero, Stencil buffer updated as: increase, decrease, invert, zero, keep, etc.keep, etc.

• Frame buffer over-written only if both stencil test and depth Frame buffer over-written only if both stencil test and depth test passtest pass

• Stencil test:Stencil test:

– ifif ( (refref & & mask)mask) opop ( (stencilstencil & & mask)mask)op: <, <=, >, >=, ==, !=, always, neverop: <, <=, >, >=, ==, !=, always, neverref: reference value for testref: reference value for testmask: bit maskmask: bit mask

– Stencil buffer updated as: increase, decrease, invert, zero, Stencil buffer updated as: increase, decrease, invert, zero, keep, etc.keep, etc.

Page 10: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek10

Examples of multi-pass algorithms

Page 11: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek11

Back-to-front transparencyUsual methodUsual method

• 1. 1. Draw opaque objectsDraw opaque objects

• 2. 2. Sort transparent objects back-to-frontSort transparent objects back-to-front

• 3. Render back-to-front using opacity/transparency factor 3. Render back-to-front using opacity/transparency factor tt

C = C = tt C Ctranstrans + (1 – + (1 – tt) C) Cbackback

• Disadvantage : slow because of sortingDisadvantage : slow because of sorting

Usual methodUsual method• 1. 1. Draw opaque objectsDraw opaque objects

• 2. 2. Sort transparent objects back-to-frontSort transparent objects back-to-front

• 3. Render back-to-front using opacity/transparency factor 3. Render back-to-front using opacity/transparency factor tt

C = C = tt C Ctranstrans + (1 – + (1 – tt) C) Cbackback

• Disadvantage : slow because of sortingDisadvantage : slow because of sorting

CbackCtrans

Page 12: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek12

Back-to-front transparencywithout sorting• Deifenbach, “Pipeline rendering: Interaction and realism Deifenbach, “Pipeline rendering: Interaction and realism

through hardware based multi-pass rendering”, through hardware based multi-pass rendering”, Ph.D ThesisPh.D Thesis, , Univ. Penn, (1996).Univ. Penn, (1996).

• 2 2 OpenGL Z-buffersOpenGL Z-buffers

• Deifenbach, “Pipeline rendering: Interaction and realism Deifenbach, “Pipeline rendering: Interaction and realism through hardware based multi-pass rendering”, through hardware based multi-pass rendering”, Ph.D ThesisPh.D Thesis, , Univ. Penn, (1996).Univ. Penn, (1996).

• 2 2 OpenGL Z-buffersOpenGL Z-buffers

Zcurrent : depth of current pixelfurthest from viewer but closerthan Zprev

Zprev : depth of previousprocessed transparent pixel

Page 13: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek13

Back-to-front transparency• initialize : draw opaque objectsinitialize : draw opaque objects

• looploop

– Find transparent object furthestFind transparent object furthest

– Blend on top of opaqueBlend on top of opaque, , updateupdate

• initialize : draw opaque objectsinitialize : draw opaque objects

• looploop

– Find transparent object furthestFind transparent object furthest

– Blend on top of opaqueBlend on top of opaque, , updateupdate

Advance drawing opaque objectsZmin

Advance drawing transparent obj

Don’t draw transparent, advance Z

Page 14: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek14

Planar reflections• Two approaches for modeling objects inside mirrorTwo approaches for modeling objects inside mirror

– Reflect objectReflect object

– Reflect view pointReflect view point

• Two approaches for modeling objects inside mirrorTwo approaches for modeling objects inside mirror

– Reflect objectReflect object

– Reflect view pointReflect view point

mirror

Reflect object

Reflect view point

Page 15: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek15

Planar reflection

Rendering order (reverse also works)Rendering order (reverse also works)

• Render everything except mirror objectsRender everything except mirror objects

• Mirror area stencil bufferMirror area stencil buffer turned ONturned ON

• Reflect object to new locationReflect object to new location

• Render againRender again

– Because stencil buffer only mirror area renderedBecause stencil buffer only mirror area rendered

Rendering order (reverse also works)Rendering order (reverse also works)

• Render everything except mirror objectsRender everything except mirror objects

• Mirror area stencil bufferMirror area stencil buffer turned ONturned ON

• Reflect object to new locationReflect object to new location

• Render againRender again

– Because stencil buffer only mirror area renderedBecause stencil buffer only mirror area rendered

Page 16: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek16

Example :final result

Page 17: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek17

Example :stencil buffer & mirror

Page 18: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek18

Multi-pass shadow volumes• McReynolds and Blythe, “Advanced graphics programming techniques McReynolds and Blythe, “Advanced graphics programming techniques

using OpenGL”, using OpenGL”, SIGGRAPH’98 course notesSIGGRAPH’98 course notes, (1998)., (1998).

• Render scene as if it was entirely in shadow using Z-buffer Render scene as if it was entirely in shadow using Z-buffer (ambient light only)(ambient light only)

• Make stencil buffer from shadow volumeMake stencil buffer from shadow volume

– ““Render” front then back facing shadow volume to determine Render” front then back facing shadow volume to determine pixels that are between the twopixels that are between the two

• Render scene using lightingRender scene using lighting

– Render outside stencil bufferRender outside stencil buffer

– Outside shadow becomes brighterOutside shadow becomes brighter

• McReynolds and Blythe, “Advanced graphics programming techniques McReynolds and Blythe, “Advanced graphics programming techniques using OpenGL”, using OpenGL”, SIGGRAPH’98 course notesSIGGRAPH’98 course notes, (1998)., (1998).

• Render scene as if it was entirely in shadow using Z-buffer Render scene as if it was entirely in shadow using Z-buffer (ambient light only)(ambient light only)

• Make stencil buffer from shadow volumeMake stencil buffer from shadow volume

– ““Render” front then back facing shadow volume to determine Render” front then back facing shadow volume to determine pixels that are between the twopixels that are between the two

• Render scene using lightingRender scene using lighting

– Render outside stencil bufferRender outside stencil buffer

– Outside shadow becomes brighterOutside shadow becomes brighter

Page 19: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek19

Spherical Light Objects• Using Z-buffer create stencil bufferUsing Z-buffer create stencil buffer

– Render front face with inverted Z-test (part below Render front face with inverted Z-test (part below surface)surface)

– Render back face withRender back face withinverted Z-testinverted Z-test

• Render inside stencilRender inside stencilbuffer with lightbuffer with light

• Using Z-buffer create stencil bufferUsing Z-buffer create stencil buffer

– Render front face with inverted Z-test (part below Render front face with inverted Z-test (part below surface)surface)

– Render back face withRender back face withinverted Z-testinverted Z-test

• Render inside stencilRender inside stencilbuffer with lightbuffer with light

camera

stencil buffer ON

Front-facing

Page 20: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek20

Anti-aliasing• Original use of accumulation bufferOriginal use of accumulation buffer

• Determine n view windowsDetermine n view windows

• Average theAverage the n n imagesimages

• Result: super samplingResult: super sampling

• Can also work for other “Monte Carlo” integration methodsCan also work for other “Monte Carlo” integration methods

– Temporal anti-aliasingTemporal anti-aliasing

– Depth of fieldDepth of field

• Original use of accumulation bufferOriginal use of accumulation buffer

• Determine n view windowsDetermine n view windows

• Average theAverage the n n imagesimages

• Result: super samplingResult: super sampling

• Can also work for other “Monte Carlo” integration methodsCan also work for other “Monte Carlo” integration methods

– Temporal anti-aliasingTemporal anti-aliasing

– Depth of fieldDepth of field

Page 21: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek21

Simulated Depth of Field• Render scene from different view point but same Render scene from different view point but same

view plane and center of interest (shear projection)view plane and center of interest (shear projection)

• When averaged objects on focus When averaged objects on focus plane in focusplane in focus

• Render scene from different view point but same Render scene from different view point but same view plane and center of interest (shear projection)view plane and center of interest (shear projection)

• When averaged objects on focus When averaged objects on focus plane in focusplane in focus

Object in focus

Object outof focus

viewpoints

Page 22: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek22

Multi-texture• Using hardwareUsing hardware to combine a number of texture maps simultaneously with dynamically to combine a number of texture maps simultaneously with dynamically

changing mapschanging maps

– Texture map static, light map changed by light motion, fog map changed by camera motionTexture map static, light map changed by light motion, fog map changed by camera motion

• Implemented in hardware for OpenGL graphics cardsImplemented in hardware for OpenGL graphics cards

• Using hardwareUsing hardware to combine a number of texture maps simultaneously with dynamically to combine a number of texture maps simultaneously with dynamically changing mapschanging maps

– Texture map static, light map changed by light motion, fog map changed by camera motionTexture map static, light map changed by light motion, fog map changed by camera motion

• Implemented in hardware for OpenGL graphics cardsImplemented in hardware for OpenGL graphics cards

texturemap

lightmap

fogmap

mappingH/W

mappingH/W

mappingH/W

no-textureimage

framebuffer

Page 23: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek23

Multi-texture example:Detail modulation

original image

grain image

Page 24: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek24

Detail modulated image

Page 25: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek25

Example of Multi-texture:view-dependent light maps• Light maps are usually for view independent (diffuse) Light maps are usually for view independent (diffuse)

light – slowly changing: low frequencylight – slowly changing: low frequency

• Calculate number of high-frequency light maps Calculate number of high-frequency light maps corresponding to different view directionscorresponding to different view directions

• At runtime, blend between the different high-At runtime, blend between the different high-frequency light maps based on current view-direction frequency light maps based on current view-direction using multi-textureusing multi-texture

• Similar effect as bump mappingSimilar effect as bump mapping

• Light maps are usually for view independent (diffuse) Light maps are usually for view independent (diffuse) light – slowly changing: low frequencylight – slowly changing: low frequency

• Calculate number of high-frequency light maps Calculate number of high-frequency light maps corresponding to different view directionscorresponding to different view directions

• At runtime, blend between the different high-At runtime, blend between the different high-frequency light maps based on current view-direction frequency light maps based on current view-direction using multi-textureusing multi-texture

• Similar effect as bump mappingSimilar effect as bump mapping

Page 26: Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.

© 2002 James K. Hahn, N.H. Baek26

Complete Light Model• Routine rendering implemented entirely as set of Routine rendering implemented entirely as set of

map blending operationsmap blending operations

• General light equationGeneral light equation

– C = fog * (texture map * light mapC = fog * (texture map * light map+ specular map+ specular map+ environment map)+ environment map)

• Routine rendering implemented entirely as set of Routine rendering implemented entirely as set of map blending operationsmap blending operations

• General light equationGeneral light equation

– C = fog * (texture map * light mapC = fog * (texture map * light map+ specular map+ specular map+ environment map)+ environment map)