【发布时间】:2013-01-16 19:54:33
【问题描述】:
我正在使用 WebGL 在我正在开发的应用程序中快速调整图像客户端的大小。我编写了一个 GLSL 着色器,它对我要缩小的图像执行简单的双线性过滤。
它在大多数情况下都可以正常工作,但在很多情况下调整大小会很大,例如从 2048x2048 图像缩小到 110x110 以生成缩略图。在这些情况下,质量很差而且过于模糊。
我目前的 GLSL 着色器如下:
uniform float textureSizeWidth;\
uniform float textureSizeHeight;\
uniform float texelSizeX;\
uniform float texelSizeY;\
varying mediump vec2 texCoord;\
uniform sampler2D texture;\
\
vec4 tex2DBiLinear( sampler2D textureSampler_i, vec2 texCoord_i )\
{\
vec4 p0q0 = texture2D(textureSampler_i, texCoord_i);\
vec4 p1q0 = texture2D(textureSampler_i, texCoord_i + vec2(texelSizeX, 0));\
\
vec4 p0q1 = texture2D(textureSampler_i, texCoord_i + vec2(0, texelSizeY));\
vec4 p1q1 = texture2D(textureSampler_i, texCoord_i + vec2(texelSizeX , texelSizeY));\
\
float a = fract( texCoord_i.x * textureSizeWidth );\
\
vec4 pInterp_q0 = mix( p0q0, p1q0, a );\
vec4 pInterp_q1 = mix( p0q1, p1q1, a );\
\
float b = fract( texCoord_i.y * textureSizeHeight );\
return mix( pInterp_q0, pInterp_q1, b );\
}\
void main() { \
\
gl_FragColor = tex2DBiLinear(texture,texCoord);\
}');
TexelsizeX 和 TexelsizeY 分别只是(1.0 / 纹理宽度)和高度...
我想实现更高质量的过滤技术,理想情况下是 [Lancosz][1] 过滤器,它应该会产生更好的结果,但我似乎无法理解如何使用 GLSL 实现算法,因为我是新手一般适用于 WebGL 和 GLSL。
谁能指出我正确的方向?
提前致谢。
【问题讨论】:
标签: javascript glsl webgl