Filter Video with Shader?

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
User avatar
pgimeno
Party member
Posts: 1903
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Filter Video with Shader?

Post by pgimeno » Sun Sep 08, 2019 11:39 pm

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

User avatar
Sasha264
Citizen
Posts: 60
Joined: Mon Sep 08, 2014 7:57 am

Re: Filter Video with Shader?

Post by Sasha264 » Mon Sep 09, 2019 11:57 am

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.

User avatar
pgimeno
Party member
Posts: 1903
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: Filter Video with Shader?

Post by pgimeno » Mon Sep 09, 2019 3:28 pm

Gah, you're so right, thank you! I haven't used video much yet as you can imagine :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 9 guests