Jump to content

  • Log In with Google      Sign In   
  • Create Account


Aliasing using ellipses


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Plerion   Members   -  Reputation: 365

Like
0Likes
Like

Posted 12 October 2012 - 08:10 AM

Hello everybody!

To draw ellipses in my application i use the following HLSL-code:
[source lang="csharp"]void PixelMainFill(in PixelShaderInput input, out float4 color : COLOR0){ float elemX = (-elementSize.x / 2.0f) + elementSize.x * input.texCoord.x; float elemY = (-elementSize.y / 2.0f) + elementSize.y * input.texCoord.y; float radius = getEllipseRadius(elemX, elemY); float radiusCoord = sqrt(elemX * elemX + elemY * elemY); if(radiusCoord <= radius) color = input.color; else color = float4(0, 0, 0, 0);}[/source]


While the ellipse really is an ellipse with this code i have a problem that it looks absolutely blocky as with no multisampling even though i have eight samples and a quality of two.

Is there a way to have multisampling applied to my ellipse?

Greetings
Plerion

Edited by Plerion, 12 October 2012 - 08:13 AM.


Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2338

Like
0Likes
Like

Posted 12 October 2012 - 09:46 AM

I'm not a multisampling expert, but the problem might be that the multisampling is only applied to the polygon edges, and since you calculate your ellipse in the pixel shader (I assume that you draw a rectangle) the multisampling may not be applied to the pixels inside the rectangle.

So, to have smoother edges for your ellipse you can either:

- create a ellipse geometry with mesh refinement to make it smooth

- or add a smoothing to your pixel shader. That is, instead of doing (radiusCoord <= radius) which gives either inside or outside (=blocky) output, you'll interpolate between in and out at few pixel radius.

- you can also sample your ellipse multiple times for each pixel shader invocation with a little jitter (less than a pixel) and then use the inside and outside values as interpolator for the color.

Cheers!

#3 Plerion   Members   -  Reputation: 365

Like
0Likes
Like

Posted 12 October 2012 - 11:52 AM

Hey

I already used the approach of making multiple samples but it seems i have chosen a stupid way to create the samples :D. I switched now and interpolated at the edges of the ellipse with an inverted sinus function and 2 pixel radius. Its not yet perfect, but id say its a good start!

Before:
Posted Image

After:
Posted Image

#4 MJP   Moderators   -  Reputation: 10871

Like
0Likes
Like

Posted 12 October 2012 - 05:25 PM

MSAA does not increase the rate at which the pixel shader runs, it only increases the sampling rate for rasterization and depth testing. In your case you're analytically calculating pixel coverage in your pixel shader instead of with the rasterizer, so MSAA is of no use. What you really want to do is either

A. Use more than one sample per pixel for testing whether a pixel is part of the ellipse. For this randomized sample patterns are better than uniform sampling, and more sample points is always better.

or

B. Analytically calculate the fraction of a pixel that will be covered by your ellipse. Estimating or approximating the fraction may be good enough to provide decent results.

In both cases, you'll end up with some fraction representing the amount of coverage for a pixel. Once you have that, you can use it as an alpha value (with alpha blending enabled, obviously). This will blend your ellipse value with the background based on coverage, giving nice antialiased results. Your lack of alpha-blending is what's currently giving you the black halo around the ellipse when it overlaps with the square.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS