290 likes | 447 Views
Post-Processing Pipeline GDC March 2nd, 2011 by Michael Alling. Goal. Simulate a real camera for PostFX Real Camera Effects Real Camera Controls Focus Position (Depth of Field) Focal Length (Zoom) ISO Speed Aperture (F-Stop) Shutter Angle (Shutter Speed). Intro to Camera Basics.
E N D
Post-Processing PipelineGDC March 2nd, 2011by Michael Alling
Goal • Simulate a real camera for PostFX • Real Camera Effects • Real Camera Controls • Focus Position (Depth of Field) • Focal Length (Zoom) • ISO Speed • Aperture (F-Stop) • Shutter Angle (Shutter Speed)
Intro to Camera Basics • F-Stop (Aperture) • Determines size of opening in camera • Affects how much light comes in • Affects depth of field • Affects bokeh shape
Intro to Camera Basics • Depth of Field • The area in focus
Intro to Camera Basics • ISO Speed • How fast film reacts to light • More reactive film is noisy • Less reactive film absorbs less light over time • Shutter Speed • Time frame is exposed to light • Focal Length • Distance of one lens from another • Creates zoom • Affects depth of field size • Changing the focus position changes the focal length very slightly
Pipeline • Reduce • Adapt Camera • DOF Blur • Upsample • Final Pass
Reduction • Reduce the scene to a size that will balance performance and quality
Camera Adaptation • Convert reduced texture to log luminance • Reduce to 1x1 and store in a history texture • Average the history
Camera Adaptation • Use this average luminance to calculate the four main variables • Input: ISO Speed, Shutter Speed, Aperture Size, Average Luminance • Output: ISO Speed, Shutter Speed, Aperture Size, Exposure • Aperture^2 / Shutter Speed = Average Luminance * ISO Speed / 12.5 • Try to keep as much of the calculations on the GPU as possible
Depth of Field • Used physically based equations to control DOF blur size • Use the aperture size (from previous pass) and focus position • Blur the reduced buffer based on depth using a 7x7 blur that simulates a circle (bokeh) • Gaussian and box filters do not simulate bokeh [Gotanda] • Upsample the blurred image
Final Pass • Generate blur size and lerp between blurred image and the original image • Resolve MSAA afterward
Camera controls • Use focal length, aperture size, and focus position controls to generate blur size float GetRangeCoefficient( float focalLength, float fStop, float focusDist ){ //http://en.wikipedia.org/wiki/Circle_of_confusion return (focalLength * focalLength) / (fStop * (focusDist – focalLength));}float GetBlurSize( float depth, float focalLength, float fStop, float focusDist, float blurScale ){ //http://en.wikipedia.org/wiki/Circle_of_confusion float factor = abs( depth - focusDist ) / depth; float rangeC = GetRangeCoefficient( focalLength, fStop, focusDist ); float scale = blurScale; float result = abs( scale * factor * rangeC ); //prevents artifacts from the algorithm (you probably don't need) return min( result, 20.0f ); //can't be lower than 0 since abs()}
Focal Length and Focus Distance • Increasing focal length zooms and crunches depth of field (area in focus) • Changing focus distance causes... • Focal length to change slightly which causes fov to change slightly • Depth of field to crunch
Misc • Remember to convert world coordinates into meters or nothing will looked scaled correctly • Can reuse reduced buffer for bloom, scotopic vision, etc. • If tonemapping, remember to tonemap then resolve MSAA [Persson]
References • Useful information: http://en.wikipedia.org/wiki/Circle_of_confusion http://en.wikipedia.org/wiki/Focal_length http://en.wikipedia.org/wiki/Depth_of_field http://en.wikipedia.org/wiki/Aperture http://en.wikipedia.org/wiki/Shutter_angle http://en.wikipedia.org/wiki/Iso_speed http://en.wikipedia.org/wiki/Exposure_value
References [Engel] Wolfgang Engel, "High-Dynamic Range Rendering", http://wiki.gamedev.net/index.php/D3DBook:High-Dynamic_Range_Rendering [Persson] Emil Persson, “Deferred Shading 2”, http://www.humus.name/index.php?page=3D [Gotanda] Yoshiharu Gotanda, "Star Ocean 4: Flexible Shader Management and Post-processing", http://research.tri-ace.com/Data/SO4_flexible_shader_managment_and_postprocessing.ppt