I have a custom GPU based particle solution Im whipping up for a project and Ive got everything working really well, but now that I added alpha support for color gradients over lifetime everything breaks.
I add “needAlphaBlending: true, needAlphaTesting: true,” or to the “this.mesh.hasVertexAlpha = true;” and get an error that BJS cant find a boundingSphere? Im assuming it needs the spheres to sort but since my particle faces are created on a compute shader that info does not exist?
How do I get my alpha working on the shader without this error dropping?
// ── Mesh + render material ────────────────────────────────────────────────
this.mesh = CreatePlane("particleMesh", { size: 1, updatable: true }, this.scene);
this.mesh.isPickable = false;
this.mesh.alwaysSelectAsActiveMesh = true;
// this.mesh.hasVertexAlpha = true;
// VertexData establishes the index buffer and a dummy position buffer.
// The dummy position VB is immediately replaced below.
const vd = new VertexData();
vd.indices = buildIndexData(count);
vd.positions = new Float32Array(totalVerts * 3); // zeros; compute overwrites every frame
vd.applyToMesh(this.mesh, true);
// Replace the dummy position VB with the storage-backed output buffer.
this.mesh.setVerticesBuffer(
new VertexBuffer(engine, this.outPositionsBuffer.getBuffer(),
VertexBuffer.PositionKind, false, true, 3, false), false
);
this.mesh.setVerticesBuffer(
new VertexBuffer(engine, this.outScalesBuffer.getBuffer(),
"particleScale", false, true, 3, false), false
);
this.mesh.setVerticesBuffer(
new VertexBuffer(engine, this.outColorsBuffer.getBuffer(),
"particleColor", false, true, 4, false), false
);
// Static quadCorner buffer — written once, never changes.
this.mesh.setVerticesBuffer(
new VertexBuffer(engine, buildCornerData(count), "quadCorner", false, false, 2, false), false
);
This is how I setup the buffers.
And this is how I handle them in the compute shader.
// Colour over lifetime.
let colt = sampleGrad(tc);
var fc: vec4f;
if (params.colorMode == 0u) { fc = p.spawnColor * colt; }
else { fc = clamp(p.spawnColor + colt, vec4f(0.0), vec4f(1.0)); }
// Write simulation state back.
particles[i] = p;
// Write 6 vertex entries for this particle.
for (var v = 0u; v < 6u; v++) {
let vi = i * 6u + v;
let pb = vi * 3u;
outPositions[pb] = p.pos.x;
outPositions[pb + 1u] = p.pos.y;
outPositions[pb + 2u] = p.pos.z;
let sb = vi * 3u;
outScales[sb] = fs; outScales[sb + 1u] = fs; outScales[sb + 2u] = fs;
let cb = vi * 4u;
outColors[cb] = fc.r; outColors[cb + 1u] = fc.g;
outColors[cb + 2u] = fc.b; outColors[cb + 3u] = fc.a;
}
Is there something Im doing wrong that is causing the boundingSphere error?
Should I be doing the alpha differently?



