Browse Source

Fix Postprocessing example;

bjorn 5 years ago
parent
commit
c6096e83d9
1 changed files with 13 additions and 7 deletions
  1. 13 7
      examples/Postprocessing/main.lua

+ 13 - 7
examples/Postprocessing/main.lua

@@ -29,6 +29,9 @@ local screenShaderFragment = [[
   #define OFFSET1 1.3846153846
   #define OFFSET1 1.3846153846
   #define OFFSET2 3.2307692308
   #define OFFSET2 3.2307692308
 
 
+  // The Canvas texture to sample from.
+  uniform sampler2DMultiview canvas;
+
   // UVs are sampled from a texture over the range 0..1.
   // UVs are sampled from a texture over the range 0..1.
   // This uniform is set outside the shader so we know what UV distance "one pixel" is.
   // This uniform is set outside the shader so we know what UV distance "one pixel" is.
   uniform vec2 resolution;
   uniform vec2 resolution;
@@ -40,11 +43,11 @@ local screenShaderFragment = [[
   vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
   vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) {
     vec2 pixelOff = direction / resolution;
     vec2 pixelOff = direction / resolution;
     vec4 color = vec4(0.0);
     vec4 color = vec4(0.0);
-    color += texture(image, uv) * WEIGHT0;
-    color += texture(image, uv + pixelOff * OFFSET1) * WEIGHT1;
-    color += texture(image, uv - pixelOff * OFFSET1) * WEIGHT1;
-    color += texture(image, uv + pixelOff * OFFSET2) * WEIGHT2;
-    color += texture(image, uv - pixelOff * OFFSET2) * WEIGHT2;
+    color += textureMultiview(canvas, uv) * WEIGHT0;
+    color += textureMultiview(canvas, uv + pixelOff * OFFSET1) * WEIGHT1;
+    color += textureMultiview(canvas, uv - pixelOff * OFFSET1) * WEIGHT1;
+    color += textureMultiview(canvas, uv + pixelOff * OFFSET2) * WEIGHT2;
+    color += textureMultiview(canvas, uv - pixelOff * OFFSET2) * WEIGHT2;
     return color;
     return color;
   }
   }
 ]]
 ]]
@@ -109,7 +112,8 @@ end
 
 
 -- This simple callback is used to draw one canvas onto another
 -- This simple callback is used to draw one canvas onto another
 local function fullScreenDraw(source)
 local function fullScreenDraw(source)
-  lovr.graphics.fill(source)
+  screenShader:send('canvas', source:getTexture())
+  lovr.graphics.fill()
 end
 end
 
 
 function lovr.draw()
 function lovr.draw()
@@ -122,6 +126,7 @@ function lovr.draw()
 
 
     -- Start by drawing the scene to one of our temp canvases.
     -- Start by drawing the scene to one of our temp canvases.
     tempCanvas[1]:renderTo(sceneDraw)
     tempCanvas[1]:renderTo(sceneDraw)
+    tempCanvas[2]:renderTo(function() lovr.graphics.clear() end)
 
 
     -- We now have the scene in a texture (a canvas), which means we can apply a full-screen effect
     -- We now have the scene in a texture (a canvas), which means we can apply a full-screen effect
     -- by rendering the texture with a shader material. However, because our blur is separable,
     -- by rendering the texture with a shader material. However, because our blur is separable,
@@ -146,6 +151,7 @@ function lovr.draw()
     tempCanvas[2]:renderTo(fullScreenDraw, tempCanvas[1])
     tempCanvas[2]:renderTo(fullScreenDraw, tempCanvas[1])
 
 
     screenShader:send("direction", {0, 4})
     screenShader:send("direction", {0, 4})
-    lovr.graphics.fill(tempCanvas[2]) -- On the final pass, render directly to the screen.
+    screenShader:send("canvas", tempCanvas[2]:getTexture())
+    lovr.graphics.fill() -- On the final pass, render directly to the screen.
   end
   end
 end
 end