glshader element location property removed

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

glshader element location property removed

pneves
Hey,

In the latest tagged release the location property in glshader which allows for a shader file to be loaded was removed with no mention on the commit log as far as I found. Is there any reasoning for this?

How can I have the same functionality from gst-launch?
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

Matthew Waters
Hi,

The location property was removed in favour of explicit fragment and
vertex properties which take the shader strings directly.  You can
emulate the location property by reading the file in whatever language
you desire and setting its contents to the fragment property.

For gst-launch, you'll have to read the file in shell script and set the
fragment property to its contents.  Note that gst-launch is only a
debugging tool.

Cheers
-Matt

On 15/12/15 05:53, pneves wrote:

> Hey,
>
> In the latest tagged release the location property in glshader which allows
> for a shader file to be loaded was removed with no mention on the commit log
> as far as I found. Is there any reasoning for this?
>
> How can I have the same functionality from gst-launch?
>
>
>
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/glshader-element-location-property-removed-tp4674911.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
>


_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

Holger
Hi,

I use a script for barrel distortion (HTC-Vive) which used the location property of glshader.
Can you give me an example how to adapt the old shader script to use it with the new gstreamer version?
> For gst-launch, you'll have to read the file in shell script and set the
> fragment property to its contents.
Where to put the content? What exactly do you mean?

Thanks
Holger

Matthew Waters wrote
Hi,

The location property was removed in favour of explicit fragment and
vertex properties which take the shader strings directly.  You can
emulate the location property by reading the file in whatever language
you desire and setting its contents to the fragment property.

For gst-launch, you'll have to read the file in shell script and set the
fragment property to its contents.  Note that gst-launch is only a
debugging tool.

Cheers
-Matt

On 15/12/15 05:53, pneves wrote:
> Hey,
>
> In the latest tagged release the location property in glshader which allows
> for a shader file to be loaded was removed with no mention on the commit log
> as far as I found. Is there any reasoning for this?
>
> How can I have the same functionality from gst-launch?
>
>
>
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/glshader-element-location-property-removed-tp4674911.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
>



_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


signature.asc (484 bytes) <http://gstreamer-devel.966125.n4.nabble.com/attachment/4674913/0/signature.asc>
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

pneves
Hello Mathew,

I too was confused and honestly I could not get it to work with a shader that previously worked flawlessly. Now it complains of shader linking "All shaders must use the same shading language".

Regardless in the code of gstglfiltershader.c there is an example which might work for you:

gst-launch-1.0 videotestsrc ! glupload ! glshader fragment="\"`cat myshader.frag`\"" ! glimagesink

Also writing the shader contents to the fragment property should also get you started.
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

pneves
Fo my case I had to set something like this, otherwise it would not work with the versions i tried. (By the way it is really burdensome to get the version.)

#version 100                                                                                                  
#extension GL_ARB_texture_rectangle : enable                                                                  
#ifdef GL_ES                                                                                                  
precision mediump float;                                                                                      
#endif
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

Holger
In reply to this post by pneves
Hi,

I also tried to make it work as you described with:
 fragment="\"`cat myshader.frag`\""
But all "\n" are dropped (under windows) and it doesn't work. I tried many other thinks to
pass it but without success. Finally I ended up in building the pipline with python. But it was nearly impossible to find any information how to setup gst-1.0 and python under windows.

Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

pneves
Hmm even so i think the \n being dropped shouldn't make a difference. I know you solved your problem but I am curious at what errors you were getting. Maybe somebody in the future may share the problem.
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

Holger
If I first read in the shader file in bash like this:

SHADER=`cat shaders/barrel_distortion.txt`
echo $SHADER

The output is:
 vec2 theta = (texCoord - LensCenter) CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.s float rSq = theta.x CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh theta.x + theta.y CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pi vec2 rvector = theta CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh (kappa.x + kappa.y CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh rSq + kappa.z CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh rSq CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh rSq + kappa.w CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh rSq CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh rSq CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipel vec2 tc = LensCenter + Scale CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pi vec2 ScaleIn = vec2(2.0 CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.sh tst_pipeline.py udpsend.sh scaleFactor, 1.0 / as CMakeLists.txt mono.py mono_cam.sh mono_cam_new.sh nbproject shader_test.sh shaders stereo_cam.s }l_FragColor = color;, tc );xCoordSeparated, Scale, ScaleIn);

There are some lines skipped because the original files looks like this:
#ifdef GL_ES
precision mediump float;
#endif
#pragma debug
#extension GL_ARB_texture_rectangle : enable
uniform sampler2D tex;
uniform float separation;
varying vec2 v_texcoord;

const vec4 kappa = vec4(1.0,1.7,0.7,15.0);
const float screen_width = 2160.0;
const float screen_height = 1200.0;
const float scaleFactor = 0.9;
const vec2 leftCenter = vec2(0.25, 0.5);
const vec2 rightCenter = vec2(0.75, 0.5);
//const float separation = -0.00;

// Scales input texture coordinates for distortion.
vec2 hmdWarp(vec2 LensCenter, vec2 texCoord, vec2 Scale, vec2 ScaleIn) {
    vec2 theta = (texCoord - LensCenter) * ScaleIn;
    float rSq = theta.x * theta.x + theta.y * theta.y;
    vec2 rvector = theta * (kappa.x + kappa.y * rSq + kappa.z * rSq * rSq + kappa.w * rSq * rSq * rSq);
    vec2 tc = LensCenter + Scale * rvector;
    return tc;
}

bool validate(vec2 tc, int left_eye) {
    //keep within bounds of texture
    if ((left_eye == 1 && (tc.x < 0.0 || tc.x > 0.5)) ||  
        (left_eye == 0 && (tc.x < 0.5 || tc.x > 1.0)) ||
        tc.y < 0.0 || tc.y > 1.0) {
        return false;
    }
    return true;
}


void main() {
    vec2 screen = vec2(screen_width, screen_height);

    float as = float(screen.x / 2.0) / float(screen.y);
    vec2 Scale = vec2(0.5, as);
    vec2 ScaleIn = vec2(2.0 * scaleFactor, 1.0 / as * scaleFactor);

    vec2 texCoord = (v_texcoord.xy);
    vec2 texCoordSeparated = texCoord;
   
    vec2 tc = vec2(0);
    vec4 color = vec4(0);
   
    if (texCoord.x < 0.5) {
        texCoordSeparated.x += separation;
        tc = hmdWarp(leftCenter, texCoordSeparated, Scale, ScaleIn );
        color = texture2D(tex, tc );
        if (!validate(tc, 1))
            color = vec4(0);
    } else {
        texCoordSeparated.x -= separation;
        tc = hmdWarp(rightCenter, texCoordSeparated, Scale, ScaleIn);
        color = texture2D(tex, tc );
        if (!validate(tc, 0))
            color = vec4(0);  
           
    }  
    gl_FragColor = color;
}
Reply | Threaded
Open this post in threaded view
|

Re: glshader element location property removed

Holger
.... so seems to be a problem with msys and windows... because it reads in directories etc.