Can glBlendedFunc be used in the custom shader of babylonjs

BABYLON.Effect.ShadersStore[“customVertexShader”] = `
precision highp float;

attribute vec3 position;
uniform mat4 worldViewProjection;

void main() {
gl_Position = worldViewProjection * vec4(position, 1.0);
}
`;

BABYLON.Effect.ShadersStore[“customFragmentShader”] = `
precision highp float;

void main() {
vec4 fragColor = vec4(1.0, 0.0, 0.0, 0.5); // 紅色,Alpha 0.5
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_FragColor = fragColor;
}
`;

const shaderMaterial = new BABYLON.ShaderMaterial(“shader”, scene, {
vertex: “custom”,
fragment: “custom”,
}, {
attributes: [“position”],
uniforms: [“worldViewProjection”]
});

const sphere = BABYLON.MeshBuilder.CreateSphere(“sphere”, {}, scene);
sphere.material = shaderMaterial;

glBlendFunc is not something you use in shaders. it’s an opengl spec.

Babylon uses it to give different blending modes.

see babylonjs docs on blending modes

you can access those on the .alphaMode property on materials

same w/ shader materials : )

3 Likes