Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Magnify Shader QQuickShaderEffect error
Forum Updated to NodeBB v4.3 + New Features

QML Magnify Shader QQuickShaderEffect error

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Popa Raluca
    wrote on last edited by
    #1

    hi, i am new in qt and qml qorld so please help me with something;

    i'm trying to apply magnify effect on a photo
    i don't understand why i get this :

    'src_tex_unit0' does not have a matching property!

    can anyone help me?
    here is the code
    @ vertexShader: "uniform highp mat4 qt_Matrix;
    attribute highp vec4 qt_Vertex;
    attribute highp vec2 qt_MultiTexCoord0;
    varying highp vec2 coord;
    varying highp vec2 positionVarying;
    void main() {
    coord = qt_MultiTexCoord0;
    positionVarying = qt_Vertex.xy;
    gl_Position = qt_Matrix * qt_Vertex;
    }"
    fragmentShader: "
    #extension GL_ARB_texture_rectangle : enable
    uniform sampler2DRect src_tex_unit0;
    //uniform vec2 image_source;

    //uniform vec2 circlePos;
    //uniform float circleRadius;
    //uniform float minZoom;
    //uniform float maxZoom;
    const vec2 circlePos = vec2 (1000.0, 1000.0);
    const float circleRadius = 40.0;
    const float minZoom = 0.1;
    const float maxZoom= 1.0;
    varying highp vec2 coord;
    vec4 color;

    void main( void )
    {
    // vec2 st = gl_TexCoord[0].st;
    //check if our pixels fit in the bounding rect - so we avoid expensive operations like sqrt.
    float maxX = circlePos.x + circleRadius;
    float minX = circlePos.x - circleRadius;
    float maxY = circlePos.y + circleRadius;
    float minY = circlePos.y - circleRadius;

    if( coord.x > minX && coord.x < maxX && coord.y > minY && coord.y < maxY)
    

    {
    float relX = coord.x - circlePos.x;
    float relY = coord.y - circlePos.y;
    float ang = atan(relY, relX);
    float dist = sqrt(relXrelX + relYrelY);
    if( dist <= circleRadius ){
    //figure a zoom value for the pixel based on its distance from the center of the circle
    float newRad = dist * ( (maxZoom * dist/circleRadius) + minZoom );

            float newX = circlePos.x + cos( ang ) * newRad;
            float newY = circlePos.y + sin( ang ) * newRad;
    
            gl_FragColor = texture2DRect(src_tex_unit0, vec2(newX, newY) );
    
        }
        else{
            //just draw the pixels as normal
            gl_FragColor = texture2DRect(src_tex_unit0, coord );
            }
        }
    

    else{
    //just draw the pixels as normal
    gl_FragColor = texture2DRect(src_tex_unit0, coord );
    }
    }
    "@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Arpegius
      wrote on last edited by
      #2

      Declare
      @
      property var src_tex_unit0: photo1
      @

      in your ShaderEffect. Where photo1 is your Image.
      You also would pass your const as uniforms, so you need to declare them as propeties too:
      @
      property var circlePos: Qt.vector2d(1000.0, 1000.0)
      property real circleRadius: 40.0
      property real minZoom: 0.1
      property real maxZoom: 1.0
      @

      Somehow Qt.vector2d has a bug for me, as is not updated. I would use point:
      @
      property point mouse: Qt.point( mousearea1.mouseX, mousearea1.mouseY )
      @

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Popa Raluca
        wrote on last edited by
        #3

        whoo, thanks a lot !! i didn't figure out that i can define in ShaderEffect those properties :) i did what you said and i have 0 errors, but still something it's wrong, i think because of uniform vec2 src_tex_offset0;
        i have no output :D

        i read more about automatic QML propertybinding into vertex- and fragment shader uniforms matrix and found this:

        http://harmattan-dev.nokia.com/docs/library/html/qt4/qml-shadereffectitem.html

        my question is : how about matrix ? i use uniform mat4

        @ property matrix4x4 modelViewProjectionMatrix : Qt.matrix4x4(1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0,
        1.0, 1.0, 1.0, 1.0)@
        this does not work ...

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          @Arpegius: make certain that you import QtQuick 2.0 in the document. You can use "property vector2d circlePos" instead of property var (to ensure a property of the correct type). If there are still issues, please file a bug report.

          Cheers,
          Chris.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved