ios - 将强度参数添加到 GPUImageFalseColorFilter

标签 ios objective-c opengl-es gpuimage

查看底部的更新


看起来 GPUImageFalseColorFilter 是从另一个滤镜复制的 - 我可以在着色器中看到强度属性,尽管它实际上没有做任何事情。我已经为它添加了 setter 和 Obj-c 包装器,但现在我似乎无法获得 gl_fragColor 返回值以将强度作为参数。

这是使用 100% 强度的着色器:

 precision lowp float;

 varying highp vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;
 uniform lowp float intensity;
 uniform vec4 shadowTintColor;
 uniform vec4 highlightTintColor;

 const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);

 void main()
 {
     lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
     float luminance = dot(textureColor.rgb, luminanceWeighting);

     gl_FragColor = vec4( mix(shadowTintColor.rgb, highlightTintColor.rgb, luminance), textureColor.a);
 }
 );

我试过:

gl_FragColor = vec4( mix(shadowTintColor.rgb, highlightTintColor.rgb, luminance), intensity);
gl_FragColor = mix(textureColor, mix(shadowTintColor.rgb, highlightTintColor.rgb, luminance), intensity);

和其他一些,但过滤器崩溃并出现大量错误(No matching function for call to mix(vec4, vec3, float), Too many arguments to constructor of 'vec4').

我怎样才能获得强度属性?

为了加分,原始过滤器被编写为将 vec4 色调颜色作为输入,但在过滤器中仅使用 vec3 色调颜色。除了全局“强度”属性之外,我还想在每个单独的色调颜色上支持一个 alpha channel 。


更新:

在这方面取得了一些重大进展 - 它现在接受像这样的个人强度参数:

 precision lowp float;

 varying highp vec2 textureCoordinate;

 uniform sampler2D inputImageTexture;
 uniform lowp float shadowTintIntensity;
 uniform lowp float highlightTintIntensity;
 uniform vec4 shadowTintColor;
 uniform vec4 highlightTintColor;

 const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
 {
    lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
    highp float luminance = dot(textureColor.rgb, luminanceWeighting);
    highp vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity);
    highp vec4 mixedResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity / 3.0);

    gl_FragColor = mixedResult;
 }
 );

我现在可以让它通过强度适本地影响图像,但在亮度加权方面似乎有点偏差?我在高光计算器上手动添加了一个 /3.0 乘数,它似乎平衡了阴影和高光强度效果,但这并不是正确的方法。 编辑:这甚至根本无法将它们正确地混合在一起 - 如果未指定 highlightTint,则效果不起作用。

如何正确地将最终图像混合在一起?

最佳答案

最终通过使用 mix 并将两个结果与亮度常数混合来实现:

vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
float luminance = dot(textureColor.rgb, luminanceWeighting);

vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity);
vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity);

gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a);
//                            ^                   ^

关于ios - 将强度参数添加到 GPUImageFalseColorFilter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32959107/

相关文章:

android - 是否可以将 Google Play 游戏服务实时多人游戏集成到适用于 Android 和 iOS 的 LibGDX 中?

ios - 从 iPhone 应用程序在 Facebook 'feed' 上发布图片

ios - 如何将 AVAudioRecorder 本地实例设置为 Property 以使其保持保留状态?

objective-c - 在 Objective-C 中将 float 转换为 int

ios - 如何在 UIView 和另一个线程之间共享 CVOpenGLESTextureCache?

ios - CMMotionManager vs UIAccelerometer 效率

ios - 应用程序卸载/重新安装后 CoreData + Cloudkit fetch() 不返回任何结果

ios - Objective C 递归调用

Android 在多边形上绘制位图

ios - 场景套件: Use multiple SCNView instances side by side