Author Topic: How to use video texture in a GLSL Shader  (Read 9007 times)

0 Members and 1 Guest are viewing this topic.

Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4457
How to use video texture in a GLSL Shader
« on: February 02, 2016, 11:05:54 PM »
So i saw this nice Shadertoy demo Wrist Slitter , which consists of a Mandelbrot with video in background.

Porting to GeeXLab is pretty simple, just copy the video texture code from demo_video_player_gles2_v2.xml and use it with iChannel

The demo is preset to Timelapse-1.m4v from code sample pack, try Big Buck Bunny instead or whatever makes you happy.

As you can see i don't know how to vertical flip textures in GeeXLab  :P

Mandelbrot zooming was too fast so i patched the pixelshader

#define slowdown 20.0
    return zoomto(xy, DEST, iGlobalTime/slowdown);


change value dependent on length of video


« Last Edit: February 03, 2016, 06:43:05 PM by Stefan »


JeGX

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2217
    • Geeks3D.com
Re: How to use video texture in a GLSL Shader
« Reply #1 on: February 03, 2016, 02:59:15 PM »
To flip the texture in the shader, you have to play with the vec2 texture coordinates. Try something like that to flip the texture around the horizontal axis (by inversing the Y coordinate):

Code: [Select]
vec4 getColor( in vec2 xy )
{

...

if (int(iter) >= ITER_MAX)
{
  vec2 uv = zxy*0.25 + 0.5;
  uv.y *= -1.0;
  return texture2D(iChannel0, uv);
}

...

vec2 uv = vec2(picx, dist);
uv.y *= -1.0;
vec4 color = texture2D(iChannel0, uv);

...

}



Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4457
Re: How to use video texture in a GLSL Shader
« Reply #2 on: February 03, 2016, 06:41:50 PM »
I was hoping you already have a function in LUA (equivalent to the magic button at Shadertoy.com)

Anyway i found the sweet spot in the pixelshader: simply replace iResolution.y with -iResolution.y or -1*iResolution.y
But it's only that easy in this particular shader because iResolution is split into x and y

>>>download fixed version here<<<

« Last Edit: February 03, 2016, 08:07:07 PM by Stefan »

Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4457
Re: How to use video texture in a GLSL Shader
« Reply #3 on: February 03, 2016, 09:12:44 PM »
OK,
here is a generic flip code:

replace
iResolution.xy
with
vec2(iResolution.x, -iResolution.y)

Tested in toon video shader and ascii art

I'll upload the demos later with a non-commercial video
« Last Edit: February 05, 2016, 07:10:36 PM by Stefan »

Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4457
Re: How to use video texture in a GLSL Shader
« Reply #4 on: February 05, 2016, 07:18:14 PM »
>>>Here is a package with 13 demos<<< - d/l below

These demos use http://hwcdn.net/j9t9v3v5/cds/Suzie_H264.mp4 from http://www.elementaltechnologies.com/resources/4k-test-sequences
It is licensed under a Creative Commons Attribution-NoDerivs 3.0 Unported License.

If this 4K video crashes GeeXLab on exit or reload, use the shrunk video in the package.

Some shaders use iChannelTime[0] - to calculate the length of the video i assume

In the demos it looks like this:

uniform float iChannelTime0;
...
float time = iChannelTime0;
 
gh_gpu_program.uniform1f(shadertoy_prog, "iChannelTime0", video_elapsed_time)

« Last Edit: February 07, 2016, 10:17:17 AM by Stefan »

Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4457
Re: How to use video texture in a GLSL Shader
« Reply #5 on: February 07, 2016, 10:16:08 AM »
>>>download updated package<<<

Note: i didn't get the 3 layers in  "Page curl effect" look right


"video heightfield" flipped via -pixel.y

"The Tender Cut [TV]" added - uses video and keyboard texture

« Last Edit: February 10, 2016, 05:43:24 PM by Stefan »

Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4457
Re: How to use video texture in a GLSL Shader
« Reply #6 on: February 10, 2016, 05:42:30 PM »
>>>Update 3 - download now<<<

18 demos now in total

Following ports were a PITA  :P

"Page curl effect" fixed
Code: [Select]
return texture2D(iChannel0, vec2(p.x, -p.y));               // seethrough 1
vec4 color = texture2D(iChannel0, vec2(point.x, -point.y)); // seethrough 2
vec4 color = texture2D(iChannel0, vec2(point.x, -point.y)); // backside
bgColor = texture2D(iChannel0, vec2(uv.x, -uv.y)).rgga;     // background
color = texture2D(iChannel0, vec2(uv.x, -uv.y));            // rotation

"Overkill" contains 2 videos (!) - a real time clock and a cubemap ("Yokohama" is already in demo pack FEB 2016).
After 22 seconds "News" appears as billboard and "Suzie" in the tiles. Latter is hard to see, so maximise window.