我从这篇文章中得到了这个 biqubic 着色器,但由于 vec2 错误识别问题,它无法在我的 glsl 代码中运行,我找不到答案
编译 FRAGMENT_SHADER 时出错:错误:0:44:“=”:无法从“int 的 highp 2 分量向量”转换为“float 的 highp 2 分量向量”
// from http://www.java-gaming.org/index.php?topic=35123.0
vec4 cubic(float v){
vec4 n = vec4(1.0, 2.0, 3.0, 4.0) - v;
vec4 s = n * n * n;
float x = s.x;
float y = s.y - 4.0 * s.x;
float z = s.z - 4.0 * s.y + 6.0 * s.x;
float w = 6.0 - x - y - z;
return vec4(x, y, z, w) * (1.0/6.0);
}
vec4 textureBicubic(sampler2D sampler, vec2 texCoords){
/// next line is there the issue is
vec2 texSize = textureSize(sampler, vec2(0.0, 0.0)).rg;
vec2 invTexSize = 1.0 / texSize;
texCoords = texCoords * texSize - 0.5;
vec2 fxy = fract(texCoords);
texCoords -= fxy;
vec4 xcubic = cubic(fxy.x);
vec4 ycubic = cubic(fxy.y);
vec4 c = texCoords.xxyy + vec2 (-0.5, +1.5).xyxy;
vec4 s = vec4(xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw);
vec4 offset = c + vec4 (xcubic.yw, ycubic.yw) / s;
offset *= invTexSize.xxyy;
vec4 sample0 = texture(sampler, offset.xz);
vec4 sample1 = texture(sampler, offset.yz);
vec4 sample2 = texture(sampler, offset.xw);
vec4 sample3 = texture(sampler, offset.yw);
float sx = s.x / (s.x + s.y);
float sy = s.z / (s.z + s.w);
return mix(
mix(sample3, sample2, sx), mix(sample1, sample0, sx)
, sy);
}
从纹理中获取 xy 分量textureSize(sampler, vec2(0.0, 0.0)).rg;
当使用带有
textureSize()
的函数时,ivec2
的返回值为 sampler2D
。而且参数化也不正确(lod
是一个整数值)。应该是:
ivec2 texSize = textureSize(sampler, 0);
如果您需要浮点向量,请执行以下操作:
vec2 texSize = vec2(textureSize(sampler, 0));