Page 1 of 1

Filter Video with Shader?

Posted: Sun Sep 08, 2019 11:39 pm
by pgimeno
I'm trying to use a shader to apply effects to a video, but when I set any shader, even the default shader, I get a blank video image.

Minimal example:

Code: Select all

local video = love.graphics.newVideo('video.ogv')
local shader = love.graphics.newShader[[
  vec4 effect(vec4 colour, Image tex, vec2 texpos, vec2 scrpos)
  {
    return Texel(tex, texpos) * colour;
  }
]]
video:play()

function love.draw()
  love.graphics.setShader(shader)
  love.graphics.draw(video)
  love.graphics.setShader()
end
Is it possible to use a shader to filter a video? In this thread, bartbes seems to imply that it is, but I was unable: https://love2d.org/forums/viewtopic.php ... deo+shader

Re: Filter Video with Shader?

Posted: Mon Sep 09, 2019 11:57 am
by Sasha264
Hello!
I suggest that the problem is in Texel(...) function which is not intended to sample video.

Here I found proper sampling function for video: https://love2d.org/wiki/love.graphics.newShader

Code: Select all

local video = love.graphics.newVideo('video.ogv')
local shader = love.graphics.newShader[[
  vec4 effect(vec4 colour, Image tex, vec2 texpos, vec2 scrpos)
  {
    return vec4(1.0f, 1.0f, 1.0f, 2.0f) - VideoTexel(texpos) * colour;
  }
]]
video:play()

function love.draw()
  love.graphics.setShader(shader)
  love.graphics.draw(video)
  love.graphics.setShader()
end
vec4(1.0f, 1.0f, 1.0f, 2.0f) -
Does a simple inverse in my case.

Re: Filter Video with Shader?

Posted: Mon Sep 09, 2019 3:28 pm
by pgimeno
Gah, you're so right, thank you! I haven't used video much yet as you can imagine :)