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是混合得到的结果。


相关推荐
_Emma_4 天前
【DRM&Graphic】Linux图形与显示框架
linux·驱动开发·图形渲染·显示器
算力百科小星5 天前
2026 算力平台测评:智星云、Vast.ai、Lambda Labs 口碑与实力对比
图形渲染·gpu算力·gpu租用
郝学胜-神的一滴6 天前
[简化版 GAMES 101] 计算机图形学 13:从光栅化到着色——赋予三维像素光影灵魂
c++·计算机视觉·unity·godot·图形渲染·opengl·unreal
DBBH7 天前
AI帮我忙之webgpu实时路径追踪 下级 three.js接入OIDN
图形渲染·webgpu
成都渲染101云渲染66669 天前
CR15新功能介绍以及CR15云渲染流程
ue5·图形渲染·blender·maya·corona
charlie1145141919 天前
通用GUI编程技术——图形渲染实战(五十)——命中测试与鼠标事件路由:精确交互
c++·windows·架构·交互·图形渲染
做cv的小昊9 天前
计算机图形学:【Games101】学习笔记08——光线追踪(辐射度量学、渲染方程与全局光照、蒙特卡洛积分与路径追踪)
图像处理·笔记·学习·计算机视觉·游戏引擎·图形渲染·概率论
RReality9 天前
【Unity UGUI】血条 / 进度条(HP Bar)
ui·unity·游戏引擎·图形渲染
郝学胜-神的一滴10 天前
中级OpenGL教程 009:用环境光告别模型死黑
前端·c++·unity·godot·图形渲染·opengl·unreal
charlie11451419110 天前
通用GUI编程技术——图形渲染实战(四十八)——Owner-Draw控件:让标准控件焕然一新
图形渲染