GPGPU labor IV. Scatter és gather. Kezdeti teendők Tantárgy honlapja, Scatter és gather A labor kiindulási alapjának letöltése (lab4_base.zip), kitömörítés.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Presented by: Stacy C. Lovell. How do we perceive color? Our eyes contain only 3 types of photosentitive cells tuned to three frequencies Red, Green,
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Hardware Virtual Texturing
POST-PROCESSING SET09115 Intro Graphics Programming.
GPGPU labor IV. Scatter és gather. Kezdeti teendők Tantárgy honlapja, Scatter és gather A labor kiindulási alapjának letöltése (lab4_base.zip), kitömörítés.
GPGPU labor XIII. Folyadék szimuláció. Kezdeti teendők Tantárgy honlapja, Folyadék szimuláció A labor kiindulási alapjának letöltése (lab13_base.zip),
GPGPU labor VI. Rekurzív algoritmusok labirintus.
GPGPU labor VIII. OpenCL bevezetés. Kezdeti teendők Tantárgy honlapja, OpenCL bevezetés II. A labor kiindulási alapjának letöltése (lab8_base.zip), kitömörítés.
GPGPU labor XI. Monte Carlo szimuláció. Kezdeti teendők Tantárgy honlapja, Monte Carlo szimuláció A labor kiindulási alapjának letöltése (lab11_base.zip),
Week 4 Lecture 1: OpenGL 3.x & 4.x. 2 Objectives Changes in OpenGL 3.x 4.x Changes in GLSL 1.3/4/5 4.x.
Vertex Buffer Objects, Vertex Array Objects, Pixel Buffer Objects.
Procedural Textures. Noise in glman  glman automatically creates 2D and 3D textures (with default sizes 64x64 and 64x64x64) named  Noise2  Noise3 
© Copyright Khronos Group, Page 1 COLLADA FX Update and FX Composer 2.0 Daniel Horowitz & Ignacio Castaño.
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
CCSprite *sprite = [CCSprite [sprite runAction: [CCRepeatForever actionWithAction: [CCSequence actions: [CCEaseIn.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
Functions Prototypes, parameter passing, return values, activation frams.
EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 2: Shader Fundamentals (continued)
Frame Buffer Postprocessing Effects in DOUBLE-S.T.E.A.L (Wreckless)
The Buffers and Operations
OpenGL Fragment Operations
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
University of Sulaimani - School of Science - Computer Dept.
GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State.
Optimized Effects for Mobile Devices Ed Plowman, Director of Performance Analysis, ARM Stacy Smith, Senior Software Engineer, ARM.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Fast GPU Histogram Analysis for Scene Post- Processing Andy Luedke Halo Development Team Microsoft Game Studios.
GLSL Applications: 1 of 2 Joseph Kider Source: Patrick Cozzi – Spring 2011 University of Pennsylvania CIS Fall 2011.
Skin Rendering GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from David Gosselin’s Power Point and article, Real-time skin rendering,
Mapping Computational Concepts to GPU’s Jesper Mosegaard Based primarily on SIGGRAPH 2004 GPGPU COURSE and Visualization 2004 Course.
Image Processing.  a typical image is simply a 2D array of color or gray values  i.e., a texture  image processing takes as input an image and outputs.
Queensland University of Technology CRICOS No J INB382/INN382 Real-Time Rendering Techniques Lecture 13: Revision Ross Brown.
Geometry Shaders. Visualizing Normal Vectors  textbook calls this a “hedgehog plot” but (I think) that this is a misuse of the term  a hedgehog plot.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
UniS CS293 Graphics with Java and OpenGL Textures.
Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.
Geometric Objects and Transformations. Coordinate systems rial.html.
GPU Computation Strategies & Tricks Ian Buck Stanford University.
Interactive Time-Dependent Tone Mapping Using Programmable Graphics Hardware Nolan GoodnightGreg HumphreysCliff WoolleyRui Wang University of Virginia.
Tone Mapping on GPUs Cliff Woolley University of Virginia Slides courtesy Nolan Goodnight.
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
Cel shading By jared brock.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
Geometry processing on GPUs Jens Krüger Technische Universität München.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Realishtime Radiosity And Next Shooter Selection Jeff Pool COMP 870 Final December 4, 2008 UNC Dept. of Computer Science.
GPGPU: Parallel Reduction and Scan Joseph Kider University of Pennsylvania CIS Fall 2011 Credit: Patrick Cozzi, Mark Harris Suresh Venkatensuramenan.
CDS 301 Fall, 2008 From Graphics to Visualization Chap. 2 Sep. 3, 2009 Jie Zhang Copyright ©
User-Defined Functions (cont’d) - Reference Parameters.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CS 4722 Made by Dr. Jeffrey Chastine Modified by Dr. Chao Mei
Reflective Shadow Mapping By: Mitchell Allen.
Computer Graphics Lecture 33
Introduction to Computer Graphics with WebGL
Introduction to Programmable Hardware
GPGPU: Parallel Reduction and Scan
Java Lesson 36 Mr. Kalmes.
CS 1430: Programming in C++.
Introduction to Computer Graphics with WebGL
Chapter X Output Merger.
Digital Image Synthesis Yung-Yu Chuang 11/8/2007
Frame Buffers Fall 2018 CS480/680.
Presentation transcript:

GPGPU labor IV. Scatter és gather

Kezdeti teendők Tantárgy honlapja, Scatter és gather A labor kiindulási alapjának letöltése (lab4_base.zip), kitömörítés a GPGPU\Labs könyvtárba

Hisztogram Szükséges osztálypéldányok: Quad* fullscreenQuad = new Quad(); Shader* histogramShader = new Shader("histogram.vert", "histogram.frag"); Shader* visualizeShader = new Shader("passthrough.vert", "visualize.frag"); Texture2D* texture = new Texture2D(); texture->loadFromFile(std::string("lena.jpg")); int windowWidth = texture->getWidth(); int windowHeight = texture->getHeight(); PointGrid* grid = new PointGrid(texture->getWidth(), texture->getHeight()); Framebuffer* histogramBuffer = new Framebuffer(255, 1, 1);

Hisztogram // TODO // // histogramBuffer->clear // // Setup the blending stage // glEnable(GL_BLEND) // glBlendEquation(GL_FUNC_ADD) // glBlendFunc(GL_ONE, GL_ONE) // // render target := histogramBuffer // inputBuffer := texture->getTextureHandle() // grid->render // disable histogramShader // disable histogramBuffer // glDisable(GL_BLEND); // void histogram(){ // Your code here! // … }

Hisztogram visszaolvasása glFinish(); float histogram[255] = {0.0f}; glBindFramebuffer(GL_FRAMEBUFFER, histogramBuffer->getHandle()); glReadBuffer(GL_COLOR_ATTACHMENT0); glReadPixels(0, 0, 255, 1, GL_RED, GL_FLOAT, histogram); glBindFramebuffer(GL_FRAMEBUFFER, 0); std::cout << "Histogram:\n " << std::endl; int maxValue = 0; for(int i = 0; i < 255; ++i){ maxValue = maxValue > histogram[i] ? maxValue : histogram[i]; std::cout << i << " : " << histogram[i] << std::endl; } std::cout << " \nMaximum: " << maxValue << std::endl;

histogram.vert #version 130 uniform sampler2D inputBuffer; in vec4 position; out vec4 color; float I (vec2 coord){ vec4 color = texture(inputBuffer, coord); return(dot(color.rgb, vec3(0.21, 0.39, 0.4))); } // TODO // // luminance := I(vertex position) // gl_Position := histogram[bucket] // color := 1 void main(void){ }

histogram.frag #version 130 out vec4 outColor; void main(){ outColor = vec4(1.0); }

passthrough.vert #version 130 in vec4 position; in vec2 texCoord; out vec2 fTexCoord; void main(void){ gl_Position = position; fTexCoord = texCoord; }

visualize.frag #version 130 uniform sampler2D inputBuffer; uniform sampler2D original; uniform int maxValue; in vec2 fTexCoord; out vec4 outColor; float I (vec2 coord){ vec4 color = texture(original, coord); return(dot(color.rgb, vec3(0.21, 0.39, 0.4))); } void main() { float data = texture(inputBuffer, fTexCoord).x; if(data / float(maxValue) > fTexCoord.y){ outColor = vec4(0.5f + 0.5f * I(fTexCoord)); } else { outColor = vec4(I(fTexCoord)); }

Próba

Kvantálás Szükséges osztálypéldányok: Shader* quantizeShader = new Shader("passthrough.vert", "quantize.frag"); Framebuffer* quantizedBuffer = new Framebuffer(texture->getWidth(), texture->getHeight(), 1);

Kvantálás int levels = 16; // TODO // // render target := quantizedBuffer // quantizeShader shader parameters: //inputBuffer := texture->getTextureHandle() // levels := levels // render fullscreen quad // disable shader // disable render target void quantizeAndHistogram(){ // Your code // }

quantize.frag #version 130 uniform sampler2D inputBuffer; uniform int levels; in vec2 fTexCoord; out vec4 outColor; float I (vec2 coord){ vec4 color = texture(inputBuffer, coord); return(dot(color.rgb, vec3(0.21, 0.39, 0.4))); } // TODO // // data := I(sample_position) // bin := nearest_histogram_bin(data) // outColor := bin void main(){ }

Próba

Hisztogram kiegyenlítés Szükséges osztálypéldányok: Framebuffer* U_histogramBuffer = NULL; Framebuffer* U_cumulatedHistogramBuffer[2] = {NULL}; Framebuffer* U_equalizedBuffer = NULL; Shader* computeHistogram = NULL; Shader* computeCumulativeHistogram = NULL; Shader* computeEqualizedHistogram = NULL; Shader* histogramShader = NULL; Shader* visualizeShader = NULL; const int histogramLevels = 256;

Hisztogram kiegyenlítés // TODO // // Generate histogram: //histogramBuffer->clear // //Setup the blending stage //glEnable(GL_BLEND) //glBlendEquation(GL_FUNC_ADD) //glBlendFunc(GL_ONE, GL_ONE) // //render target := histogramBuffer //histogramShader parameters: //inputBuffer := texture->getTextureHandle() //incr := 1.0 //histogramLevels := histogramLevels //grid->render //disable histogramShader //disable histogramBuffer //glDisable(GL_BLEND); void histogramEqualization(){... }

Hisztogram kiegyenlítés // TODO // // Compute cumulative histogram // // offset := 1 / histogramLevels // LOOP I = 0.. log2(histogramLevels): // render target := U_cumulatedHistogramBuffer[(inputBuffer + 1) % 2] // computeCumulativeHistogram shader parameters: //inputMap := (I == 0) ? U_histogramBuffer->getColorBuffer(0) : // U_cumulatedHistogramBuffer[inputBuffer]->getColorBuffer(0) //offset := -offset //render fullscreenQuad // disable shader // disable render target // inputBuffer = (inputBuffer + 1) % 2; // offset := 2 * offset void histogramEqualization(){... }

Hisztogram kiegyenlítés // TODO // // Histogram equalization // // clear U_equalizedBuffer // render target := U_equalizedBuffer // computeEqualizedHistogram shader parameters: //inputMap := texture->getTextureHandle() // histogram := U_cumulatedHistogramBuffer[inputBuffer]->getColorBuffer(0) // level := (texture->getWidth() * texture->getHeight() / (histogramLevels / 8)) // numLevel := histogramLevels / 8 // render fullscreen quad // disable shader // disable render target void histogramEqualization(){... }

computeCumulativeHistogram.frag #version 130 uniform sampler2D inputMap; uniform float offset; in vec2 fTexCoord; out vec4 outColor; // TODO // // outColor = texture(samplePos) + texture(samplePos + offset) void main(void){ }

computeCumulative Histogram.frag #version 130 uniform sampler2D inputMap; uniform sampler2D histogram; in vec2 fTexCoord; out vec4 outColor; float I (vec2 coord){ vec4 color = texture(inputMap, coord); return(dot(color.rgb, vec3(0.21, 0.39, 0.4))); } void main(void){ vec2 size = textureSize(inputMap, 0); float current = I(fTexCoord); float accum = texture(histogram, vec2(current, 0.0)).x; float bin = accum / size.x / size.y; outColor = vec4(bin) ; }

Próba

Summed Area Table Szükséges osztálypéldányok: Shader* satXShader; Shader* satYShader; Shader* satVisShader; Framebuffer* satBuffer[2];

Summed Area Table // TODO // // offset := 1 / texture->getWidth() // passes := ceil(log(texture->getWidth)/log(2.0)) // LOOP I = 0.. passes: // SatXPass // SatYPass // offset := 2 * offset // // SatXPass: // render target := satBuffer[(inputBuffer + 1) % 2 ] // satXShader shader parameters: // inputMap := (I == 0) ? texture->getTextureHandle() : // satBuffer[inputBuffer]->getColorBuffer(0) // offset := -offset // render fullscreen quad // disable shader // disable render target // inputBuffer := (inputBuffer + 1) % 2 void sat(){... }

satx.frag #version 130 uniform sampler2D inputMap; uniform float offset; in vec2 fTexCoord; out vec4 outColor; // TODO // // outColor = texture(samplePos) + texture(samplePos + offset) void main(void){ }

saty.frag #version 130 uniform sampler2D inputMap; uniform float offset; in vec2 fTexCoord; out vec4 outColor; // TODO // // outColor = texture(samplePos) + texture(samplePos + offset) void main(void){ }

Tone Mapping Szükséges osztálypéldányok: Texture2D* hdrTexture; Framebuffer* satHDRBuffer[2] = {NULL, NULL}; Framebuffer* hdrLumBuffer = NULL; Framebuffer* hdrRelLumBuffer = NULL; Shader* hdrLuminanceShader = NULL; Shader* hdrSatXShader = NULL; Shader* hdrSatYShader = NULL; Shader* hdrRelLumShader = NULL; Shader* hdrToneMapShader = NULL; float W = 0.9f; float alpha = 0.5f;

Tone Mapping satHDRBuffer[0] = new Framebuffer(hdrTexture->getWidth(), hdrTexture->getHeight(), 1); satHDRBuffer[1] = new Framebuffer(hdrTexture->getWidth(), hdrTexture->getHeight(), 1); hdrLumBuffer = new Framebuffer(hdrTexture->getWidth(), hdrTexture->getHeight(), 1); hdrRelLumBuffer = new Framebuffer(hdrTexture->getWidth(), hdrTexture->getHeight(), 1); hdrSatXShader = new Shader("passthrough.vert", "satx.frag"); hdrSatYShader = new Shader("passthrough.vert", "saty.frag"); hdrToneMapShader = new Shader("passthrough.vert", "tonemap.frag"); hdrLuminanceShader = new Shader("passthrough.vert", "luminance.frag"); hdrRelLumShader = new Shader("passthrough.vert", "rellum.frag"); hdrTexture = new Texture2D(); hdrTexture->loadFromFile(std::string("free_005.hdr"));

Tone Mapping void toneMap(){ // generate luminance hdrLumBuffer->clear(); hdrLumBuffer->setRenderTarget(); hdrLuminanceShader->enable(); hdrLuminanceShader->bindUniformTexture("hdr", hdrTexture->getTextureHandle(), 0); fullscreenQuad->render(hdrLuminanceShader); hdrLuminanceShader->disable(); hdrLumBuffer->disableRenderTarget();

Tone Mapping // generate SAT float offset = 1.0f / (float)hdrTexture->getWidth(); int passes = ceil(log(hdrTexture->getWidth()) / log(2)); int inputBuffer = 0; for(int i = 0; i < passes; ++i){ satHDRBuffer[(inputBuffer + 1) % 2 ]->setRenderTarget(); hdrSatXShader->enable(); hdrSatXShader->bindUniformTexture("inputMap", i == 0 ? hdrLumBuffer->getColorBuffer(0) : satHDRBuffer[inputBuffer]->getColorBuffer(0), 0); hdrSatXShader->bindUniformFloat("offset", -offset); fullscreenQuad->render(hdrSatXShader); hdrSatXShader->disable(); satHDRBuffer[(inputBuffer + 1) % 2 ]->disableRenderTarget(); inputBuffer = (inputBuffer + 1) % 2; satHDRBuffer[(inputBuffer + 1) % 2 ]->setRenderTarget(); hdrSatYShader->enable(); hdrSatYShader->bindUniformTexture("inputMap", satHDRBuffer[inputBuffer]->getColorBuffer(0), 0); hdrSatYShader->bindUniformFloat("offset", -offset); fullscreenQuad->render(hdrSatYShader); hdrSatYShader->disable(); satHDRBuffer[(inputBuffer + 1) % 2 ]->disableRenderTarget(); inputBuffer = (inputBuffer + 1) % 2; offset *= 2.0f; }

Tone Mapping hdrRelLumBuffer->clear(); hdrRelLumBuffer->setRenderTarget(); hdrRelLumShader->enable(); hdrRelLumShader->bindUniformTexture("luminanceMap", hdrLumBuffer->getColorBuffer(0), 0); hdrRelLumShader->bindUniformTexture("sat", satHDRBuffer[inputBuffer]->getColorBuffer(0), 1); hdrRelLumShader->bindUniformFloat("alpha", alpha); fullscreenQuad->render(hdrRelLumShader); hdrRelLumShader->disable(); hdrRelLumBuffer->disableRenderTarget();

Tone Mapping hdrToneMapShader->enable(); hdrToneMapShader->bindUniformTexture("hdr", hdrTexture->getTextureHandle(), 0); hdrToneMapShader- >bindUniformTexture("rellum", hdrRelLumBuffer- >getColorBuffer(0), 1); hdrToneMapShader->bindUniformFloat("W", W); fullscreenQuad->render(hdrToneMapShader); hdrToneMapShader->disable();}

luminance.frag #version 130 uniform sampler2D hdr; in vec2 fTexCoord; out vec4 outColor; void main(void){ vec4 color = texture(hdr, fTexCoord); outColor = vec4(color.r * , color.g * , color.b * , 1.0); }

satX.frag #version 130 uniform sampler2D inputMap; uniform float offset; in vec2 fTexCoord; out vec4 outColor; void main(void){ float c = texture(inputMap, fTexCoord).r; vec2 sampleOff = fTexCoord + vec2(offset, 0); float addValue = 0.0f; if(sampleOff.x >= 0.0){ addValue = texture(inputMap, sampleOff).r; } outColor = vec4(c + addValue); }

satY.frag #version 130 uniform sampler2D inputMap; uniform float offset; in vec2 fTexCoord; out vec4 outColor; void main(void){ float c = texture(inputMap, fTexCoord).r; vec2 sampleOff = fTexCoord + vec2(0.0, offset); float addValue = 0.0f; if(sampleOff.y >= 0.0){ addValue = texture(inputMap, sampleOff).r; } outColor = vec4(c + addValue); }

rellum.frag #version 130 uniform sampler2D luminanceMap; uniform sampler2D sat; uniform float alpha; in vec2 fTexCoord; out vec4 outColor; void main(void){ vec2 mapSize = textureSize(sat, 0); float avg = texture(sat, vec2(1.0, 1.0)).r / mapSize.x / mapSize.y; outColor = alpha * texture(luminanceMap, fTexCoord) / avg; }

tonemap.frag #version 130 uniform sampler2D hdr; uniform sampler2D rellum; uniform float W; in vec2 fTexCoord; out vec4 outColor; void main(void){ float Yr = texture(rellum, fTexCoord).x / ; vec4 hdrColor = texture(hdr, fTexCoord); outColor = hdrColor * ( Yr * ( 1 + Yr / W / W) / (1 + Yr) ); }

Próba

VÉGE