跳到主要内容
← Image Manipulation with Shaders

Image Manipulation with Shaders

Texel Size

shader-learning 自学第 10 课:Texel Size

实时渲染 · 纹理 GLSL

第 10 课:Texel Size

我的解

uniform vec2 iResolution;
uniform sampler2D iChannel0;
uniform vec2 iChannelSize0;

const float RADIUS = 3.0;

void main() {
  vec2 texCoord = gl_FragCoord.xy / iResolution.xy;
  vec2 texelSize = 1.0 / iChannelSize0;
  vec2 offX = vec2(RADIUS, 0.0) * texelSize;
  vec2 offY = vec2(0.0, RADIUS) * texelSize;

  vec2 uvt = texCoord + offY;
  vec2 uvr = texCoord + offX;
  vec2 uvb = texCoord - offY;
  vec2 uvl = texCoord - offX;

  vec4 c = texture(iChannel0, texCoord);
  vec4 t = texture(iChannel0, uvt);
  vec4 r = texture(iChannel0, uvr);
  vec4 b = texture(iChannel0, uvb);
  vec4 l = texture(iChannel0, uvl);

  vec4 newUV = (c+t+r+b+l) / 5.0;

  gl_FragColor = newUV;
}