V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
liuliupet
V2EX  ›  程序员

分享一个我厂 iOS 程序员写的水纹滤镜源码

  •  
  •   liuliupet · Apr 1, 2015 · 6253 views
    This topic created in 4052 days ago, the information mentioned may be changed or developed.
    17 replies    2015-04-21 14:32:33 +08:00
    wzyuliyang
        1
    wzyuliyang  
       Apr 1, 2015
    GPU?????
    kepenj
        2
    kepenj  
       Apr 1, 2015
    感谢分享
    sincway
        3
    sincway  
       Apr 1, 2015
    看起来很不错的样子
    PP
        4
    PP  
       Apr 1, 2015 via iPad   ❤️ 1
    好逼真,我还以为我的屏幕出了问题。
    liuliupet
        5
    liuliupet  
    OP
       Apr 1, 2015
    @wzyuliyang OpenGLES
    liuliupet
        6
    liuliupet  
    OP
       Apr 1, 2015
    @sincway 在准备做一个哈哈镜的App
    sumhat
        7
    sumhat  
       Apr 1, 2015
    目测源码里有一堆 double 型常量,你们厂只能祈祷那个程序员不要离职了....
    lzsadam
        8
    lzsadam  
       Apr 1, 2015
    猛一看还以为阿森纳有iOS程序员。
    zhangchioulin
        9
    zhangchioulin  
       Apr 1, 2015
    好逼真!!
    sophymax
        10
    sophymax  
       Apr 1, 2015 via iPad
    那用的是个什么库,GPUImage开头的那一堆?看到这个第一感觉是写的opengl shader,但打眼一看好像没shader文件,只有一堆GPUimagexxxxxx文件
    ryd994
        11
    ryd994  
       Apr 1, 2015 via Android
    @sumhat 求问double常量是什么坑?
    sumhat
        12
    sumhat  
       Apr 1, 2015   ❤️ 1
    @ryd994 就是形如这样的代码,摘录自楼主的 Github。一点注释都没有,后人完全没办法维护。

    void main()
    {
    vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
    vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);

    float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b;
    float maskCr = 0.7132 * (colorToReplace.r - maskY);
    float maskCb = 0.5647 * (colorToReplace.b - maskY);

    float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b;
    float Cr = 0.7132 * (textureColor.r - Y);
    float Cb = 0.5647 * (textureColor.b - Y);

    // float blendValue = 1.0 - smoothstep(thresholdSensitivity - smoothing, thresholdSensitivity , abs(Cr - maskCr) + abs(Cb - maskCb));
    float blendValue = 1.0 - smoothstep(thresholdSensitivity, thresholdSensitivity + smoothing, distance(vec2(Cr, Cb), vec2(maskCr, maskCb)));
    gl_FragColor = mix(textureColor, textureColor2, blendValue);
    }
    theoractice
        13
    theoractice  
       Apr 2, 2015   ❤️ 1
    liyonghelpme
        14
    liyonghelpme  
       Apr 2, 2015
    学shader 上这个网站哈哈 有一起玩得同学没 https://www.shadertoy.com/
    magicianzrh
        15
    magicianzrh  
       Apr 2, 2015
    kepenj
        16
    kepenj  
       Apr 2, 2015
    theoractice
        17
    theoractice  
       Apr 21, 2015
    @sumhat 那些常量是色彩空间转换公式里用到的。RGB转灰度时也会用到类似的常量。
    科学家研究的结果,不需要改~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4794 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 141ms · UTC 01:09 · PVG 09:09 · LAX 18:09 · JFK 21:09
    ♥ Do have faith in what you're doing.