[ad_1]
In a WebGL 2 GLSL fragment shader, one can’t entry the pre-existing coloration worth of the present pixel, i.e. the colour that’s already there within the framebuffer earlier than the pixel that’s presently calculated. I’m woundering how one can get round this limitation?
For occasion, as an instance that I need to do some coloration publish processing by operating a fraction shader on a quad masking the entire display. I’ll use gamma correction for example, however it could possibly be any arbitrary operate that takes a coloration for and return a brand new coloration. I wish to write code like this:
#model 300 es
precision highp float;
in vec2 uv;
out vec4 outColor;
void most important() {
vec4 currentColor = readPixel(uv)
outColor = pow(currentColor, vec3(1.0, 1.0, 1.0) / 2.2);
}
However, there isn’t a such operate as readPixel
, so I have no idea what coloration I’m attempting to gamma right. I can suppose of some approaches to deal with the issue:
- Leverage the mix modes. However, they’re fairly restricted (all are linear, I feel), and I do not suppose they’ll assist me right here.
- Include the publish processing in all fragment shaders. If all fragment shaders that put pixels on the display has the identical publish processing in-built on the finish, I need not do it in a separate go. But this complicates my code, since each single fragment shader is abruptly dependant upon my publish processing wants. It’s not a lot publish any extra.
- Use ping pong buffers. Render to at least one framebuffer, and skim the pixels from a texture belonging to a different framebuffer. The non-existing
readPixel
can then get replaced with the very a lot currenttexture
operate. However, this cannot be nice for efficiency since I’m principally copying the total body every body.
What is one of the best path ahead right here? Is there a fourth possibility that I’m lacking? Is there some established finest observe in a scenario like this?
[ad_2]