The Graphics Pipeline and OpenGL IV: Stereo Rendering, Depth of Field Rendering, Multi-pass Rendering!

Similar documents
Head Mounted Display Optics I!

The Graphics Pipeline and OpenGL I: Transformations!

The Graphics Pipeline and OpenGL I: Transformations!

ENGINEERING Electrical Engineering

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Sign up for crits! Announcments

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Overview. By end of the week:

Computer graphics 2: Graduate seminar in computational aesthetics

Rendering Objects. Need to transform all geometry then

Rasterization Overview

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

OPENGL RENDERING PIPELINE

CS 563 Advanced Topics in Computer Graphics Stereoscopy. by Sam Song

SUMMARY. CS380: Introduction to Computer Graphics Projection Chapter 10. Min H. Kim KAIST School of Computing 18/04/12. Smooth Interpolation

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Virtual Cameras and The Transformation Pipeline

3D in 3D: Rendering anaglyph stereographics in real-time. Bruce Oberg, Programming Lead. Sucker Punch Productions

Realtime 3D Computer Graphics Virtual Reality

TSBK03 Screen-Space Ambient Occlusion

Ciril Bohak. - INTRODUCTION TO WEBGL

The Graphics Pipeline

Models and Architectures

Scanline Rendering 2 1/42

CS 464 Review. Review of Computer Graphics for Final Exam

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Overview. By end of the week:

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Shaders. Slide credit to Prof. Zwicker

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Devices displaying 3D image. RNDr. Róbert Bohdal, PhD.

Stereographics. Mike Bailey. Stereovision is not new It s been in common use in the movies since the 1950s

Stereographics. Mike Bailey. Computer Graphics stereographics.pptx

Stereographics. Mike Bailey. Oregon State University. Oregon State University Computer Graphics mjb January 27, 2011

Stereographics. Stereovision is not new It s been in common use in the movies since the 1950s. And, in stills, even longer than that.

CS451Real-time Rendering Pipeline

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Introduction to Computer Graphics with WebGL

zspace Developer SDK Guide - Introduction Version 1.0 Rev 1.0

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

CSE 167: Introduction to Computer Graphics Lecture #9: Visibility. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Advanced Deferred Rendering Techniques. NCCA, Thesis Portfolio Peter Smith

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

Computer Graphics - Treasure Hunter

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Computer Graphics with OpenGL ES (J. Han) Chapter VII Rasterizer

Game Graphics & Real-time Rendering

Vincent Nozick. Graduate School of Science and Technology, Keio University, Japan.

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

Vincent Nozick. Graduate School of Science and Technology, Université Paris Est LABINFO IGM UMR CNRS Keio University, Japan

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CS559 Computer Graphics Fall 2015

Lecture 4. Viewing, Projection and Viewport Transformations

Assignment 1 due 4/13/2017 at 11:59PM Topic: Getting Started with WebGL and Transformations

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

Projection Matrix Tricks. Eric Lengyel

Simple, Low-Cost Stereographics: VR for Everyone

Smoothing Region Boundaries in Variable Depth Mapping for Real Time Stereoscopic Images

Homework 1: Getting Started with WebGL and Transformations EE267 Virtual Reality 2018

Virtual Cameras & Their Matrices

Computergrafik. Matthias Zwicker. Herbst 2010

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

CS452/552; EE465/505. Intro to Lighting

CS4620/5620: Lecture 14 Pipeline

BCA611 Video Oyunları için 3B Grafik

GPU rendering for autostereoscopic displays

Recall: Indexing into Cube Map

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Deferred Rendering Due: Wednesday November 15 at 10pm

Overview of Projections: From a 3D world to a 2D screen.

Lecture 2. Shaders, GLSL and GPGPU

CS 112 The Rendering Pipeline. Slide 1

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

CS 4620 Program 3: Pipeline

Transforms 3: Projection Christian Miller CS Fall 2011

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

The Projection Matrix

VGP353 Week 2. Agenda: Assignment #1 due Introduce shadow maps. Differences / similarities with shadow textures Added benefits Potential problems

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Computer Graphics Shadow Algorithms

The Rasterization Pipeline

Texture. Texture Mapping. Texture Mapping. CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

CS 475 / CS 675 Computer Graphics. Lecture 11 : Texture

VGP352 Week March-2008

Transcription:

! The Graphics Pipeline and OpenGL IV: Stereo Rendering, Depth of Field Rendering, Multi-pass Rendering! Gordon Wetzstein! Stanford University! EE 267 Virtual Reality! Lecture 6! stanford.edu/class/ee267/!!

Lecture Overview! overview of glasses-based stereo! stereo rendering with OpenGL! projection matrix! view matrix! offscreen frame buffers and multi-render passes! anaglyph stereo rendering with GLSL! depth of field rendering!

Glasses-based Stereo! 1. Anaglyph! 2. Polarization! 3. Shutter Glasses! 4. Chromatic Filters (e.g., Dolby)!

Glasses-based Stereo! 1. Anaglyph! 2. Polarization! 3. Shutter Glasses! 4. Chromatic Filters (Dolby)!

Glasses-based Stereo! passive glasses! 1. Anaglyph! active LC element on projector or interlaced rows/columns on monitor (resolution loss)! 2. Polarization! e.g. RealD most 3D cinemas use this! circular polarization to allow for head roll! inexpensive glasses, little crosstalk! 4. Chromatic Filters (Dolby)! need polarization-preserving screen!! 3. Shutter Glasses!

Glasses-based Stereo! 1. Anaglyph! 2. Polarization! 3. Shutter Glasses! 4. Chromatic Filters (Dolby)!

Glasses-based Stereo! active glasses, temporally-multiplexed display! e.g. StereoGraphics! 1. Anaglyph! somewhat expensive glasses, little crosstalk! need fast display (at least 120 Hz)! sync monitor update with glasses! 2. Polarization! 3. Shutter Glasses! 4. Chromatic Filters (Dolby)!

Glasses-based Stereo! 4. Chromatic Filters (e.g., Dolby)!

Glasses-based Stereo! passive glasses, usually two projectors with passive color filters! somewhat expensive glasses (not as widespread in cinemas)! full color!! www.shortcourses.com/stereo/stereo1-12.html! 4. Chromatic Filters (e.g., Dolby)!

Glasses-based Stereo! 1. Anaglyph! 2. Polarization! 3. Shutter Glasses! 4. Chromatic Filters (Dolby)!

Glasses-based Stereo! 1. Anaglyph! 2. Polarization! passive, inexpensive glasses (least expensive overall)! no modifications to display necessary just render stereo images in different colors! 3. Shutter Glasses! cannot reproduce correct colors! but not as bad as it sounds! 4. Chromatic Filters (Dolby)!

2. Polarization! Put on Your 3D Glasses Now!! 3. Shutter Glasses! 4. Chromatic Filters (Dolby)!

pintrest.com! Glasses-based Stereo!

Anaglyph Stereo - Monochrome! render L & R images, convert to grayscale! merge into red-cyan anaglyph by assigning I(r)=L, I(g,b)=R (I is anaglyph)! from movie Bick Buck Bunny!

Anaglyph Stereo Full Color! render L & R images, do not convert to grayscale! merge into red-cyan anaglyph by assigning I(r)=L(r), I(g,b)=R(g,b) (I is anaglyph)! from movie Bick Buck Bunny!

Anaglyph Stereo - Dubois! paper: Eric Dubois A Projection Method to Generate Anaglyph Stereo Images, ICASSP 2001! optimize color management in CIE XYZ space! requires spectral transmission of glasses & spectral emission curves of display primaries! great course project - see last year s projects!

Open Source Movie: Big Buck Bunny!! Rendered with Blender (Open Source 3D Modeling Program)! http://bbb3d.renderfarming.net/download.html!

Glasses-based Stereo!

Glasses-based Stereo! Anaglyph Comparison!!! show video clips!

Parallax! http://paulbourke.net/stereographics/stereorender/! parallax is the relative distance of a 3D point projected into the 2 stereo images! case 1! case 2! case 3!

Parallax! http://paulbourke.net/stereographics/stereorender/! visual system only uses horizontal parallax, no vertical parallax!! naïve toe-in method creates vertical parallax à visual discomfort! Toe-in = incorrect! Off-axis = correct!!

Parallax well done!

Parallax well done! 1862! Tending wounded Union soldiers at Savage's Station, Virginia, during the Peninsular Campaign,! Library of Congress Prints and Photographs Division!!

Parallax not well done (vertical parallax = unnatural)!

2. Polarization! Take Off Your 3D Glasses Now! 3. Shutter Glasses! 4. Chromatic Filters (Dolby)!

Stereo Rendering with OpenGL/WebGL: View Matrix! need to modify view matrix and projection matrix! rendering pipeline does not change only those two matrices! however: need to render two images in sequence (more details later)! look at view matrix first: THREE.Matrix4().lookAt(eye,center,up)! function is as useful as it has been, just need to adjust parameters!

Important Numbers! monitor width & height x z world origin is in the center of the physical monitor!! IPD! d IPD! d interpupillary distance! distance to monitor!

Stereo Rendering with OpenGL: View Matrix! x z

Stereo Rendering with OpenGL: View Matrix! center points for lookat!

Stereo Rendering with OpenGL: View Matrix! lookat( vec3(ipd/2,0,d),! vec3(ipd/2,0,0), vec3(0,1,0) );! lookat( vec3(-ipd/2,0,d),! vec3(-ipd/2,0,0), vec3(0,1,0) );!

! Stereo Rendering with OpenGL: Projection Matrix! perspective projection we have discussed so far is on-axis=symmetric! we need a different way to set up the asymmetric, off-axis frustum! use THREE.Matrix4().makePerspective(left,right,top,bottom,znear,zfar) http://paulbourke.net/stereographics/stereorender/!

monitor! On-axis Frustum! view frustum symmetric! h y z d Side View!

monitor! On-axis Frustum! y view frustum symmetric! near clipping plane! z near h z d Side View!

monitor! On-axis Frustum! h y z view frustum symmetric! top! bottom! near clipping plane! z near d Side View!

monitor! On-axis Frustum! h similar triangles:! top = z near bottom = z near h 2d h 2d view frustum symmetric! top! bottom! near clipping plane! z near d Side View!

monitor! Off-axis Frustum! w x z view frustum asymmetric! near clipping plane! z near ipd/2! d Top View!

virtual image! Off-axis Frustum! w x z view frustum asymmetric! right! near clipping plane! z near ipd/2! left! d Top View!

virtual image! Off-axis Frustum! w similar triangles:! right = z near w + ipd 2d view frustum asymmetric! right! near clipping plane! z near ipd/2! left = z near w ipd 2d d left! Top View!

virtual image! Off-axis Frustum! view frustum asymmetric! similar triangles:! w right = z near w ipd 2d right! left! z near left = z near w + ipd 2d d Top View!

Anaglyph with OpenGL!!!! most efficient way: 1. clear color and depth buffer! 2. set left modelview and project matrix, render scene only into red channel 3. clear depth buffer! 4. set right modelview and project matrix, render scene only into green & blue channels we ll do it in a slightly more complicated way (need for other tasks anyway):! multiple render passes! render into offscreen (frame) buffers!

OpenGL Frame Buffers! usually (frame) buffers are provided by the window manager (i.e., your browser)! for most mono applications, two (double) buffers: back buffer and front buffer! à render into back buffer; swap buffers when done (WebGL does this for you!)! advantage: rendering takes time, you don t want the user to see how triangles get drawn onto the screen; only show final image! in many stereo applications, 4 (quad) buffers: front/back left and right buffer! render left and right images into back buffers, then swap both together!

OpenGL Frame Buffers! more generic model: offscreen buffer! most common form of offscreen buffer in OpenGL: framebuffer object! concept of render-to-texture but with multiple attachments for color, depth, and other important per-fragment information! as many framebuffer objects as desired, they all live on the GPU (no memory transfer)! bit depth per color: 8 bits, 16 bits, 32 bits for color attachments; 24 bits for depth!

OpenGL Frame Buffers! FrameBuffer Object (FBO)! render! color attachment 0! texture! render into FBO as usual, just enable/ disable the FBO! color attachment 1!! color attachment n! texture! texture! access content by texture ID (e.g. in GLSL shader)! depth attachment! stencil attachment! texture! texture!

OpenGL Frame Buffers! FBOs are crucial for multiple render passes!! 1 st pass: render color and depth into FBO! 2 nd pass: render textured rectangle access FBO in fragment shader! we ll provide a simple-to-use interface that shields you from the details of FBOs! in JavaScript FBOs are wrapped by WebGLRenderTarget in Three.js! more details in lab / homework starter code on Friday!

Anaglyph Rendering with OpenGL & GLSL! 1. activate FBO1! 2. set left modelview & projection matrix! 3. render scene! 4. deactivate FBO1! 5. activate FBO2! 6. set right modelview & projection matrix! 7. render scene! 8. deactivate FBO2! 9. render rectangle, pass FBO1 and FBO2 into fragment shader as textures! 10. merge stereo images in fragment shader! render pass 1! render pass 2! render pass 3!

Retinal Blur / Depth of Field Rendering! aperture controls amount of light! accommodation distance!

Retinal Blur / Depth of Field Rendering! aperture controls amount of light! accommodation distance!

Retinal Blur / Depth of Field Rendering! out of focus blur! retinal blur! accommodation distance!

Retinal Blur / Depth of Field Rendering! out of focus blur! retinal blur! accommodation distance!

Retinal Blur / Depth of Field Rendering! c = M D S S 1 f S M = S 1 f accommodation distance: S 1! f = 17mm D! retinal blur diameter c! S!

Circle of Confusion! c = M D S S 1 S circle of confusion in m! accommodation distance! distance to eye in m!

Retinal Blur / Depth of Field Rendering! depth of field blur on screen (in mm) via similar triangles:! b = S S 1 D S D! b accommodation dist = dist to screen: S 1! S!

Depth of Field with OpenGL/GLSL! two rendering passes:! 1. render image and depth map into FBO! 2. render quad textured with image + depth! vertex shader is pass-through (just transforms, pass on texture coordinates, no lighting)! in fragment shader:! calculate depth for each fragment in mm (given in clip coords)! calculate retinal blur size in pixels given depth & pupil diameter! apply blur via convolution with double for loop over neighboring color values in the texture!

Depth of Field with OpenGL/GLSL! how to get metric depth of a fragment?! in fragment shader we provide depth map z as uniform texture (range [0,1])! get normalized device coordinates, i.e. z NDC =2*z-1 in [-1,1]! now undo perspective projection to get z in view coordinates:! x NDC y NDC = z NDC 1!# " $# v NDC x clip / w clip y clip / w clip z clip / w clip 1 x clip x x view y clip y z = M proj M view M model = M proj y view clip z z view w clip 1!"$ 1!# " $#!# " $# v clip v v view

Depth of Field with OpenGL/GLSL! how to get metric depth of a fragment?! M proj = 2n r + l 0 r l r l 2n t + b 0 t b t b 0 0 f + n f n 0 0 2 f n f n 0 0 1 0 z clip = f + n f n z view 2 fn f n w clip = z view z view = 2 fn f n 1 z NDC f + n f n x NDC y NDC = z NDC 1!# " $# v NDC x clip / w clip y clip / w clip z clip / w clip 1 x clip x x view y clip y z = M proj M view M model = M proj y view clip z z view w clip 1!"$ 1!# " $#!# " $# v clip v v view

Depth of Field with OpenGL/GLSL! how to compute retinal blur size and convert to pixels?! pixel _ size x/y = screen _ size x/y screen _ resolution x/y screen _ size blur _ diameter _ px = b pixel _ size is either screen width or height (same units as other distances)! b b = S S 1 D S D! screen _ resolution is either number of horizontal pixels or vertical pixels of the screen! S!

Depth of Field with OpenGL/GLSL! 1. activate FBO! 2. set modelview & projection matrix! render pass 1! 3. render 3D scene! 4. deactivate FBO! 5. render rectangle, pass FBO with image & depth map into fragment shader as textures! 6. execute depth of field fragment shader! render pass 2!

Depth of Field with OpenGL/GLSL! putting it all together this is just a general overview, do not use this exact code! uniform sampler2d image; // RGB image was written in the first rendering pass uniform sampler2d depthmap; // depth map was written in the first rendering pass uniform float znear; uniform float zfar; uniform float pupildiameter; varying vec2 texturecoords; void main () // fragment shader { // get fragment z in NDC float zndc = 2*sampler2D( depthmap, texturecoords ).r 1; // get z in view coordinates (metric depth of current fragment) float zview = // compute retinal blur radius in pixels float blurradius = int blurradiusint = round(blurradius); // set output color by averaging neighboring pixels in the color image (i.e., convolution) gl_fragcolor.rgb = 0; for (int i=-blurradiusint; i<blurradiusint; i++) for (int j=-blurradiusint; j<blurradiusint; j++) if (float(i*i+j*j) <= blurradius*blurradius) gl_fragcolor.rgb += texture lookup in neighboring pixels // normalize color }

Depth of Field - Disclaimer! z view does not actually give you the 3D distance from the camera to a vertex! 2 2 2 would need to calculate x view + y view + z view for that! ignore for the purpose of our homework and use z view instead!!

Summary! many different technologies for glasses-based stereo! we ll work with anaglyph for this lab + homework! color management is important for anaglyph! getting the view and projection matrices right is important (otherwise headaches)! may need multiple render passes (all wrapped in the starter code)! depth of field rendering may add more realism!

Next Lecture: HMD Optics and Microdisplays! magnifiers! VR & AR optics! microdisplays! stereo rendering for HMDs! lens distortion / undistortion! drawing from Google Glass patent!

Further Reading! http://paulbourke.net/stereographics/stereorender/! Eric Dubois, A Projection Method to Generate Anaglyph Stereo Images, ICASSP 2001! Library of Congress, Stereoscopic Cards:! http://www.loc.gov/pictures/search/?st=grid&co=stereo!