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;