CS 179 GPU Programming

Similar documents
Picking (In WebGL) Picking idea

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Introduction to Computer Graphics with WebGL

CS452/552; EE465/505. Shadow Mapping in WebGL

CS179: GPU Programming

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

Framebuffer Objects. Emil Persson ATI Technologies, Inc.

Mention driver developers in the room. Because of time this will be fairly high level, feel free to come talk to us afterwards

Texturing. Slides done by Tomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

CS 179: GPU Programming

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

CS179 GPU Programming Introduction to CUDA. Lecture originally by Luke Durant and Tamas Szalay

Definition. Blending & Compositing. Front & Back Buffers. Left & Right Buffers. Blending combines geometric objects. e.g.

OpenGL ES for iphone Games. Erik M. Buck

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Superbuffers Workgroup Update. Barthold Lichtenbelt

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

Pixels and Buffers. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CS 432 Interactive Computer Graphics

OpenCL / OpenGL Texture Interoperability: An Image Blurring Case Study

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Lecture 2. Shaders, GLSL and GPGPU

Rationale for Non-Programmable Additions to OpenGL 2.0

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

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

DEFERRED RENDERING STEFAN MÜLLER ARISONA, ETH ZURICH SMA/

Computer Graphics. Bing-Yu Chen National Taiwan University

Rendering Objects. Need to transform all geometry then

Introduction to Shaders.

GLSL Applications: 2 of 2

GPGPU: Parallel Reduction and Scan

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Next-Generation Graphics on Larrabee. Tim Foley Intel Corp

The Graphics Pipeline

OpenGL ES 3.0 and Beyond How To Deliver Desktop Graphics on Mobile Platforms. Chris Kirkpatrick, Jon Kennedy

Working with Metal Overview

December Copyright Khronos Group, Page 1

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

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

Lecture 07: Buffers and Textures

Dave Shreiner, ARM March 2009

OpenGL Über Buffers Extension

Projection Matrix Tricks. Eric Lengyel

Screen Space Ambient Occlusion TSBK03: Advanced Game Programming

CS195V Week 6. Image Samplers and Atomic Operations

Getting fancy with texture mapping (Part 2) CS559 Spring Apr 2017

GPU Memory Model. Adapted from:

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

E.Order of Operations

COMP371 COMPUTER GRAPHICS

More frames per second. Alex Kan and Jean-François Roy GPU Software

Point-Based rendering on GPU hardware. Advanced Computer Graphics 2008

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Sign up for crits! Announcments

Mobile HW and Bandwidth

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

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

OpenGL Status - November 2013 G-Truc Creation

OpenGL on Android. Lecture 7. Android and Low-level Optimizations Summer School. 27 July 2015

OpenGL 3 Overview. Barthold Lichtenbelt, NVIDIA OpenGL ARB Chair. Copyright Khronos Group, Page 1

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

OpenGL Essentials Training

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

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Order Independent Transparency with Dual Depth Peeling. Louis Bavoil, Kevin Myers

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

The Application Stage. The Game Loop, Resource Management and Renderer Design

Lighting and Texturing

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Basic GPU techniques Josef Pelikán CGG MFF UK Praha.

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

CIS 665 GPU Programming and Architecture

Ciril Bohak. - INTRODUCTION TO WEBGL

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

Programming shaders & GPUs Christian Miller CS Fall 2011

INF3320 Computer Graphics and Discrete Geometry

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Graphics Pipeline & APIs

TSBK03 Screen-Space Ambient Occlusion

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

GeForce 8 Features for OpenGL

Bringing AAA graphics to mobile platforms. Niklas Smedberg Senior Engine Programmer, Epic Games

CPSC 436D Video Game Programming

A Shader Library for OpenGL 4 and GLSL 4.3 Learning and Development

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Graphics Processing Unit Architecture (GPU Arch)

Homework 3: Programmable Shaders

CS 5610 / Spring Depth Buffering and Hidden Surface Removal

VGP352 Week 8. Agenda: Post-processing effects. Filter kernels Separable filters Depth of field HDR. 2-March-2010

Introduction to Computer Graphics with WebGL

The GPGPU Programming Model

Performance OpenGL Programming (for whatever reason)

CS770/870 Fall 2015 Advanced GLSL

Mixing graphics and compute with multiple GPUs

Computergraphics Exercise 15/ Shading & Texturing

Transcription:

CS179: GPU Programming Lecture 7: Render to Texture Lecture originally by Luke Durant, Russell McClellan, Tamas Szalay 1

Today: Render to Texture Render to texture in OpenGL Framebuffers and renderbuffers Multi-output rendering Image processing via RTT Reduction 2

How to in OpenGL Always had bad ways of doing it Very basic access to pixel data glreadpixels() Would need to get pixels and then set a texture using glteximage2d() Horribly horribly slow glreadpixels() is completely synchronous Same with glcopyteximage2d() 3

The better way We ve thus far kept textures and buffers separate Both are fundamentally the same thing: image data Textures generic read, buffers function-specific write: Front, back, depth, stencil There should be a way to make more 4

Framebuffer objects (FBOs) Framebuffer objects are groups of renderable buffers Can be associated with existing textures GLuint fbo; glgenframebuffers(1, &fbo); glbindframebuffer(gl_framebuffer, fbo); But what do we draw into? FBOs are just groupings of render targets Nothing to draw into yet 5

Renderbuffers Now we need to create render buffers to actually draw into (for example, a depth buffer) GLuint depthbuffer; glgenrenderbuffers(1, &depthbuffer); glbindrenderbuffer(gl_renderbuffer, depthbuffer); glrenderbufferstorage(gl_renderbuffer, GL_DEPTH_COMPONENT, width, height); And we need to attach it to the FBO (as a depth buffer) glframebufferrenderbuffer(gl_framebuffer, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer); 6

Adding textures Could add color buffers like the depth buffer above But we want to bind existing textures: GLuint img; // is a texture (with associated data!) glframebuffertexture2d(gl_framebuffer, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, img, 0); To check for errors (see docs for error codes) GLenum status = glcheckframebufferstatus(gl_framebuffer); 7

And to render One key step is changing viewport Recall: viewport is NDC -> pixel coordinate transform Texture size will likely differ from window size, so need a different viewport transform Do all this as follows: glbindframebuffer(gl_framebuffer, fbo); glpushattrib(gl_viewport_bit); glviewport(0,0,width, height); // RENDER HERE // Output goes to fbo objects glpopattrib(); glbindframebuffer(gl_framebuffer, 0); Rendered data will now be in textures! 8

Generating more outputs Might want to generate mipmaps after rendering glgeneratemipmap(gl_texture_2d); You may have noticed GL_COLOR_ATTACHMENT0 There can be multiple color buffers, up to 16ish You can specify which ones to draw to using gldrawbuffers GLenum buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; gldrawbuffers(2, buffers); In GLSL: gl_fragcolor is an array gl_fragcolor[i] draws to buffers[i] in current FBO 9

To summarize You can think of all the buffers you have now as one FBO (it is, actually, with ID = 0) A new FBO is just another group of render buffers Render buffers can either be created with new storage or from an existing texture Those textures can then be rendered to 10

Uses of RTT Most things we have talked about (and some we haven t yet) hint at RTT Shadow maps Dynamic environment mapping Image processing General computation Deferred rendering A couple of examples: 11

Portal (environment mapping) 12

Reflection (environment mapping) 13

Deferred rendering 14 Example from Bill Clark s 2010 presentation

Distortion image filter 15

Heat shimmer 16

Image processing Say we want to compute a blur center pixel = average of surrounding pixels But we want to save it instead of displaying it Can we write back into itself? Basically, no source data needs to remain intact, or the result will be wrong Some pixels will be blurred with the result, not the source Solution: use two textures, A and B Read from A, write to B And if you want to iterate filters, go back and forth Called flipping or ping-ponging 17

Image processing Many common algorithms iterated One pixel at a time, but parallelizable Kernel-based algorithms very fast Read from small region near pixel Blur, erode, dilate, edge finding Most have been implemented on GPU How to find minimum or maximum pixels in an image? In fragment shader, want to just compare each fragment to some global value Except all globals are read-only Could always do glreadpixels() and find on CPU An example problem took about 1 second on my computer Not fast enough if you need to do this many times! 18

Ping-ponging reduction Best way: reduction shader Go from texture A -> B, B half the size of A in each dimension For each destination pixel (x, y) in B, set color to be min/max of pixels (2x, 2y), (2x+1, 2y), (2x, 2y+1), and (2x+1, 2y+1) Repeat until result is a 1x1 texture 19

Reduction shader Can read out final result using glreadpixels() The same example took about 10 ms on my computer 100x faster! Need to be extremely careful with texture coordinates, since FragCoords are in pixels but we read using s and t, which are floats FragCoords are also at centers of pixels, so bottom-left pixel is (0.5, 0.5) Can do larger steps than 2x->1x I found ~10x->1x to be most efficient 20

Buffer blending mode Recall the heat shimmer example So far, have used no blending replace current color in buffer with frag color (possibly with depth test) Many more options available: glblendfunc(src, dest); Blending can use some combination of source or destination color or alpha to weight input and output pixels But color clamping still occurs on output pixels! And they get converted to integer RGBA Don t want to do all our processing in range 0 1 21

Floating point buffers Floating point buffers are now supported glteximage2d(gl_texture_2d, 0, GL_RGBA32F, etc.. In documentation, you will often see this and others with ARB or EXT appended ARB means working extension, not mandatory, but will eventually become spec EXT means optional extension Also have vendor specific: NV_POINT_SPRITE, ATI_... glext.h resolves most of these issues, removes ARB if you support it, etc. 22

Color clamping So now have destination color blended and written in floating point, but still clamped Solution: glclampcolor glclampcolorarb(gl_clamp_vertex_color_arb, GL_FALSE); glclampcolorarb(gl_clamp_fragment_color_arb, GL_FALSE); glclampcolorarb(gl_clamp_read_color_arb, GL_FALSE); Now behaves as expected But wait! Are floating point texture accesses clamped? Thankfully, no 23

Performance Floating point textures are slower But there s no way around that, really New hardware will probably help this So avoid when possible or whenever you can store numbers as an integer range 24

Computation on the GPU Now know enough to do general computation Textures effectively represent large arrays Can read from multiple arrays using multiple texture bindings Can write to multiple arrays using multiple render targets Tricky part is breaking up the problem into small parallel pieces Much of the course will be focused on this 25