OpenGL学习笔记-Blending

  混合方程中,Csource是片段着色器输出的颜色向量(the color output of the fragment shader),其权重为Fsource。Cdestination是当前存储在color buffer中的颜色向量(the color vector that is currently stored in the color buffer),其权重为Fdestination。Csource和Cdestination由OpenGL自动设置,但Fsource和Fdestination需要由我们进行设置(The source and destination colors will automatically be set by OpenGL, but the source and destination factor can be set to a value of our choosing)。当OpenGL渲染一个片段时,会根据混合方程对上述两个颜色向量进行加权组合(whenever OpenGL renders a fragment, it combines the current fragment's color with the fragment color currently in the color buffer),Cresult是加权组合后的结果,将保存到color buffer中,并且会将Cdestination覆盖掉。

  要想实现混合的效果,需要先使能混合:

cpp 复制代码
glEnable(GL_BLEND);

  然后设置混合方程中的Fsource和Fdestination,一种常用的设置如下:

cpp 复制代码
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glBlendFunc函数的原型如下,上述设置的含义是:Fsource取Csource的alpha分量,Fdestination取(1-Csource的alpha分量)。

cpp 复制代码
void glBlendFunc(GLenum sfactor, GLenum dfactor);

  完成渲染后,需要将混合关闭:

cpp 复制代码
glDisable(GL_BLEND);

  一个简单的例子:图1是待混合的两个片段,图2是混合方程,图3是混合得到的结果。


相关推荐
烧酒同学12 小时前
【C++】记录size of std::vector的巧妙坑
开发语言·c++·图形渲染
玖釉-18 小时前
nvpro_core2 源码与架构解析:NVIDIA Vulkan 图形开发基础框架
c++·windows·图形渲染
SNAKEpc121386 天前
OpenGL(十六)- 着色器统一值
c语言·c++·线性代数·算法·矩阵·图形渲染·着色器
SNAKEpc121386 天前
OpenGL(十三)- Mip贴图
c语言·c++·图形渲染·贴图
SNAKEpc121387 天前
OpenGL(十五)- 着色器语言GLSL
c语言·c++·线性代数·算法·矩阵·图形渲染·着色器
郝学胜-神的一滴11 天前
中级OpenGL教程 030:gl_FragCoord解锁区域渲染与深度可视化新姿势
c++·unity·游戏引擎·图形渲染·unreal engine·opengl
SNAKEpc1213812 天前
OpenGL(十一)- 变换管线
c语言·c++·算法·矩阵·图形渲染
anxiao_m14 天前
数字孪生3D可视化有哪些?主流实时渲染平台深度测评
图形渲染·3dcoat
NutShell Wang15 天前
每帧重建整条路径、每秒倾倒 48MB 给 GC:实时折线图渲染架构的实测复盘
前端·性能优化·架构·图形渲染·数据可视化·vibe coding
噗噗夹的TA之旅17 天前
Shader 学习 21:自定义 Render Feature
学习·游戏·unity·c#·游戏引擎·图形渲染