我有一个片段着色器,我想构建一个小型查找表并在其上进行插值。我当前的代码是这样的(抱歉冗长):
float inverse_f(float r)
{
// Build a lookup table on the radius, as a fixed-size table.
// We will use a vec3 since we will store the multipled number in the Z coordinate.
// So to recap: x will be the radius, y will be the f(x) distortion, and Z will be x * y;
vec3[32] lut;
// Flame has no overflow bbox so we can safely max out at the image edge, plus some cushion
float max_r = sqrt((adsk_input1_aspect * adsk_input1_aspect) + 1) + 0.1;
float incr = max_r / 32;
float lut_r = 0;
float f;
for(int i=0; i < 32; i++) {
f = distortion_f(lut_r);
lut[i] = vec3(lut_r, f, lut_r * f);
lut_r += incr;
}
float df;
float dz;
float t;
// Now find the nehgbouring elements
for(int i=0; i < 32; i++) {
if(lut[i].z < r) {
// found!
df = lut[i+1].y - lut[i].y;
dz = lut[i+1].z - lut[i].z;
t = (r - lut[i].z) / dz;
return df * t;
}
}
}
我正在使用#version 120。但是它不起作用(调用此函数的所有迭代都返回相同的值)。所以要么我对数组做错了(它被填充了相同的值),要么for循环的返回不起作用,因为循环以某种我不理解的方式展开。有没有什么东西会引起这种行为(独立于传入的 R 值返回的相同值)?