Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

android - Is there a way in Opengl es 2.0 fragment shader, to get a previous fragment color

My code is drawing a background image and drawing some other images (particles) on top of that image. I want to make the particles have some blending effects, like darken, lighten, burn ... the same as Canvas globalcompositeoperation does . So in the fragment shader, i need to get the previous fragment color and blend it with the new color. But i could not find a way to do it.

question from:https://stackoverflow.com/questions/65642257/is-there-a-way-in-opengl-es-2-0-fragment-shader-to-get-a-previous-fragment-colo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...