I have run into a weird problem. The Alpha values of sprites are not respected when the sprites are in motion.
I was trying to do particles in 3d, and so for the start I just rendered them onto a quad(I am using Raylib), the image is the usual fading white to black circle used for particle systems. Somehow the artifacts of black borders show up. Even after playing around with the various blend functions, I can't seem to figure out how to remove this artifact.
The code looks like this
void DrawBlurSphere(Texture2D text, Vector3 position, f32 Radius, Color color)
{
f32 x = position.x, y = position.y, z = position.z;
f32 width = 3.0f;
f32 height = 3.0f;
rlSetTexture(text.id);
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
// Front Face
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
rlTexCoord2f(0.0f, 0.0f);
rlVertex3f(x - width / 2,
y - height / 2,
z); // Bottom Left Of The Texture and Quad
rlTexCoord2f(1.0f, 0.0f);
rlVertex3f(x + width / 2,
y - height / 2,
z); // Bottom Right Of The Texture and Quad
rlTexCoord2f(1.0f, 1.0f);
rlVertex3f(x + width / 2,
y + height / 2,
z); // Top Right Of The Texture and Quad
rlTexCoord2f(0.0f, 1.0f);
rlVertex3f(x - width / 2,
y + height / 2,
z); // Top Left Of The Texture and Quad
rlEnd();
rlSetTexture(0);
}
while (!WindowShouldClose())
{
f32 dt = GetFrameTime();
update_particles(&origin, dt);
BeginDrawing();
ClearBackground(BLANK);
DrawFPS(SCREEN_WIDTH - 100, 10);
BeginMode3D(camera);
rlSetBlendFactors(RL_SRC_ALPHA, RL_ONE, RL_FUNC_ADD);
BeginBlendMode(BLEND_CUSTOM);
for (size_t i = 0; i < origin.used; ++i)
{
particle_3d *p1 = origin.pool + i;
if (p1->lifetime > 0)
{
DrawBlurSphere(text, p1->position, 15, p1->color);
}
}
EndBlendMode();
EndMode3D();
EndDrawing();
}
I have also tried the normal GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA and that doesn't work as well. The other thing is, the objects don't have that boxy look when they are stationary.
Can you please help me with this one?
