Solution

Files changed (2) hide show
  1. lab5-rendertotexture/lab5_main.cpp +35 -0
  2. lab5-rendertotexture/postFx.frag +1 -1
lab5-rendertotexture/lab5_main.cpp CHANGED
@@ -38,6 +38,7 @@ bool g_isMouseDragging = false;
38
38
  // Shader programs
39
39
  ///////////////////////////////////////////////////////////////////////////////
40
40
  GLuint backgroundProgram, shaderProgram, postFxShader;
41
+ GLuint verticalBlurShader = 0, horizontalBlurShader = 0, cutoffShader = 0;
41
42
 
42
43
  ///////////////////////////////////////////////////////////////////////////////
43
44
  // Environment
@@ -222,6 +223,12 @@ void initialize()
222
223
  "../lab5-rendertotexture/shading.frag");
223
224
  postFxShader = labhelper::loadShaderProgram("../lab5-rendertotexture/postFx.vert",
224
225
  "../lab5-rendertotexture/postFx.frag");
226
+ horizontalBlurShader = labhelper::loadShaderProgram("../lab5-rendertotexture/postFx.vert",
227
+ "../lab5-rendertotexture/horizontal_blur.frag");
228
+ verticalBlurShader = labhelper::loadShaderProgram("../lab5-rendertotexture/postFx.vert",
229
+ "../lab5-rendertotexture/vertical_blur.frag");
230
+ cutoffShader = labhelper::loadShaderProgram("../lab5-rendertotexture/postFx.vert",
231
+ "../lab5-rendertotexture/cutoff.frag");
225
232
 
226
233
  ///////////////////////////////////////////////////////////////////////////
227
234
  // Load environment map
@@ -390,6 +397,32 @@ void display()
390
397
  // 2. Set postFxShader as active
391
398
  // 3. Bind the framebuffer to texture unit 0
392
399
  // 4. Draw a quad over the entire viewport
400
+ FboInfo& horizontalBlurFbo = fboList[3];
401
+ FboInfo& verticalBlurFbo = fboList[4];
402
+ if(currentEffect == PostProcessingEffect::Separable_blur)
403
+ {
404
+ // horizontal blur
405
+ glBindFramebuffer(GL_FRAMEBUFFER, horizontalBlurFbo.framebufferId);
406
+ glViewport(0, 0, horizontalBlurFbo.width, horizontalBlurFbo.height);
407
+ glClear(GL_DEPTH_BUFFER_BIT);
408
+
409
+ glUseProgram(horizontalBlurShader);
410
+ glActiveTexture(GL_TEXTURE0);
411
+ glBindTexture(GL_TEXTURE_2D, cameraFB.colorTextureTarget);
412
+
413
+ labhelper::drawFullScreenQuad();
414
+
415
+ // vertical blur
416
+ glBindFramebuffer(GL_FRAMEBUFFER, verticalBlurFbo.framebufferId);
417
+ glViewport(0, 0, verticalBlurFbo.width, verticalBlurFbo.height);
418
+ glClear(GL_DEPTH_BUFFER_BIT);
419
+
420
+ glUseProgram(verticalBlurShader);
421
+ glActiveTexture(GL_TEXTURE0);
422
+ glBindTexture(GL_TEXTURE_2D, horizontalBlurFbo.colorTextureTarget);
423
+
424
+ labhelper::drawFullScreenQuad();
425
+ }
393
426
 
394
427
  // Task 4: Set the required uniforms
395
428
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -407,6 +440,8 @@ void display()
407
440
  glActiveTexture(GL_TEXTURE0);
408
441
  glBindTexture(GL_TEXTURE_2D, cameraFB.colorTextureTarget);
409
442
 
443
+ glActiveTexture(GL_TEXTURE1);
444
+ glBindTexture(GL_TEXTURE_2D, verticalBlurFbo.colorTextureTarget);
410
445
 
411
446
  labhelper::drawFullScreenQuad();
412
447
 
lab5-rendertotexture/postFx.frag CHANGED
@@ -81,7 +81,7 @@ void main()
81
81
  fragmentColor = textureRect(frameBufferTexture, mosaic(gl_FragCoord.xy));
82
82
  break;
83
83
  case 7:
84
- fragmentColor = vec4(0.0); // place holder
84
+ fragmentColor = textureRect(blurredFrameBufferTexture, gl_FragCoord.xy);
85
85
  break;
86
86
  case 8:
87
87
  fragmentColor = vec4(0.0); // place holder