gpt4 book ai didi

android - 在 Opengl es 2.0 fragment 着色器中有没有办法获得以前的 fragment 颜色

转载 作者:行者123 更新时间:2023-12-04 02:28:41 26 4
gpt4 key购买 nike

我的代码正在绘制背景图像并在该图像之上绘制一些其他图像(粒子)。我想让粒子有一些混合效果,比如变暗、变亮、燃烧……就像 Canvas globalcompositeoperation 做的一样。所以在 fragment 着色器中,我需要获取之前的 fragment 颜色并将其与新颜色混合。但我找不到办法。

最佳答案

不,标准内不可能。但是,使用扩展名 EXT_shader_framebuffer_fetch (非马里设备)和 ARM_shader_framebuffer_fetch (Mali 设备)可以读取帧缓冲区中的值(自 OpenGL 2.0 和 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.

请注意,不能保证硬件将支持扩展。您需要在运行时测试扩展是否受支持。

如果你想从之前的渲染中读取 fragment ,通常的做法是实现多个渲染 channel 并渲染到一个纹理上。另见 LearnOpenGL - Deferred Shading .

在很多情况下,片元着色器中不需要读取片元。使用标准 Blending 可以实现很多渲染效果功能。可以使用 glBlendFunc 更改混合功能混合方程可以用 glBlendEquation 改变.

关于android - 在 Opengl es 2.0 fragment 着色器中有没有办法获得以前的 fragment 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65642257/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com