已解决
Three.js 材质的 blending
来自网友在路上 168868提问 提问时间:2023-10-28 18:01:48阅读次数: 68
最佳答案 问答题库688位专家为你答疑解惑
Three.js 材质的 blending
// blending modes
export type Blending =| typeof NoBlending| typeof NormalBlending| typeof AdditiveBlending| typeof SubtractiveBlending| typeof MultiplyBlending| typeof CustomBlending;// custom blending destination factors
export type BlendingDstFactor =| typeof ZeroFactor| typeof OneFactor| typeof SrcColorFactor| typeof OneMinusSrcColorFactor| typeof SrcAlphaFactor| typeof OneMinusSrcAlphaFactor| typeof DstAlphaFactor| typeof OneMinusDstAlphaFactor| typeof DstColorFactor| typeof OneMinusDstColorFactor;// custom blending equations
export type BlendingEquation =| typeof AddEquation| typeof SubtractEquation| typeof ReverseSubtractEquation| typeof MinEquation| typeof MaxEquation;// custom blending src factors
export const SrcAlphaSaturateFactor: 210;
export type BlendingSrcFactor = typeof SrcAlphaSaturateFactor;// custom blending destination factors
export type BlendingDstFactor =| typeof ZeroFactor| typeof OneFactor| typeof SrcColorFactor| typeof OneMinusSrcColorFactor| typeof SrcAlphaFactor| typeof OneMinusSrcAlphaFactor| typeof DstAlphaFactor| typeof OneMinusDstAlphaFactor| typeof DstColorFactor| typeof OneMinusDstColorFactor;class Material {blending: Blending;blendEquation: BlendingEquation;blendEquationAlpha: BlendingEquation;blendDst: BlendingDstFactor;blendDstAlpha: BlendingDstFactor;blendSrc: BlendingSrcFactor | BlendingDstFactor;blendSrcAlpha: BlendingSrcFactor | BlendingDstFactor;
}
1、blending
材质的混合模式。
id = gl.BLEND// NoBlending
gl.disable( id );// NormalBlending
// AdditiveBlending
// SubtractiveBlending
// MultiplyBlending
// CustomBlending
gl.enable( id );
2、blendEquation
混合公式确定如何将新像素与 中 WebGLFramebuffer 已有的像素组合。
混合方程的API:
gl.blendEquationSeparate
: 用于分别设置 RGB 混合方程和 alpha 混合方程
gl.blendEquation
: RGB 混合方程和 alpha 混合方程设置为单个方程。
// blending:
// NormalBlending
// AdditiveBlending
// SubtractiveBlending
// MultiplyBlending
gl.blendEquation( gl.FUNC_ADD );// blending:
// CustomBlending
gl.blendEquationSeparate(equationToGL[ blendEquation ],equationToGL[ blendEquationAlpha ]
);
混合方程的值:
const equationToGL = {[ AddEquation ]: gl.FUNC_ADD,[ SubtractEquation ]: gl.FUNC_SUBTRACT,[ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT[ MinEquation ]: gl.MIN[ MaxEquation ]: gl.MAX
};
source: 接下来要画的颜色
destination: 已经画在了帧缓冲区中的颜色
AddEquation: source + destination
SubtractEquation: source - destination
ReverseSubtractEquation: destination - source
MinEquation: Math.min(source, destination)
MaxEquation: Math.max(source, destination)
3、blendFunc
用于混合像素算法的函数。
混合函数API:
gl.blendFunc
: RGB 和 alpha 设置为单个混合函数。
gl.blendFuncSepar
: 分别混合 RGB 和 alpha 分量的混合函数。
// 混合像素算法的函数
// sfactor: source 混合因子
// dfactor: destination 混合因子
gl.blendFunc(sfactor, dfactor)// sourceColor: vec4;
// color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor)
// srcRGB: source RGB 混合因子
// dstRGB: destination RGB 混合因子
// dstRGB: source A 混合因子
// dstRGB: dstAlpha RGB 混合因子
blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha)// sourceColor: vec3;
// sourceAlpha: float;
// color(RGB) = (sourceColor * srcRGB) + (destinationColor * dstRGB)
// color(A) = (sourceAlpha * srcAlpha) + (destinationAlpha * dstAlpha)
// blending = NormalBlending
gl.blendFuncSeparate(gl.SRC_ALPHA,gl.ONE_MINUS_SRC_ALPHA,gl.ONE,gl.ONE_MINUS_SRC_ALPHA
);// blending = AdditiveBlending
gl.blendFunc( gl.SRC_ALPHA, gl.ONE );// blending = SubtractiveBlending
gl.blendFuncSeparate(gl.ZERO,gl.ONE_MINUS_SRC_COLOR,gl.ZERO,gl.ONE
);// blending = MultiplyBlending
gl.blendFunc( gl.ZERO, gl.SRC_COLOR );// blending = CustomBlending
gl.blendFuncSeparate(factorToGL[ blendSrc ],factorToGL[ blendDst ],factorToGL[ blendSrcAlpha ],factorToGL[ blendDstAlpha ]
);
混合因子的值:
const factorToGL = {[ ZeroFactor ]: gl.ZERO,[ OneFactor ]: gl.ONE,[ SrcColorFactor ]: gl.SRC_COLOR,[ SrcAlphaFactor ]: gl.SRC_ALPHA,[ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE,[ DstColorFactor ]: gl.DST_COLOR,[ DstAlphaFactor ]: gl.DST_ALPHA,[ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR,[ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA,[ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR,[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
};
R S , G S , B S , A S R_S, G_S, B_S, A_S RS,GS,BS,AS, source 的 RGBA.
R D , G D , B D , A D R_D, G_D, B_D, A_D RD,GD,BD,AD, destination 的 RGBA.
4、live examples
WebGL “port” of this.
gl.blendFunc()
gl.blendFuncSeparate()
查看全文
99%的人还看了
相似问题
- C/C++最大质因子 2021年12月电子学会中小学生软件编程(C/C++)等级考试一级真题答案解析
- acwing算法基础之数学知识--分解质因子
- 计算机视觉与深度学习 | 基于GPS/BDS多星座加权图因子优化的行人智能手机导航
- 牛客小白月赛80 D一种因子游戏
- 36基于matlab的对分解层数和惩罚因子进行优化
- HashMap 哈希碰撞、负载因子、插入方式、扩容倍数
- R语言:因子分析 factor analysis
- java中的容器(集合),HashMap底层原理,ArrayList、LinkedList、Vector区别,hashMap加载因子0.75原因
- O(根号n/ln(根号n))时间复杂度内求n的所有因子
- LeetCode 75-02:字符串的最大公因子
猜你感兴趣
版权申明
本文"Three.js 材质的 blending":http://eshow365.cn/6-26980-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: C++: 类和对象(上)
- 下一篇: 【pytorch】pytorch中的高级索引