Inside3D!
     

Brush model Z-Fighting Fix

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Mon Dec 22, 2008 5:54 pm    Post subject: Brush model Z-Fighting Fix Reply with quote

You hate it, I hate it, even the dogs in the street organized a protest march about it last week.

So let's get rid of it. Very Happy

Step 1
Find the #define for DIST_EPSILON in world.c and move it to quakedef.h

Step 2
Open gl_rsurf.c, find R_DrawBrushModel, and add these lines before the call to R_RotateForEntity:
Code:
   // hack the origin to prevent bmodel z-fighting
   e->origin[0] -= DIST_EPSILON;
   e->origin[1] -= DIST_EPSILON;
   e->origin[2] -= DIST_EPSILON;


Step 3
Same file, same function, add these lines after the call to R_RotateForEntity:
Code:
   // un-hack the origin
   e->origin[0] += DIST_EPSILON;
   e->origin[1] += DIST_EPSILON;
   e->origin[2] += DIST_EPSILON;


Result
No more brush model Z-fighting.

OK, it's the cheapest, nastiest hack in the universe, but it works. You do get a tiny glitch in that there's a very very small see-through crack around some edges of some doors, but if that bothers you, you can make your own define for this purpose (or even cvar-ize it) (I don't recommend messing with the value of DIST_EPSILON).
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
metlslime



Joined: 05 Feb 2008
Posts: 177

PostPosted: Tue Dec 23, 2008 9:05 am    Post subject: Reply with quote

Corrects if I'm wrong, but this code will arbitrarily (but consistently) show either the bmodel face or the world face, depending on facing angle, right? And there's a certain weird angle that will still have z-fighting?

(Not knocking it, seems like a worthwhile hack)
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Tue Dec 23, 2008 4:01 pm    Post subject: Reply with quote

metlslime wrote:
Corrects if I'm wrong, but this code will arbitrarily (but consistently) show either the bmodel face or the world face, depending on facing angle, right? And there's a certain weird angle that will still have z-fighting?

(Not knocking it, seems like a worthwhile hack)

No, you're perfectly right. I consider it an acceptable trade-off, as the Z-fighting normally occurs on horizontal planes viewed at oblique angles, and is more likely to be observed looking forward or down than looking up, so subtracting a tiny fraction from the z origin (going up in Quake) will resolve it in 99% of practical cases, with 99% of the remaining being at least consistent (no fighting).
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Thu Dec 25, 2008 3:43 pm    Post subject: Reply with quote

what the F Shocked oh so thats what that codebit was for very cool Very Happy some where wondering how you fixed z fighting in realm me to btw Laughing

back from christmas now and going to release some tutorials about how to add compressed pk3 support to quake and a few other goodies comming Wink
Back to top
View user's profile Send private message
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Fri Oct 16, 2009 1:53 pm    Post subject: Reply with quote

I have implemented this fix and have done extensive testing.

I still noticed a small amount of Z-Fighting.

It does reduce it drastically but it is just enough to still be a small annoyance.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Fri Oct 16, 2009 3:20 pm    Post subject: Reply with quote

It's never going to be perfect owing to the non-linear nature of the Z buffer (the same applies to a polygon offset solution).
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Sat Dec 05, 2009 6:57 am    Post subject: Reply with quote

sorry to sound like a newb but i am one. so what exactly is Brush model Z-Fighting?
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
reckless



Joined: 24 Jan 2008
Posts: 390
Location: inside tha debugger

PostPosted: Sat Dec 05, 2009 7:48 am    Post subject: Reply with quote

http://en.wikipedia.org/wiki/Z-fighting

Wink

in basic its if two surfaces hold the same data in the Z-buffer the image will look like its broken up so to alleviate it you offset part of the data.

or you use a higher resolution Z-buffer.
Back to top
View user's profile Send private message
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Sat Dec 05, 2009 3:32 pm    Post subject: Reply with quote

hmm sounds like something worth trying to implement. on my list.
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Sat Dec 05, 2009 9:16 pm    Post subject: Reply with quote

ceriux wrote:
hmm sounds like something worth trying to implement. on my list.


For what it is worth, the Z-fighting thing is largely an original id1 maps problem that affects e1m1 near quad, several exit areas with doors and a couple of other places.

Any engine with the idea of running all custom made maps, doesn't really need this. Because no one would make maps like that today.

For instance, I can't recall seeing Z-fighting in any quality custom map I have ever played. Or even a bad quality one, actually.

I'm just saying that any engine with the idea of it really being made more for a specific total conversion, the priority level of this kind of thing would be near rock bottom.
Back to top
View user's profile Send private message
ceriux



Joined: 06 Sep 2008
Posts: 969
Location: Florida, USA

PostPosted: Sat Dec 05, 2009 9:53 pm    Post subject: Reply with quote

oh well then scratch one off then lol thanks for the tips. im just now getting into engine stuff so i have a lot to learn.
_________________
QuakeDB - Quake ModDB Group
Back to top
View user's profile Send private message Yahoo Messenger
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Sat Dec 05, 2009 10:12 pm    Post subject: Reply with quote

Baker wrote:
ceriux wrote:
hmm sounds like something worth trying to implement. on my list.


For what it is worth, the Z-fighting thing is largely an original id1 maps problem that affects e1m1 near quad, several exit areas with doors and a couple of other places.

Any engine with the idea of running all custom made maps, doesn't really need this. Because no one would make maps like that today.

For instance, I can't recall seeing Z-fighting in any quality custom map I have ever played. Or even a bad quality one, actually.

I'm just saying that any engine with the idea of it really being made more for a specific total conversion, the priority level of this kind of thing would be near rock bottom.


Well with every quake total conversion that you can map for someone is bound to make a badly made map.

I think this is good but mainly because I like keeping backwards compatibility with standared Quake maps via engine side.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Sun Dec 06, 2009 12:32 pm    Post subject: Reply with quote

The real fix of course is to just rebuild and rerelease the maps. Opportunity could be taken to fix a few other minor bugs in them, such as misaligned textures/etc.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group