No, there is no possibility within the standard. However, with the extensions EXT_shader_framebuffer_fetch (non-Mali devices) and ARM_shader_framebuffer_fetch (Mali devices) a value from the framebuffer can be read (since OpenGL 2.0 and for OpenGL ES 2.0 / 3.0):
This extension provides a mechanism whereby a fragment shader may read existing framebuffer data as input. This can be used to implement compositing operations that would have been inconvenient or impossible with fixed-function blending. It can also be used to apply a function to the framebuffer color, by writing a shader which uses the existing framebuffer color as its only input.
Note that there is no guarantee that hardware will support an extension. You need to test whether the extension is supported or not at runtime.
If you want to read fragments from the previous rendering, the usual way is to implement multiple rendering passes and render to a texture. See also LearnOpenGL - Deferred Shading.
In many cases, there is no need to read fragments in the fragment shader. A lot of rendering effects can be implemented using the standard Blending functionality. The blend function can be changed with glBlendFunc
and the blend equation can be changed with glBlendEquation
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…