gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > 3D Tearing

#159049 - ritz - Tue Jun 24, 2008 10:48 pm

Hi all,

I'm hoping for some help or ideas on a problem that I've been having with visual tearing in my 3D project. I've written a small program that reproduces the same problem that exists in my regular project. Using triangle strips, I put four squares together (i.e. floor tiles). Use the pen to rotate the view around and you'll see the tearing.

Screenshot of the tearing: tear.jpg
Rom of the tearing program: tear.zip
Code of the tearing program: tear.c
This is my actual project: sonic_r233.zip

I currently believe it's related to matrix imprecision, but I'm not sure.


Last edited by ritz on Wed Jun 25, 2008 11:20 pm; edited 1 time in total

#159051 - TwentySeven - Tue Jun 24, 2008 11:03 pm

Yep! It's a precision issue. Typically it only shows up on t-junctions in geometry (where one vert sits on an edge of another polygon), but rendering a quad like you've done there by positioning it with a matrix is what the issue is.

This even happens on pc video cards when you try and create a flush seam like that by drawing "models" fitted together by matrixes, because theres small imprecisions in the transform that mean the final screen X and Y of what should be a shared vert isn't 100% the same.

Anyway, the solution is to render your quad tiles using world space coordinates for your vertexes.

ie:

DrawQuad(-2,-2,2,2); //x1,y1,x2,y2
DrawQuad(2,-2,4,2);
DrawQuad(4,-2,6,2);

p.s. your project looks kickass! very nice!


Last edited by TwentySeven on Tue Jun 24, 2008 11:19 pm; edited 1 time in total

#159053 - ritz - Tue Jun 24, 2008 11:15 pm

Thanks for the info/clarification. I see how your example would work, it makes sense.

However, my tiles are filled with inner geometry that can span the full 16-bit range (-8 to 7.999). Have a look at my original project I posted above and you'll see what I mean. I'm stitching them together to produce full towns/rooms/etc.

Is there any ideas out there as to how I could alleviate this tearing problem?

#159054 - relpats_eht - Tue Jun 24, 2008 11:18 pm

Use triangle strips instead of quads, that should work.

[edit]
Bah, didn't read, I just looked at the pictures.

There is really no reason for those triangle-strip-quadrangles to not share vertices. Just draw them as one, longer triangle strip.
_________________
- relpats_eht


Last edited by relpats_eht on Tue Jun 24, 2008 11:20 pm; edited 1 time in total

#159055 - ritz - Tue Jun 24, 2008 11:19 pm

I am :)

#159056 - relpats_eht - Tue Jun 24, 2008 11:25 pm

See the edit above.

Also, making sure the vertices are the same by using some form of indexing wouldn't hurt.

I had the same problem when I wrote a geomipmapping class. I solved it by making long triangle strips and storing all vertices in one place and calling them up with indices. Also, to get as much use out of the limited range as possible, I stored the vertices as smaller values and used a matrix scale before drawing.
_________________
- relpats_eht

#159057 - TwentySeven - Tue Jun 24, 2008 11:30 pm

Aye, it really is a pickle of a situation because you'd run into the same issue on the pc, it'd just be less noticable due to the PC's higher resolution and higher precision geometry pipeline.

You using high frequency detail in your ground textures helps alot, for example I didn't actually notice any cracking running around your .nds.

However, that's not really a solution is it?

#159058 - silent_code - Tue Jun 24, 2008 11:43 pm

Just a small hint: Your problem is not tearing (that is yet another problem that has to do with disabled vertical synchronisation - which is not present on the NDS), is is rather polygon (or better: primitive) "gaping". ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#159060 - kusma - Wed Jun 25, 2008 12:08 am

By carefully tailoring your matrices in fixed-point, you should be able to get completely rid of the problem. But it might be easier just to extend the geometry slightly until the problem isn't noticeable any more ;)

#159062 - DensitY - Wed Jun 25, 2008 1:18 am

yeah looks like a precision problem, go fixed point. you can either adjust the texture coords or texture matrix so the texture is slightly larger then the quad, so any precision errors and round snapping don't result in gaps.

Edit:

of course you aren't doing strip quad rendering, so you could result in something like

Code:

---- ----
|   ||    |
---- ----

^ vertex precision problems can result in a gap anywhere along here.

strip rendering would fix that up

Code:

--------
|   |   |
--------

#159083 - ritz - Wed Jun 25, 2008 5:13 am

Thanks for the hints and tips so far.

In my actual project I use indexed vertices so there's no dups or wasted space. All my models/objects are made up of multiple meshes which are all triangle stripped. The tearing/seams/gaps that I refer to only show up on the object's boundaries and not within it (basically where I stitch together each of these 'big' models/objects into their final world coords - a diff trans matrix for each). So that's why I believe that it is most likely matrix precision. I hope that makes sense :)

I'll try fudging with my transform matrices tomorrow and see. I dunno. I added glScalef32(4098) to some areas for fun and it helped a fair bit but still shows an unacceptable (to me) amount especially when my clear color is bright white. It's much easier to see the white bleed through that way.

Just to be clear, when I refer to tiles/object I'm referring to lots of geometry that could potentially fill up from -8 to 7.9 in the 16bit range. Then I put it together like a rubix cube with transform matrices. Sorta. Kinda.

@TwentySeven - Thanks!

#159089 - TwentySeven - Wed Jun 25, 2008 6:37 am

Well, I think you're not going to be able to fix it without modifying your artpath some.
If it were me, I'd do the following:

* Use a more neutral clear color. Dark greys a better choice then bright white :)
* For the majority of your tile models, remove the "ground plane" quad from them and render the terrain that uses them as strips, or, at the very least, using worldspace coords and triangles. It'll bugger up your art path a little bit but better to do it now then 500 tile models in..
* For the tile models that have holes in them or arn't a clean ground plane quad (so you can't generate the mesh in software) you can either scale the model up a little bit on the x/y plane to cover the crack, or just eat it for the few tiles it occurs on.

#159091 - nce - Wed Jun 25, 2008 10:39 am

It exist an other solution on pc...

extend your geometry border vertically and repeat the uv on them...

( I gess that my explanation is kind of crap ^_^ so here is a paper about the chunk quadtree where I've seen that technique for the first time :

http://tulrich.com/geekstuff/chunklod.html

the pdf is at the bottom of the page.
Check the way he resolves the cracks between chunks )

I implemented this paper long time ago on pc and I was thinking about doing that on ds but it looks a little expensive for the ds but maybe the crack filling technique will suit your needs.
_________________
-jerome-

#159094 - silent_code - Wed Jun 25, 2008 11:28 am

Btw: The gaps are generated by the resterizing engine. Due to different interpolation values in different primitive setups (e.g. used vertex' positions), the boundary pixels might not align propperly. This is a sub pixel accuracy problem.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#159103 - elhobbs - Wed Jun 25, 2008 2:52 pm

for me this mainly occurs when triangles intersect the view frustum and get clipped by the hardware. for some reason the same edges shared by two different triangle will be projected differently by the hardware even though they are using the exact same vertices and matrices. the effect is more noticeable closer to the viewpoint and when they are large triangles.

#159135 - ritz - Wed Jun 25, 2008 11:23 pm

Thanks all for the info and help. I'll let you know if I figure out something suitable.