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


相关推荐
成都渲染101云渲染66667 小时前
C4D 云渲染平台哪个好?价格、速度、稳定性全网真实对比(含渲染101)
ue5·图形渲染·blender·maya·houdini
郝学胜-神的一滴8 小时前
深入理解OpenGL VBO:原理、封装与性能优化
c++·程序人生·性能优化·图形渲染
BoBoZz199 小时前
Hello 隐式建模
python·vtk·图形渲染·图形处理
明洞日记12 小时前
【VTK手册024】高效等值面提取:vtkFlyingEdges3D 详解与实战
c++·图像处理·vtk·图形渲染
DeltaTime15 小时前
一 图形学概述, 线性代数
c++·图形渲染
成都渲染101云渲染666615 小时前
Blender 云渲染平台实测对比:iRender、GarageFarm、渲染101 哪家更适合动画云渲染?
ue5·图形渲染·blender·maya·houdini
郝学胜-神的一滴2 天前
深入浅出:理解OpenGL的标准化设备坐标(NDC)
开发语言·程序人生·图形渲染
BoBoZz192 天前
ExtractData 椭球的并集与函数的裁剪
python·vtk·图形渲染·图形处理
我想_iwant2 天前
PBR渲染案例:babylonjs 中的PBR渲染
图形渲染
BoBoZz193 天前
DiscreteMarchingCubes离散等值面提取算法
python·vtk·图形渲染·图形处理