diff --git a/include/Warp.h b/include/Warp.h index 637d0a9..cc3e610 100644 --- a/include/Warp.h +++ b/include/Warp.h @@ -159,6 +159,24 @@ class Warp : public std::enable_shared_from_this { mEdges.z = glm::clamp( edges.z * 0.5f, 0.0f, 1.0f ); mEdges.w = glm::clamp( edges.w * 0.5f, 0.0f, 1.0f ); } + //! returns the edge blending shift value for the left, top, right and bottom (values between -1 and 1) + virtual const ci::vec4 getShift() const { return mShift; } + //! set the edge blending shift value for the left, top, right and bottom (values between -1 and 1) + virtual void setShift(float left, float top, float right, float bottom) + { + mShift.x = left; + mShift.y = top; + mShift.z = right; + mShift.w = bottom; + } + //! set the edge blending shift value for the left, top, right and bottom (values between -1 and 1) + virtual void setShift(const ci::vec4 &shift) + { + mShift.x = shift.x; + mShift.y = shift.y; + mShift.z = shift.z; + mShift.w = shift.w; + } //! reset control points to undistorted image virtual void reset() = 0; @@ -267,7 +285,7 @@ class Warp : public std::enable_shared_from_this { ci::vec3 mGamma; ci::vec4 mEdges; float mExponent; - + ci::vec4 mShift; //! time of last control point selection double mSelectedTime; //! keep track of mouse position diff --git a/src/Warp.cpp b/src/Warp.cpp index 11c76a1..2313c91 100644 --- a/src/Warp.cpp +++ b/src/Warp.cpp @@ -47,6 +47,7 @@ Warp::Warp( WarpType type ) , mGamma( 1.0f ) , mEdges( 0.0f ) , mExponent( 2.0f ) + , mShift( 0.0f ) , mSelectedTime( 0 ) { mWindowSize = vec2( float( mWidth ), float( mHeight ) ); @@ -177,6 +178,14 @@ XmlTree Warp::toXml() const luminance.setAttribute( "green", mLuminance.y ); luminance.setAttribute( "blue", mLuminance.z ); blend.push_back( luminance ); + + XmlTree shift; + shift.setTag("shift"); + shift.setAttribute("left", mShift.x); + shift.setAttribute("top", mShift.y); + shift.setAttribute("right", mShift.z); + shift.setAttribute("bottom", mShift.w); + blend.push_back(shift); } xml.push_back( blend ); @@ -223,6 +232,14 @@ void Warp::fromXml( const XmlTree &xml ) mLuminance.y = luminance->getAttributeValue( "green", mLuminance.y ); mLuminance.z = luminance->getAttributeValue( "blue", mLuminance.z ); } + + auto shift = blend->find("shift"); + if (shift != blend->end()) { + mShift.x = shift->getAttributeValue("left", mShift.x); + mShift.y = shift->getAttributeValue("top", mShift.y); + mShift.z = shift->getAttributeValue("right", mShift.z); + mShift.w = shift->getAttributeValue("bottom", mShift.w); + } } // reconstruct warp @@ -274,7 +291,7 @@ void Warp::deselectControlPoint() unsigned Warp::findControlPoint( const vec2 &pos, float *distance ) const { - unsigned index; + unsigned index = 0; // store mouse position for later use in e.g. WarpBilinear::keyDown(). mMouse = pos; @@ -352,6 +369,7 @@ WarpList Warp::readSettings( const DataSourceRef &source ) // iterate maps for( XmlTree::ConstIter child = profileXml.begin( "map" ); child != profileXml.end(); ++child ) { + XmlTree warpXml = child->getChild( "warp" ); // create warp of the correct type diff --git a/src/WarpBilinear.cpp b/src/WarpBilinear.cpp index f04af37..6c13a84 100644 --- a/src/WarpBilinear.cpp +++ b/src/WarpBilinear.cpp @@ -193,6 +193,8 @@ void WarpBilinear::draw( bool controls ) mShader->uniform( "uEdges", mEdges ); mShader->uniform( "uExponent", mExponent ); mShader->uniform( "uEditMode", (bool)isEditModeEnabled() ); + mShader->uniform( "uShift", mShift + vec4(-mX1, -mY1, 1.f - mX2, 1.f - mY2) ); + mBatch->draw(); @@ -689,6 +691,7 @@ void WarpBilinear::createShader() "uniform vec4 uEdges;\n" "uniform float uExponent;\n" "uniform bool uEditMode;\n" + "uniform vec4 uShift;\n" "" "in vec2 vertTexCoord0;\n" "in vec4 vertColor;\n" @@ -706,10 +709,10 @@ void WarpBilinear::createShader() " vec4 texColor = texture( uTex0, vertTexCoord0 );\n" "" " float a = 1.0;\n" - " if( uEdges.x > 0.0 ) a *= clamp( vertTexCoord0.x / uEdges.x, 0.0, 1.0 );\n" - " if( uEdges.y > 0.0 ) a *= clamp( vertTexCoord0.y / uEdges.y, 0.0, 1.0 );\n" - " if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n" - " if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n" + " if( uEdges.x > 0.0 ) a *= clamp( ( uShift.x + vertTexCoord0.x ) / uEdges.x, 0.0, 1.0 );\n" + " if( uEdges.y > 0.0 ) a *= clamp( ( uShift.y + vertTexCoord0.y ) / uEdges.y, 0.0, 1.0 );\n" + " if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - uShift.z - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n" + " if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - uShift.w - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n" "" " const vec3 one = vec3( 1.0 );\n" " vec3 blend = ( a < 0.5 ) ? ( uLuminance * pow( 2.0 * a, uExponent ) ) : one - ( one - uLuminance ) * pow( 2.0 * ( 1.0 - a ), uExponent );\n" diff --git a/src/WarpPerspective.cpp b/src/WarpPerspective.cpp index de94ea6..f4dec82 100644 --- a/src/WarpPerspective.cpp +++ b/src/WarpPerspective.cpp @@ -121,7 +121,7 @@ void WarpPerspective::draw( const gl::Texture2dRef &texture, const Area &srcArea mShader->uniform( "uGamma", mGamma ); mShader->uniform( "uEdges", mEdges ); mShader->uniform( "uExponent", mExponent ); - + mShader->uniform("uShift", mShift); auto coords = texture->getAreaTexCoords( srcArea ); gl::drawSolidRect( rect, coords.getUpperLeft(), coords.getLowerRight() ); @@ -333,6 +333,7 @@ void WarpPerspective::createShader() "uniform vec3 uGamma;\n" "uniform vec4 uEdges;\n" "uniform float uExponent;\n" + "uniform vec4 uShift;\n" "" "in vec2 vertTexCoord0;\n" "in vec4 vertColor;\n" @@ -343,10 +344,10 @@ void WarpPerspective::createShader() " vec4 texColor = texture( uTex0, vertTexCoord0 );\n" "" " float a = 1.0;\n" - " if( uEdges.x > 0.0 ) a *= clamp( vertTexCoord0.x / uEdges.x, 0.0, 1.0 );\n" - " if( uEdges.y > 0.0 ) a *= clamp( vertTexCoord0.y / uEdges.y, 0.0, 1.0 );\n" - " if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n" - " if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n" + " if( uEdges.x > 0.0 ) a *= clamp( ( uShift.x + vertTexCoord0.x ) / uEdges.x, 0.0, 1.0 );\n" + " if( uEdges.y > 0.0 ) a *= clamp( ( uShift.y + vertTexCoord0.y ) / uEdges.y, 0.0, 1.0 );\n" + " if( uEdges.z > 0.0 ) a *= clamp( ( 1.0 - uShift.z - vertTexCoord0.x ) / uEdges.z, 0.0, 1.0 );\n" + " if( uEdges.w > 0.0 ) a *= clamp( ( 1.0 - uShift.w - vertTexCoord0.y ) / uEdges.w, 0.0, 1.0 );\n" "" " const vec3 one = vec3( 1.0 );\n" " vec3 blend = ( a < 0.5 ) ? ( uLuminance * pow( 2.0 * a, uExponent ) ) : one - ( one - uLuminance ) * pow( 2.0 * ( 1.0 - a ), uExponent );\n"