简体   繁体   English

Opengl es 2.0片段着色器中有没有办法获得以前的片段颜色

[英]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.我想让粒子有一些混合效果,比如变暗、变亮、燃烧……就像Canvas 全局复合操作一样。 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.但我找不到办法做到这一点。

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):但是,通过扩展EXT_shader_framebuffer_fetch (非 Mali 设备)和ARM_shader_framebuffer_fetchMali设备),可以从帧缓冲区中读取一个值(从 OpenGL 2.0 开始,对于 OpenGL ES 2.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.它还可以用于将 function 应用到帧缓冲区颜色,方法是编写一个使用现有帧缓冲区颜色作为其唯一输入的着色器。

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 .另请参阅LearnOpenGL - 延迟着色

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 .可以使用glBlendFunc更改混合 function 并且可以使用glBlendEquation更改混合方程。

Yes it is possible.对的,这是可能的。 First, render result to the texturebuffer.首先,将结果渲染到纹理缓冲区。 Then send the texturebuffer to the second shader to apply the effects.然后将纹理缓冲区发送到第二个着色器以应用效果。

to find out how to do this, look for the keywords GLES20.glBindFramebuffer (GL_FRAMEBUFFER, mFramebuff);要了解如何执行此操作,请查找关键字 GLES20.glBindFramebuffer (GL_FRAMEBUFFER, mFramebuff);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过Android上的OpenGL ES 2.0的片段着色器更改颜色 - How to change color by fragment shader of OpenGL ES 2.0 on Android 顶点着色器或片段着色器中的OpenGL ES2.0 Lighting - OpenGL ES2.0 Lighting in the vertex shader or fragment shader 是否可以编写片段着色器以使模型边缘在OpenGL ES 2.0中变为不同的颜色? - Is it possible to write a fragment shader that can make the model edge a different color in OpenGL ES 2.0? OpenGL ES 2.0:片段着色器中的Alpha值将被忽略(使用glReadPixels()) - OpenGL ES 2.0: Alpha value in fragment shader is ignored (using glReadPixels()) 在iOS的OpenGL ES 2.0片段着色器中可能对代码进行了优化 - Code possibly optimized away in OpenGL ES 2.0 Fragment Shader on iOS OpenGL ES 2.0尝试将浮点值传递给片段着色器Android - Opengl es 2.0 trying to pass a float value to fragment shader android Android 2.3-无法编译openGL 2.0 ES片段着色器 - Android 2.3 - cant compile openGL 2.0 ES fragment shader 计算片段着色器(OpenGL ES 2.0)中一行的平均值 - Calculate mean of a row in the fragment shader (OpenGL ES 2.0) OpenGL ES 2.0 SL从片段着色器写入纹理 - OpenGL ES 2.0 SL writing out from fragment shader to texture Android OpenGL ES片段着色器使输出颜色混乱 - Android OpenGL ES fragment shader messing output color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM