How to get pixel information inside a fragment shader?

前端 未结 2 1015
误落风尘
误落风尘 2021-02-01 16:26

In my fragment shader I can load a texture, then do this:

uniform sampler2D tex;

void main(void) {
   vec4 color = texture2D(tex, gl_TexCoord[0].st);
   gl_Frag         


        
2条回答
  •  无人共我
    2021-02-01 17:25

    Easy peasy.

    Just compute the size of a pixel based on resolution. Then look up +1 and -1.

    vec2 onePixel = vec2(1.0, 1.0) / u_textureSize;
    gl_FragColor = (
       texture2D(u_image, v_texCoord) +
       texture2D(u_image, v_texCoord + vec2(onePixel.x, 0.0)) +
       texture2D(u_image, v_texCoord + vec2(-onePixel.x, 0.0))) / 3.0;
    

    There's a good example here

提交回复
热议问题