使用查找数据处理着色器 IOS

Working with shaders using lookup data IOS

我有一个软件提供的查找数据,我想将此数据与着色器一起使用,如下所示:

7999745,8000001,8000258,8066051,8066308,8132357,8132614,8198407,8198664,8264457,8264969,8330762,8331019,8396812,8397069,8463118,8463375,8529168,8529425,8595218,8595730,8661523,8661780,8727573,8727830,8793879,8794136,8859929,8860186,8925979,8926491,8992284,8992541,9058334,9058591,9059104,9124897,9125154,9190947,9191204,9257252,9257509,9323302,9323559,9389352,9389865,9455658,9455915,9521708,9521965,9588013,9588270,9654063,9654320,9720113,9720626,9786419,9786676,9852469,9852726,9918774,9919031,9984824,9985081,10050874,10051387,10117180,10117437,10183230,10183743,10183999,10249792,10250049,10315842,10316355,10382148,10382405,10448198,10448455,10514503,10514760,10580553,10580810,10646603,10647116,10712909,10713166,10778959,10779216,10845264,10845521,10911314,10911571,10977364,10977877,11043670,11043927,11109720,11109977,11176025,11176282,11242075,11242332,11308125,11308638,11308895,11374688,11374945,11440738,11441250,11507043,11507300,11573093,11573350,11639399,11639656,11705449,11705706,11771499,11772011,11837804,11838061,11903854,11904111,11970160,11970417,12036210,12036467,12102260,12102772,12168565,12168822,12234615,12234872,12300921,12301178,12366971,12367228,12433277,12433278,12433535,12433536,12433793,12499330,12499587,12499588,12499845,12565382,12565639,12565896,12565897,12566154,12631691,12631948,12631949,12632206,12697743,12698000,12698001,12698258,12698515,12764052,12764310,12764311,12764568,12830105,12830362,12830363,12830620,12830621,12896414,12896671,12896672,12896929,12962466,12962723,12962724,12962981,12962982,13028775,13028776,13029033,13029290,13094827,13095084,13095086,13095343,13095344,13161137,13161138,13161395,13161396,13227189,13227446,13227447,13227704,13227705,13293498,13293499,13293756,13293757,13359550,13359807,13359808,13360065,13360066,13425859,13425860,13426117,13426119,13491912,13491913,13492170,13492427,13492428,13558221,13558222,13558479,13558480,13624273,13624274,13624531,13624532,13624789,13690582,13690583,13690840,13690841,13756634,13756635,13756892,13756893,13757151,13822688,13822945,13823202,13823203,13888996,13888997,13889254,13889255,13889512,13955049,13955306,13955307,13955564,14021357,14021358,14021615,14021616,14021873,14087410,14087667,14087668,14087925,14153719  

片段着色器代码:

precision highp float;

 uniform sampler2D inputImageTexture;
 uniform sampler2D inputImageTexture2;
 varying vec2 textureCoordinate;
 uniform float uAmount;

 void main() {
     vec4 color = texture2D(inputImageTexture, textureCoordinate);
     vec2 pos = vec2((color.r + color.g + color.b)/ 3.0, 0.0);
     vec4 dstColor = texture2D(inputImageTexture2, pos);

     gl_FragColor = mix(
                        color,
                        dstColor,
                        uAmount);
 }  

帮我把这个数据传给sampler2D inputimageTexture2
我认为这些应该以某种方式转换为 rgb(图像纹理),因此我可以将其传递给 sampler2D。

我认为查找 table 是 1 通道和 2D(16x16?)。

您可以尝试使用 glTexImage2D 将其上传为 GL_FLOATGL_LUMINANCEGL_ALPHA 和你的着色器将成为

vec4 color = texture2D(inputImageTexture, textureCoordinate).xxxx // GL_LUMINANCE

vec4 color = texture2D(inputImageTexture, textureCoordinate).aaaa // GL_ALPHA

这个问题被标记为 GPUImage,我根本不知道(所以下面的内容可能是完全错误的!),但我想它管理自己的纹理,所以你可能不得不问它使 LUT 可用于您的着色器。查看源代码,GPUImageRawDataInput 看起来是开始查找 table 到 GPUImage 的好地方,可能使用类似

的东西
GPUImageRawDataInput *rawInput =
    [[GPUImageRawDataInput alloc] initWithBytes:yourTable 
                                           size:CGSizeMake(16, 16)
                                    pixelFormat:GPUPixelFormatLuminance 
                                           type:GPUPixelTypeFloat];

我找到了解决方案,这些查找数据是 32 位整数类型。
将 32 位整数转换为 RGB,然后将 RGB 数组作为纹理传递给着色器。