Skip to content

Commit

Permalink
refactor: __blendEquationMode and __blendEquationModeAlpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuki Shimada committed Apr 2, 2023
1 parent 67d43c4 commit 7bcbf5c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/foundation/materials/contents/MToonMaterialContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { RenderingArg } from '../../../webgl/types/CommonTypes';
import { ShaderSemanticsInfo } from '../../definitions/ShaderSemanticsInfo';
import { Vrm0xMaterialProperty } from '../../../types';
import { Sampler } from '../../textures/Sampler';
import { Blend } from '../../definitions/Blend';

export class MToonMaterialContent extends AbstractMaterialContent {
static readonly _Cutoff = new ShaderSemanticsClass({ str: 'cutoff' });
Expand Down Expand Up @@ -806,7 +807,10 @@ export class MToonMaterialContent extends AbstractMaterialContent {
this.__floatProperties._DstBlend
);

material.setBlendEquationMode(blendEquationMode, blendEquationModeAlpha);
material.setBlendEquationMode(
Blend.from(blendEquationMode),
blendEquationModeAlpha != null ? Blend.from(blendEquationModeAlpha) : undefined
);
material.setBlendFuncFactor(blendFuncSrcFactor, blendFuncDstFactor);
}

Expand Down
7 changes: 4 additions & 3 deletions src/foundation/materials/core/Material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { GL_FUNC_ADD, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA } from '../..
import { ShaderSemanticsInfo, VertexAttributeEnum } from '../../definitions';
import { MaterialTypeName, ShaderVariable } from './MaterialTypes';
import { Sampler } from '../../textures/Sampler';
import { Blend, BlendEnum } from '../../definitions/Blend';

/**
* The material class.
Expand All @@ -63,8 +64,8 @@ export class Material extends RnObject {
public cullFace = true; // If true, enable gl.CULL_FACE
public cullFrontFaceCCW = true;
private __alphaToCoverage = false;
private __blendEquationMode = GL_FUNC_ADD; // gl.FUNC_ADD
private __blendEquationModeAlpha = GL_FUNC_ADD; // gl.FUNC_ADD
private __blendEquationMode = Blend.EquationFuncAdd; // gl.FUNC_ADD
private __blendEquationModeAlpha = Blend.EquationFuncAdd; // gl.FUNC_ADD
private __blendFuncSrcFactor = GL_SRC_ALPHA; // gl.SRC_ALPHA
private __blendFuncDstFactor = GL_ONE_MINUS_SRC_ALPHA; // gl.ONE_MINUS_SRC_ALPHA
private __blendFuncAlphaSrcFactor = GL_ONE; // gl.ONE
Expand Down Expand Up @@ -650,7 +651,7 @@ export class Material extends RnObject {
* @param blendEquationMode the argument of gl.blendEquation of the first argument of gl.blendEquationSeparate such as gl.FUNC_ADD
* @param blendEquationModeAlpha the second argument of gl.blendEquationSeparate
*/
public setBlendEquationMode(blendEquationMode: number, blendEquationModeAlpha?: number) {
public setBlendEquationMode(blendEquationMode: BlendEnum, blendEquationModeAlpha?: BlendEnum) {
this.__blendEquationMode = blendEquationMode;
this.__blendEquationModeAlpha = blendEquationModeAlpha ?? blendEquationMode;
}
Expand Down
6 changes: 5 additions & 1 deletion src/webgl/WebGLStrategyCommonMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ function setBlendSettings(material: Material, gl: WebGLRenderingContext) {
}

if (material.alphaMode === AlphaMode.Translucent) {
setBlendEquationMode(material.blendEquationMode, material.blendEquationModeAlpha, gl);
setBlendEquationMode(
material.blendEquationMode.index,
material.blendEquationModeAlpha.index,
gl
);
setBlendFuncSrcFactor(
material.blendFuncSrcFactor,
material.blendFuncDstFactor,
Expand Down

0 comments on commit 7bcbf5c

Please sign in to comment.