FxCore lets you create Core Image filters through the Custom Kernel and Custom Shader nodes:
Custom Kernel uses the Core Image Kernel Language, whereas Custom Shader is based on the newer Metal Shading Language for Core Image Kernels.
Regardless of the language used, any sampler argument to the kernel is populated with the contents of its corresponding image input.
Initially, each sampler is configured using default options picked by Core Image: values are sampled using linear interpolation, and sampling from coordinates outside the sampler region return transparent black. The default behavior also guarantees that all color values are converted to the working color space. In other words, regardless of the original color space used by your image data, all values you sample from within your kernel are expressed in terms of the working color space.
You can enable other behaviors by enabling the Customize filtering, region of interest and color space conversion option:
When that option is enabled, every sampler gets additional inputs beyond the image input:
There are different techniques to specify a custom region-of-interest for each sampler:
When passing a vector to the ROI Rectangle input, the ROI insets and transform are ignored. The ROI Rectangle input effectively overrides the others.
While insets and transforms are applied to the current tile rectangle, the vector you pass to the ROI Rectangle input is used as-is. This behavior makes sense for lookup tables and certain geometric distortions that cannot be made to support tiling.
The Wrapping input let you select between Transparent Black (the default behavior for all Core Image samplers) and Clamp to Edge.
When Transparent Black is selected, if your kernel samples any values outside the sampler region available when processing the current tile, transparent black is returned.
When Clamp to Edge is selected, if your kernel samples any values outside the sampler region available when processing the current tile, the closest available sample values are returned, i.e. the closest edge.
The Filtering input lets you specify how color values are sampled for any given coordinates:
Linear is the default behavior for all Core Image samplers, and it samples values from up to two pixels, interpolating between them based on the distance of your sampling coordinate from the center of each pixel.
Nearest forces the sampler to only ever sample from one pixel, determined by closest distance from your sampling coordinates.
By default, Core Image transparently converts any values in your sampler to the working color space. Unless the working color space has been customized, this corresponds to a linear RGB color space (refer to Core Image docs for more information).
Core Image defaults to a working color space based on a linear RGB color profile. This is the appropriate decision for the vast majority of effects. FxCore allows you to customize the working color space for all kernels and filters in the composition by customizing the current environment.
It may be helpful in some cases to prevent or control the color conversion process for each sampler. FxCore gives you three dynamic choices for your color space conversion:
All other options allow you to convert sampler color values to a specific color space, such as sRGB or sRGB Linear. The list of color spaces advertised by FxCore varies from one version to another, but any color space you choose will continue to be used even if it is no longer listed.
Output Color Space
The options above instruct Core Image to let you sample values from any given sampler in a specific color space, but please remember that your output is still expected to be expressed in terms of the working color space. If you wish to both sample values in a specific color space, and have your kernel output color information in the same color space, you need to customize the output color space of your kernel separately:
Core Image also supports simplified kernels that only manipulate one color value at a time. Such Color Kernels do not require any sampler options at all, since the kernel function is only given one set of RGBA values for the current pixel being rendered at its destination coordinate.
When editing a kernel based on the Core Image Kernel Language, FxCore will automatically switch to using color kernels when you replace the sampler
keyword with __sample
:
Notice that the __sample
argument is accessed by your kernel as any other vec4
variable.