4

I am using Following CIColorKernel Code to generate customFilter.

 kernel vec4 customFilter(__sample image, __sample noise, float time, float inputNoise) { 
 vec2 uv = destCoord() / 1280.0; 
 float d = length(uv - vec2(0.5,0.5));

 float blur = inputNoise; 
 float myTime = time * 1.0;

 vec2 myuv =  vec2(uv.x + sin( (uv.y + sin(myTime)) * abs(sin(myTime) + sin(2.0 * myTime) + sin(0.3 * myTime) + sin(1.4 * myTime) + cos(0.7 * myTime) + cos(1.3 * myTime)) * 4.0 ) * 0.02,uv.y) ;

 vec2 finalUV = myuv * 1280.0; 
 vec3 col; col.r = sample(image, samplerTransform(image, finalUV)).r; col.g = sample(image, samplerTransform(image, finalUV)).g; col.b = sample(image, samplerTransform(image, finalUV)).b;

 float scanline = sin(uv.y * 1280.0 *400.0)*0.08; col -= scanline;

// vignette
 col *= 1.0 - d * 0.5;

 return vec4(col, 1.0); 
}

this piece of code works fine with iOS 10 / iOS 11 devices, However. It generate weird crash with iOS 12 Device

[CIKernelPool] 16:40: ERROR: parameter has unexpected type 'vec4' (should be a sampler type) col.r = sample(image, samplerTransform(image, finalUV)).r;

[CIKernelPool] 17:40: ERROR: parameter has unexpected type 'vec4' (should be a sampler type) col.g = sample(image, samplerTransform(image, finalUV)).g;

[CIKernelPool] 18:40: ERROR: parameter has unexpected type 'vec4' (should be a sampler type) col.b = sample(image, samplerTransform(image, finalUV)).b;

this seem to happen in all CIColorKernel using __sample. However using sampler in place of __sample and coverting CIColorKernel to CIKernel solves the crash but it doesn't generating the expected result.

Abhishek Dave
  • 326
  • 1
  • 14
  • What's the desired effect? I put together a very simple example - a single image used as both inputs and a float "0" as both float inputs and yes, a `CIColorKernel` "worked" in iOS 11 but iOS 12 caught the fact that it needs to be either a `CIWarpKernel` or `CIKernel`. And yes, you *need* to make the input be a sampler type. It "worked" in iOS 12. Here's the odd thing - color kernels only work on a **single** pixel at a time, and your code is expecting to have access to surrounding pixels. (1) How could it work as a color kernel? (2) As a generic kernel, it "skews" the image in both iOS 11/12. –  Oct 03 '18 at 12:38
  • In other words, it should have crashed in *all* versions of iOS! :-) If you explain what the desired effect is - along with some input examples - I'll see if I can help. –  Oct 03 '18 at 12:39

1 Answers1

2

As the error stated, you are supplying wrong object to the

sample(image, samplerTransform(image, finalUV)).r

Here image is of type __sample. But it actually requires sampler type.

CIColorKernel does expect __sample type in its parameters. Thus, what you need is to use CIKernel instead of CIColorKernel. Then you can supply sampler in your kernel.

 kernel vec4 customFilter(sampler image, sampler noise, float time, float inputNoise) {
GeneCode
  • 7,545
  • 8
  • 50
  • 85
  • converting CIColorKernel to CIkernel do solves my problem. but what confuses me is that why the same piece of code works perfectly fine with iOS 10,11 devices. the code stucks only on iOS 12 device. – Abhishek Dave Nov 16 '18 at 08:49