Anti-aliasing does not work when shapes are drawn from fragment shader

Hi there,

I’m trying to draw sphere-sprites on the screen using a custom shader. The geometry shader generates 2D billboards on the fly and the spheres are obtained via ray casting inside the billboard in the fragment shader (well-known technique to render a lot of spheres very quickly)

1750398--110614--Untitled.png

When drawing my sphere-sprites (in yellow), the output is highly aliased on the edges while the sphere mesh (in grey) drawn via Unity’s internal rendering routine is nicely anti-aliased when multi-sampling X8 is enabled in the quality settings.

When drawing the same scene in a standalone OpenGL application I do not get these artefacts and the sprite-sphere appear nice and smoothly anti-aliased.

I attached my project in case you want to reproduce the bug, to see the spheres with aliased edges, simply press play and observe the results in Game mode (works with DX11 compatible machines and in game mode only). I also tested in player mode and the results are just the same.

Any help in this would be very appreciated.

In advance thx,
Mat.

1750398–110613–UnityProject.zip (91.9 KB)

What are you doing to make the spheres anti-aliased? The fragment shader is usually only executed per pixel and not per sample, which means you won’t get any anti-aliasing inside triangles.