QML Magnify Shader QQuickShaderEffect error
-
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 );
}
}
"@ -
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 )
@ -
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 :Di 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 ... -
@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.