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: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Filter Video with Shader?

Post 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
User avatar
Sasha264
Party member
Posts: 131
Joined: Mon Sep 08, 2014 7:57 am

Re: Filter Video with Shader?

Post 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.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Filter Video with Shader?

Post by pgimeno »

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: Ahrefs [Bot] and 44 guests