- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码正在绘制背景图像并在该图像之上绘制一些其他图像(粒子)。我想让粒子有一些混合效果,比如变暗、变亮、燃烧……就像 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/
我是一名优秀的程序员,十分优秀!