GPUImageLookupFilter具有强度控制? [英] GPUImageLookupFilter with intensity control?

查看:227
本文介绍了GPUImageLookupFilter具有强度控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目使用Brad Larson的GPUImage框架. 我试图找到一种方法来实现对GPUImageLookupFilter的强度控制,并且遇到了 https://github.com/BradLarson/GPUImage/issues/1485

I am using Brad Larson's GPUImage framework for my project. I was trying to find a way to implement intensity control to GPUImageLookupFilter and came across https://github.com/BradLarson/GPUImage/issues/1485

gl_FragColor = mix(textureColor,vec4(vec3(newColor),1.0),mixTexture);
"textureColor"是原始纹理,"newColor"是LookupFilter结果,mixTexture是Alpha值,为(0〜1.0),您可以将其视为强度变量.

gl_FragColor = mix(textureColor, vec4(vec3(newColor),1.0), mixTexture);
the "textureColor" is the original texture, and "newColor" is the LookupFilter result, and mixTexture is the Alpha value which is (0 ~ 1.0), you can think it as intensity variable.

我不知道该如何实现, 我不知道如何实现OpenGL着色器.谁能告诉我在哪里添加此代码以实现对GPUImageLookupFilter的强度控制?

I do not know how to implement this, I have no knowledge of how to implement OpenGL shaders. Could anyone tell me where to add this code to implement intensity control to GPUImageLookupFilter?

推荐答案

每个GPUImage过滤器都有自己的片段着色器.这些在该过滤器的.m文件顶部定义为字符串常量.对于GPUImageLookupFilter,这是GPUImageLookupFilter.m顶部的kGPUImageLookupFragmentShaderString.

Every GPUImage filter has its own fragment shader. These are defined at the top of the .m file for that filter as string constants. In the case of GPUImageLookupFilter, that's the kGPUImageLookupFragmentShaderString at the top of GPUImageLookupFilter.m.

这些片段着色器是类似于C的程序,与标准C相比,它们具有一些独特的属性,但是一旦您看到了一些示例,它们仍然应该相当容易地遵循.

These fragment shaders are C-like programs that have a few unique attributes when compared to standard C, but should still be reasonably easy to follow once you've seen a few examples.

正如该问题中指出的那样,如果您想要这种强度控件(出于性能原因,默认情况下不包括在内),则需要创建一个新的过滤器类,并从中复制代码GPUImageLookupFilter放入其中(除了片段着色器之外,几乎没有).片段着色器有两种版本,一种用于Mac(通常不带精度限定符),另一种用于iOS.在这两者的底部都有一行输出最终颜色的线.您将需要对其进行修改,以使用上述的mix()操作.

As was pointed out in that issue, if you want this kind of an intensity control (which I don't include by default for performance reasons), you'll want to create a new filter class and copy over the code from GPUImageLookupFilter into it (of which there is little beyond the fragment shader). There are two versions of the fragment shader, one for Mac (generally just without the precision qualifiers) and one for iOS. At the bottom of both of those is a line that outputs the final color. You'll want to modify that to use a mix() operation like is described above.

如果您不想对强度值进行硬编码,则还需要添加一个属性来调整此强度值.为此,您需要在片段着色器中设置一个匹配的统一体以使用此属性.在GPUImageBrightnessFilter上查找与片段着色器中的统一匹配的属性的简单示例.

You'll also need to add a property to adjust this intensity value, if you don't want to hardcode an intensity value. For that, you'll need to set up a matching uniform in the fragment shader to take in this property. Look at the GPUImageBrightnessFilter for a simple example of a property that matches to a uniform in a fragment shader.

我建议您仔细阅读为各种过滤器提供的片段着色器代码,以了解它们是如何编写的以及它们是如何工作的.大多数人只需检查框架中已经存在的各种着色器就可以了解基础知识.

I'd recommend looking through the fragment shader code provided for the various filters, to see how these are written and how they work. Most people are able to pick up the fundamentals just by examining the various shaders already in the framework.

这篇关于GPUImageLookupFilter具有强度控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆