Shader on video

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Shader on video

Post by feelixe »

Hey, I just tried applying a Blur Shader to a video, but insted of seing the video I just see some text.
Is this a limitation or did i do something wrong?
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Shader on video

Post by Nixola »

Could you share a love file?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
feelixe
Prole
Posts: 36
Joined: Tue Aug 20, 2013 10:29 am

Re: Shader on video

Post by feelixe »

Nixola wrote:Could you share a love file?
I Found this shader in the forums. I tried without the canvas first but that didn't work.

Code: Select all

	video1 = love.graphics.newVideo("images/Wildlife.ogv",false),
	blur1 = love.graphics.newShader [[

      vec4 effect(vec4 color, Image texture, vec2 vTexCoord, vec2 pixel_coords)
      {
         vec4 sum = vec4(0.0);
         number blurSize = 0.005;
         //number d = distance(vTexCoord, mousePos/screenSize);
         //number blurSize = clamp(1/d/screenSize.x, 0, 1.0);
         // blur in y (vertical)
         // take nine samples, with the distance blurSize between them
         sum += texture2D(texture, vec2(vTexCoord.x - 4.0*blurSize, vTexCoord.y)) * 0.05;
         sum += texture2D(texture, vec2(vTexCoord.x - 3.0*blurSize, vTexCoord.y)) * 0.09;
         sum += texture2D(texture, vec2(vTexCoord.x - 2.0*blurSize, vTexCoord.y)) * 0.12;
         sum += texture2D(texture, vec2(vTexCoord.x - blurSize, vTexCoord.y)) * 0.15;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
         sum += texture2D(texture, vec2(vTexCoord.x + blurSize, vTexCoord.y)) * 0.15;
         sum += texture2D(texture, vec2(vTexCoord.x + 2.0*blurSize, vTexCoord.y)) * 0.12;
         sum += texture2D(texture, vec2(vTexCoord.x + 3.0*blurSize, vTexCoord.y)) * 0.09;
         sum += texture2D(texture, vec2(vTexCoord.x + 4.0*blurSize, vTexCoord.y)) * 0.05;
         
         
         return sum;
      }
      ]],
	  blur2 = love.graphics.newShader [[
      
      vec4 effect(vec4 color, Image texture, vec2 vTexCoord, vec2 pixel_coords)
      {
         vec4 sum = vec4(0.0);
         number blurSize = 0.005;

         // blur in y (vertical)
         // take nine samples, with the distance blurSize between them
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y - 4.0*blurSize)) * 0.05;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y - 3.0*blurSize)) * 0.09;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y - 2.0*blurSize)) * 0.12;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y- blurSize)) * 0.15;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y + blurSize)) * 0.15;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y + 2.0*blurSize)) * 0.12;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y + 3.0*blurSize)) * 0.09;
         sum += texture2D(texture, vec2(vTexCoord.x, vTexCoord.y + 4.0*blurSize)) * 0.05;

         return sum;
      }
      ]]

Code: Select all

love.graphics.setCanvas(canvas)
	love.graphics.setShader(images.blur1)
	love.graphics.draw(images.video1,0,0,0,2,2)
	love.graphics.setShader()
	love.graphics.setCanvas()
	love.graphics.setShader(images.blur2)
	love.graphics.draw(canvas,0,0)
	love.graphics.setShader()
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Shader on video

Post by slime »

To get a pixel's color directly from a Video, you have to use VideoTexel(texcoord) instead of Texel/texture2D(texture, texcoord), since the Video object is not a Texture.

It might (or might not, I'm not sure) be more efficient to draw the Video to a Canvas without a shader. and then draw the Canvas to the screen (or to another Canvas) using your shader, rather than calling VideoTexel a bunch of times per pixel.
Last edited by slime on Thu Feb 25, 2016 11:26 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Shader on video

Post by bartbes »

slime wrote:TexelVideo(texcoord)
VideoTexel
Post Reply

Who is online

Users browsing this forum: dusoft and 78 guests