News:

--

Main Menu

Fun with openGL

Started by mean, June 24, 2016, 05:57:26 AM

Previous topic - Next topic

mean

I've just commited a new filter : ShaderLoader
It is a very simple shaderLoader, loading the GL script from an external text file, nothing to compile.

To test them, copy paste the sample given into a text file (i.e. shader1.txt) and give shader1.txt to the glShaderLoader video filter. That's it.

It only takes fragment shader, not vertex shader.

The predefined uniform vars are :
* myTextureY : Luma as 8 bits greyscale texture
* myTextureU : Chroma U as 8 bits greyscale texture
* myTextureV : ChromaV as 8 bits greyscale texture
* pts : Timestamp of the image in microseconds
* myResolution : Width & height of the video

/!\ U& V are subsampled by 2 in both directions, you need to multiply the coordinates by 0.5 /!\

Output pixel is
* R=Luma
* G= Chroma U
* B = Chroma V

It is better to use openGL as display when playing with openGL filter


A simple, completely useless shader example :

#extension GL_ARB_texture_rectangle: enable
uniform sampler2DRect myTextureY; // tex unit 0
uniform sampler2DRect myTextureU; // tex unit 1
uniform sampler2DRect myTextureV; // tex unit 2
uniform float pts; // tex unit 2
const vec2 half_vec=vec2(0.5,0.5);

void main(void) {
vec2 p=gl_TexCoord[0].xy;
p.x = p.x + sin(p.y*.5+p.x*6.+pts/100000.*2.)*3;
vec2 half=half_vec*p;
vec4 texY = texture2DRect(myTextureY,p);
vec4 texU = texture2DRect(myTextureU,half);
vec4 texV = texture2DRect(myTextureV,half);
gl_FragColor = vec4(texY.r, texU.r, texV.r, 1.0);
}


mean

If you dont use openGl as display, preview might not work.
Play filtered might  work.

mean

NB: There is nothing to compile, the shader program is a simple text you can load into the shaderLoader plugin

mean


mean

#4
2 small youtube videos

https://www.youtube.com/watch?v=yUpPds61ysw&list=PLLGMi2RSm8sbWip7wCruqLptvYZvyHpK8&index=3

https://www.youtube.com/watch?v=UfexjU36tDA&index=2&list=PLLGMi2RSm8sbWip7wCruqLptvYZvyHpK8

2nd one source is


#extension GL_ARB_texture_rectangle: enable
uniform sampler2DRect myTextureY; // tex unit 0
uniform sampler2DRect myTextureU; // tex unit 1
uniform sampler2DRect myTextureV; // tex unit 2
uniform float pts; // time in us
uniform vec2  myResolution; //
const vec2 half_vec=vec2(0.5,0.5);
const float PI = 3.1415926535;

void main()
{
  float aperture = 178.0;
  float apertureHalf = 0.5 * aperture * (PI / 180.0);
  float maxFactor = sin(apertureHalf)*3*cos((pts/3000000.)*PI);
  if(maxFactor<0)
  {
               maxFactor=-maxFactor; // fabs ?
  }
 
  vec2 uv;
  vec2 xy =  2*gl_TexCoord[0].xy /myResolution -vec2(1.,1.);
  float d = length(xy);
  if (d < (2.0-maxFactor))
  {
    d = length(xy * maxFactor);
    float z = sqrt(1.0 - d * d);
    float r = atan(d, z) / PI;
    float phi = atan(xy.y, xy.x);
   
    uv.x = r * cos(phi) + 0.5;
    uv.y = r * sin(phi) + 0.5;
    uv=uv*myResolution;
  }
  else
  {
    uv = gl_TexCoord[0].xy ;
  }
  vec4 cY = texture2DRect(myTextureY, uv);
  vec4 cU = texture2DRect(myTextureU, uv*half_vec);
  vec4 cV = texture2DRect(myTextureV, uv*half_vec);
  gl_FragColor = vec4(cY.r,cU.r,cV.r,1.0);
}


mean

#5
Ripple Effect


//http://www.geeks3d.com/20091116/shader-library-2d-shockwave-post-processing-filter-glsl/
#extension GL_ARB_texture_rectangle: enable
uniform sampler2DRect myTextureY; // tex unit 0
uniform sampler2DRect myTextureU; // tex unit 1
uniform sampler2DRect myTextureV; // tex unit 2
uniform vec2  myResolution;
uniform float pts; // tex unit 2
const vec2 half_vec=vec2(0.5,0.5);
void main()
{
  vec3 shockParams=vec3( 10.0, 0.8, myResolution.x/50); // 1- pow base, 2 - pow exponent 3- Size of the wave

  vec2 pos=gl_TexCoord[0].xy;
  vec2 texCoord = pos;

  float distance = distance(pos, myResolution*half_vec);

  float time=pts/3000.;

if ( (distance <= (time + shockParams.z)) &&
       (distance >= (time - shockParams.z)) )
  {
    float diff = (distance - time);
    float powDiff = 1.0 - pow(abs(diff*shockParams.x),
                                shockParams.y);
    float diffTime = diff  * powDiff;
    vec2 diffUV = normalize(pos - myResolution*half_vec);
    texCoord = pos + (diffUV * diffTime);
  }

  vec3 cY = texture2DRect(myTextureY, texCoord);
  vec3 cU = texture2DRect(myTextureU, texCoord*half_vec);
  vec3 cV = texture2DRect(myTextureV, texCoord*half_vec);

  gl_FragColor = vec4(cY.r,cU.r,cV.r,1.0);
}

mean

lightning ( http://glslsandbox.com/e#33682.0)


//http://glslsandbox.com/e#33682.0
#extension GL_ARB_texture_rectangle: enable
uniform sampler2DRect myTextureY; // tex unit 0
uniform sampler2DRect myTextureU; // tex unit 1
uniform sampler2DRect myTextureV; // tex unit 2
uniform vec2  myResolution;
uniform float pts; // tex unit 2
const vec2 half_vec=vec2(0.5,0.5);
// Lightning
// By: Brandon Fogerty
// bfogerty at gmail dot com
// xdpixel.com

float Hash( vec2 p)
{
     vec3 p2 = vec3(p.xy,1.0);
    return fract(sin(dot(p2,vec3(37.1,61.7, 12.4)))*3758.5453123);
}

float noise(in vec2 p)
{
    vec2 i = floor(p);
     vec2 f = fract(p);
     f *= f*(3.0-2.0*f);
    return mix(mix(Hash(i + vec2(0.,0.)), Hash(i + vec2(1.,0.)),f.x),
               mix(Hash(i + vec2(0.,1.)), Hash(i + vec2(1.,1.)),f.x),
               f.y);
}

float fbm(vec2 p)
{
     float v = 0.0;
     v += noise(p*1.0) * .75;
     v += noise(p*3.)  * .50;
     v += noise(p*9.)  * .250;
     v += noise(p*27.)  * .125;
     return v;
}


vec4 lightning( void )
{

vec2 uv = ( gl_TexCoord[0].xy / myResolution.xy ) * 2.0 - 1.0;
uv.x *= myResolution.x/myResolution.y;
        uv.y -= 1.05;

//vec2 tmp_uv;
//tmp_uv.x = uv.y;
//tmp_uv.y = uv.x;
//uv = tmp_uv;
float timeVal = pts /100000.;

vec3 finalColor = vec3( 0.0 );
for( int i=0; i < 10; ++i )
{
float indexAsFloat = float(i);
float amp = 10.0 + (indexAsFloat*500.0);
float period = 2.0 + (indexAsFloat+2.0);
float thickness = mix( 0.9, 1.0, noise(uv*indexAsFloat) );
float t = abs( 1.0 / (sin(uv.y + fbm( uv + timeVal * period )) * amp) * thickness );


finalColor +=  t * vec3( 0.3, 0.3, .5 );
}

return vec4( finalColor, 1.0 );

}

void main(void)
{
        vec2 pos = gl_TexCoord[0].xy ;
vec4 color = lightning();
        vec4 luma=color+texture2DRect(myTextureY,pos);
        vec4 chromaU=texture2DRect(myTextureU,pos*half_vec);
        vec4 chromaV=texture2DRect(myTextureV,pos*half_vec);
        gl_FragColor = vec4(luma.r,chromaU.r,chromaV.r,1.0);
}