Matt
Matt

Reputation: 1599

GPUImageLookupFilter with intensity control?

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);
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.

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?

Upvotes: 0

Views: 685

Answers (1)

Brad Larson
Brad Larson

Reputation: 170319

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.

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.

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.

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.

Upvotes: 2

Related Questions