2013-07-25 35 views
0

我使用Brad Larson的GPUImage庫。看起來像GPUImagePinchDistortionFilter中的錯誤。誰能提供解決方案?

GPUImageBulgeDistortionFilter可以在圖像上正常工作。但GPUImagePinchDistortion過濾器在圓形切割中將原始圖像的效果渲染出來。這與原始圖像不能平滑融合。

任何人都可以提供解決方案嗎?

Pinch Effect appears in a cut circular area instead of smoothly blended with original image

好,我知道解決..以下是最後的着色器獲得的收縮效應的平滑混合..

highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); 
highp float dist = distance(center, textureCoordinateToUse); 
textureCoordinateToUse = textureCoordinate; 

if (dist < radius) 
{ 
    textureCoordinateToUse -= center; 
    highp float percent = 1.0 + ((0.5 - dist)/0.5) * scale; 
    textureCoordinateToUse = textureCoordinateToUse * percent; 
    textureCoordinateToUse += center; 

    //modification start 
    highp vec2 textureCoordinateDiff = textureCoordinate - textureCoordinateToUse; 
    textureCoordinateToUse = textureCoordinateToUse + textureCoordinateDiff*(dist/radius); 
    //modification end 

    gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse); 
} 
else 
{ 
    gl_FragColor = texture2D(inputImageTexture, textureCoordinate); 
} 

回答

1

捏扭曲濾鏡使用以下片段着色器:

varying highp vec2 textureCoordinate; 

uniform sampler2D inputImageTexture; 

uniform highp float aspectRatio; 
uniform highp vec2 center; 
uniform highp float radius; 
uniform highp float scale; 

void main() 
{ 
    highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); 
    highp float dist = distance(center, textureCoordinateToUse); 
    textureCoordinateToUse = textureCoordinate; 

    if (dist < radius) 
    { 
     textureCoordinateToUse -= center; 
     highp float percent = 1.0 + ((0.5 - dist)/0.5) * scale; 
     textureCoordinateToUse = textureCoordinateToUse * percent; 
     textureCoordinateToUse += center; 

     gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse); 
    } 
    else 
    { 
     gl_FragColor = texture2D(inputImageTexture, textureCoordinate); 
    } 
} 

正如你所看到的那樣,當從效果的中心點到當前像素的距離小於效果的半徑大於該效果的半徑。這導致了扭曲區域和平面圖像之間的邊緣。

如果你想讓它具有更多的漸變效果,你可以用smoothstep()函數來修改上面的函數,以便更加緩和失真和正常區域之間的邊界。如果你這樣做,我很樂意接受這樣的拉動請求。

+0

嗨,布拉德..感謝您指導我到着色器區域。我做了修改,並最終得到它的工作。你可以在這個問題的編輯中看到最後的着色器。 – CodenameLambda1