|
Help translating from GLSL to Core Image KernelHi, I've created a patch using my GLSL code where i use a inout image and a small lookup image. On my GLSL, i get the value of the lookup pixel by using a mod function that is the size of the lookup. In oder words, for destination pixel at 1,1 i will use the pixel from lookup at 1,1. For a destination of 5,5 again 1,1 as my lookup is a 5x5 bitmap. Here is my GLSL code: uniform sampler2DRect u_image; uniform sampler2DRect u_lookup; varying vec2 v_texCoord; void main() { float xx = mod(gl_FragCoord.x,5.0); float yy = mod(gl_FragCoord.y,5.0); vec4 lookup1 = texture2DRect(u_lookup, vec2(xx,yy)); vec4 color1 = texture2DRect(u_image,vec2(v_texCoord.s,v_texCoord.t)); gl_FragColor = lookup1 * color5 ; } This is working perfectly and the result is what i expect. Now, i've simply translated it to core image kernel: float mod(float x, float y) { int division = int(x / y); float result = float(division) * y - x; return result; } kernel vec4 coreImageKernel(sampler u_image, sampler u_lookup) { vec2 gl_FragCoord = destCoord(); vec2 v_texCoord = samplerCoord(u_image); float xx = mod(gl_FragCoord.x,5.0); float yy = mod(gl_FragCoord.y,5.0); vec4 color1 = sample(u_image, v_texCoord); vec4 lookup1 = sample(u_lookup, vec2(xx, yy)); color.a = 1.0; return color * lookup1; } I guess sample does not work like texture2DRect and I can't find the documentation where it explains exactly what sample does. I've tried to define u_lookup with __table sampler but it still does not work correctly. Perhaps is the way i'm feeding the image wrong? I'm using a windows BMP for the lookup. 5x5 pixels. Any help highly apreciated.
|