Help wanted! How to have an alpha background when ray marching?

I am now learning to ray marching by using glsl TOP. I want to have an alpha background of my project.
How can I do that?

Hi there,

When setting your raymarched color (fragColor), you’ll need to also set the alpha channel when you hit an object (and set it to 0 when hitting the background).
A little issue is the anti-aliasing however… You would need to raymarch multiple rays per pixel to calculate the average alpha, which is of course quite heavy.

So in code it would be something like this:

float dist = March(rayOrigin, rayDirection);
vec4 color = vec4(0);
if (dist < maxDistance) { // hit something
color = vec4(1); // Render color here and setting alpha to 1
}

Hope this helps.
cheers,
tim

1 Like