Jump to content


special case polygon rasterizing problem


16 replies to this topic

#1 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 03 April 2006 - 10:14 AM

My software renderer has a problem sometimes rasterizing polygons and missing pixels - creating holes. It happens when the polygon is edge on to the viewpoint but part of a continuous surface. Here's a visual example

http://img.photobuck...ter_problem.gif

It only happens when the polygon is edge on because if it was slightly facing the camera it would be rendered and if it was slightly facing away then the faces behind that are part of the surface would cover up the holes.

Has anyone else experienced this problem? Can it be fixed with a simple correction to my rasterizing algorithm or do I need to write extra code for this special case?

Thanks

Peter Bone

#2 jirzynek

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 03 April 2006 - 11:42 AM

rounding errors? (try subpixel accuracy maybe it will help you)


j
int i = 0;
(+ - + - + - + ++--++--++--++--++--++--++--------++++++i);

#3 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 03 April 2006 - 01:15 PM

I have sub-pixel accuracy. There are no rounding errors. Elsewhere the triangles join up perfectly with no overlaps and no holes. This is just a problem with faces edge on to the camera.

#4 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1225 posts

Posted 03 April 2006 - 04:03 PM

When backface culling, don't compare to zero but use a tiny value (commonly called 'epsilon'), like 0.001. So triangles facing away from the camera only very slightly (that actually do face the camera because of floating-point inprecision) do get passed to the rasterizer. It's then the rasterizer's responsability to cull away the falsly accepted triangles (most rasterization algorithms don't render anything with a negative winding order, like the half-space method).

#5 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 03 April 2006 - 04:49 PM

Thanks but that didn't seem to make any difference. It still happens even if I turn backface culling off. The polygon is being sent to be rasterized but no pixels are being drawn because it has such a low thickness. I suppose this is just something wrong with my rasterizing algorithm that needs fixing.
I may just re-write my rasterizers using that half-space method you wrote. I wish I knew about that when I was writing my rasterizer.
Thanks

#6 karligula

    Valued Member

  • Members
  • PipPipPip
  • 180 posts

Posted 03 April 2006 - 05:58 PM

Are you using an inclusive fill on the edges? If you use an exclusive fill that can sometimes miss the odd pixel here an there.

#7 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 04 April 2006 - 10:51 AM

Thanks karligula but I havn't come across that term before. Can you please describe what exclusive fill is or point me somewhere on the net.

#8 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1225 posts

Posted 05 April 2006 - 02:54 PM

peterbone said:

Thanks karligula but I havn't come across that term before. Can you please describe what exclusive fill is or point me somewhere on the net.
What he means is what should happen when a pixel is on an edge. Inclusive fill will render them all, exclusive fill rejects them. Exclusive fill can result in gaps between polygons, while inclusive fill won't.

But inclusive fill isn't the answer, because when you do transparency you want the pixels on edges shared between polygons to be rendered exactly once. One way to do this is to use the top-left fill convention also used by Direct3D and OpenGL. It's all in my advanced rasterization article how to implement this.

#9 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 06 April 2006 - 10:19 AM

ok, I have exclusinve fill. I'm not doing transparency but I think it's better to render the edge pixels once if only to make it slightly quicker. So are missed pixels unavoidable with exclusive filll?

#10 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 06 April 2006 - 03:43 PM

Just use the top-left fill convention (or you can use a bottom-right fill convention if you choose...) and the edge pixels will be rendered exactly once no matter what.
reedbeta.com - developer blog, OpenGL demos, and other projects

#11 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 07 April 2006 - 11:21 AM

But Karligular said

karligula said:

Are you using an inclusive fill on the edges? If you use an exclusive fill that can sometimes miss the odd pixel here an there.

Using a top left fill conversion is an exclusive fill.

Does anyone know where I can find source code for the basic scanline conversion algorithm for a triangle? It's amazing that I can't find any on the internet.

#12 Mattias Gustavsson

    Senior Member

  • Members
  • PipPipPipPip
  • 413 posts

Posted 07 April 2006 - 12:48 PM

have a read through chris heckers rasterization articles, they explain it all.

http://www.d6.com/us...er/misctech.htm

#13 jirzynek

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 07 April 2006 - 01:29 PM

try to find two text files fatmap.txt and fatmap2.txt (fast affine texture mapping), and maybe some articles by Tom Hammersley could help you http://tfpsly.free.f.../TomHammersley/
int i = 0;
(+ - + - + - + ++--++--++--++--++--++--++--------++++++i);

#14 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1225 posts

Posted 07 April 2006 - 02:53 PM

peterbone said:

Using a top left fill conversion is an exclusive fill.
No it's not. And it's neither an inclusive fill.

The top-left fill convention will render pixels that are on a left or top edge, and skip pixels that are on a right or bottom edge. This way whatever mesh you render the pixels between polygons will be rendered exactly once.

Top-left fill convention is the accepted standard and used by Direct3D and OpenGL. Chris Hecker's articles also use a strict top-left fill convention.

Subpixel accuracy, subtexel accuracy and the fill convention are the first things that separate a sOftWarE rEndeRER from a Software Renderer.

#15 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 07 April 2006 - 04:19 PM

oh right. I see now. Exclusive fill doesn't render any edge pixels.
I think mine is still a sOftWarE rEndeRER despite having subpixel accuracy and a top left fill convention.
Here it is in it's simplest form http://atlas.walagat...ngle_raster.txt

#16 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1225 posts

Posted 09 April 2006 - 12:20 PM

peterbone said:

oh right. I see now. Exclusive fill doesn't render any edge pixels.
I think mine is still a sOftWarE rEndeRER despite having subpixel accuracy and a top left fill convention.
Here it is in it's simplest form http://atlas.walagat...ngle_raster.txt
I see you're using the floating-point vertex coordinates directly. This causes some precision problems because subtraction and multiplication unavoidably loose precision. The only solution is to use integer fixed-point numbers. Both my rasterization article and Hecker's articles use fixed-point.

#17 peterbone

    New Member

  • Members
  • PipPip
  • 23 posts

Posted 09 April 2006 - 02:24 PM

ok, I don't think that's what's causing the problem because it's only happening on these single pixel thickness polygons but I was intending on doing that anyway for speed up so I'll see it it helps.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users