View Issue Details

IDProjectCategoryView StatusLast Update
0004634The Dark ModGraphicspublic10.04.2021 04:11
Reporterstgatilov Assigned Tostgatilov  
Status assignedResolutionopen 
Product VersionTDM 2.04 
Target VersionTDM 2.10 
Summary0004634: Decal depth fighting (Inn Business: "rug in tavern is not smooth")
DescriptionThe rug look bad: its color (brightness) changes hardly from light to dark at a screen-horizontal line.
See screenshot.
Steps To Reproduce1. Start Inn Business map.
2. Run "notarget" command in console.
3. Enter the tavern through the main entrance.
4. Go to the place behind the bar/table.

At some moment you'll notice that the rug (behind the bar) is hardly split by a horizontal line into two parts with different brightness.
See screenshot.
TagsNo tags attached.


related to 0004079 resolvedSteveL Decals drawing over stuff in front 
related to 0005580 resolvedstgatilov Dmap : better windings precision 




14.10.2017 07:48


broken_ambient_1.jpg (73,684 bytes)   
broken_ambient_1.jpg (73,684 bytes)   


14.10.2017 07:48


broken_ambient_2.jpg (132,494 bytes)   
broken_ambient_2.jpg (132,494 bytes)   


14.10.2017 07:50

administrator   ~0009466

Note: this has nothing to do with interactions, it is present even with r_skipInteractions.
It happens both with simple and enhanced ambient rendering method. Settings like GLSL/FBO have no effect on the problem.

I suspect it is a bad texture, since other objects do not have the issue.


14.10.2017 12:13

developer   ~0009468

Last edited: 14.10.2017 12:14

View 2 revisions

I can't see the problem, neither on the screenshots or in game.
Here's my screenshot.
I used r_singleLight and r_lightscale to have the ambient light only.



14.10.2017 12:16


Untitled.jpg (274,510 bytes)


14.10.2017 12:32

administrator   ~0009469

When I try to see your screenshot, I see mantis error:

Issue 0 not found.
SYSTEM WARNING: 'extract() expects parameter 1 to be array, boolean given' in '/usr/local/www/mantis-1.2.19_1/file_download.php' line 81

Do you mean you cannot notice the problem even on my screenshots?


14.10.2017 12:33

administrator   ~0009470

Try increasing gamma to make ambient colors bright enough. With low gamma this thing can be hard to notice.


14.10.2017 12:34

developer   ~0009471

Last edited: 14.10.2017 12:36

View 3 revisions

Try to refresh the webpage because I re-uploaded the picture.
Otherwise here it is



14.10.2017 12:35

administrator   ~0009472

As for Untitled.jpg which is the third attachment in this issue, you are too close to this rug to see the effect.
Try to reproduce exactly the same camera position as on my screenshots.


14.10.2017 12:36

developer   ~0009473

How did you turn the ceiling light off?


14.10.2017 12:39

administrator   ~0009474

Speaking on my first screenshot, it has two red marks like ">" and "<" signs inside red circle. Inspect closely the horizontal line between them. It splits the rug into two parts: the lower one is significantly brighter than the upper one.

When you move slightly from that position, the splitting line moves up and down with you, which catches your eye quickly (unless you have low gamma, in which case you do not see ambient well anyway).


14.10.2017 12:40

administrator   ~0009475

I used water arrow to disable ceiling light =)


15.10.2017 10:16

developer   ~0009480

Last edited: 15.10.2017 10:40

View 5 revisions

Can see it now.
I think it's simple depth-buffer fighting.
Could it be some kind of polygon offset mapper's attempt that went wrong?
Somebody fluent with DR should take a look.

Or maybe it's just the scattered_dirt getting on top of the carpet because of insufficient depth buffer precision. Explains why r_skipAmbient 1 fixes it.



15.10.2017 15:23

reporter   ~0009481

Last edited: 15.10.2017 15:25

View 2 revisions

It turns out there are *two* func_static scattered_dirt02 patches, coplanar with each other and with the top of the floor brush. It doesn't look as though the mapper tried to offset anything (though scattered_dirt02 has DECAL_MACRO, implying sort decal and polygonOffset 1 on both patches).



15.10.2017 16:27

administrator   ~0009482

Ok, it looks like a map issue.
This is very likely because most of the rugs around do not behave wrong.
Sorry, false alarm then =)

BTW, is it hard to check that if duplicate dirt is removed, the issue is gone?

P.S. Should it be resolved as "won't fix" or changed to "mapping" category?


15.10.2017 16:40

developer   ~0009483

I would vote for moving to the "mapping" category


15.10.2017 17:30

reporter   ~0009484

Last edited: 15.10.2017 17:43

View 2 revisions

I'm not sure it is a map issue: the decal patches are below the rug. In fact they're as far below the rug as they could be. And using more than one blended decal (they use blend filter) is something a mapper might legitimately do.

Edit: I just tried and failed to see any glitches on my 2.05 installation.

If you want to test with one of the decal patches removed, setting "hide" "1" on func_static_199 should work non-destructively.



11.11.2017 15:35




11.11.2017 15:37

administrator   ~0009569

Added a screenshot from "Patently Dangerous" mission.
The same (or almost the same) rug produces the same issue.
You can see it very close to the mission start: just mantle over the fence and it will be there.


11.11.2017 18:52

developer   ~0009578

Related to 0001201?


12.11.2017 21:46

reporter   ~0009587

Or this?


14.11.2017 16:59

administrator   ~0009614

I have also noticed the same issue on one of the larger rugs in Saint Lucia. Have not taken a screenshot...


14.11.2017 19:43

developer   ~0009619

Last edited: 14.11.2017 19:48

View 4 revisions

>> the decal patches are below the rug.
Yes they are, but the engine lifts all decals automatically (see cvars r_offsetXXX).
Set the cvars to 0 and the carpet is OK but now the stain on the bar stand is broken.
You can play with cvars and try to find values that work for this particular location.
The radical solution would be to disable the hardware depth test and discard pixels in fragment shader which would bring some other glitches.
We can also use a 32-bit depth precision in an FBO.



31.12.2017 07:41

administrator   ~0009947

Last edited: 31.12.2017 07:42

View 2 revisions

I have linked a related issue, maybe interesting to read.

It looks like the only proper way to fix it is to review all the offsets (depth and 3D) and create some plan which would get everything right. Adjusting offset for one particular scenario without checking all the other cases will most likely break some other cases =(

When I set r_offsetFactor to -1 instead of -2, the issue starts happening at much smaller looking angle. With -0.6, I have to go very far to see the issue (Patently Dangerous is a great map to test it).
According to my experience, such dependence on angle must not happen when polygonOffsetFactor is used (it is divided on the minimum looking angle over the polygon).
Which leads me to conclusion that there is a plain 3D offset somewher (i.e. offset hardcoded in world coordinates). Perhaps if we remove this 3D offset, everything would work properly?


28.03.2018 08:37


This old decal issue thats been around for a while now, have you guys got an idea on how to fix it..?


28.03.2018 09:31

developer   ~0010196

Last edited: 28.03.2018 09:32

View 2 revisions

In this particular case IMHO it would make sense to make the dirt decal to include the carpet as well. (Do they only walk with their dirty boots on the woodboard?)

If we want to make an impression of carpet to cover the dirt then we need to somehow make the dirt part of the woodboard material.



28.03.2021 05:06

administrator   ~0013812

Last edited: 28.03.2021 05:16

View 2 revisions

In the Inn Business case, the depth fight is between:
  func_static_199: consists of one quad patch with material "textures/darkmod/decals/dirt/scattered_dirt02"
  func_static_323: consists of one thin brush with upper side having material "textures/darkmod/carpet/runners/geometric01_red"

The problem does happen in TDM 2.04 and later, and does not happen in TDM 2.03 and earlier.
So this is caused by a careless fix during TDM 2.04 development.

UPDATE: Broken by related issue 0004079.
The values of r_offsetFactor/r_offsetUnits were changed from 0 / -600 to -2 / -0.1.
Returning the old values back fixes the issue.

I would say -600 and -0.1 are weird numbers here...
Actually, the main difference is the addition of slope-based offset.


28.03.2021 05:21

administrator   ~0013813

The reason for changing offsets was originally reported here:
(basically, yet another depth fighting, but in different circumstances)

The cvars are used to apply glPolygonOffset to materials which have one of:
In case of polygonOffset, there can be an additional value too, which serves as a factor on offset.
But for some reason, it is applied to "units" only, not to "factor" (perhaps because "factor" was always zero):
  // set polygon offset if necessary
  if ( shader->TestMaterialFlag( MF_POLYGONOFFSET ) ) {
    qglEnable( GL_POLYGON_OFFSET_FILL );
    qglPolygonOffset( r_offsetFactor.GetFloat(), r_offsetUnits.GetFloat() * shader->GetPolygonOffset() );


28.03.2021 06:48

administrator   ~0013814

And the reason why TDM switched from -0.1 / -1 to -2 / -0.1 is described here:
I guess that was not a good idea...


28.03.2021 09:37

developer   ~0013815

I could never get qglPolygonOffset work reliably
This better be fixed on the map level via e.g. vertex blending


28.03.2021 11:41

administrator   ~0013816

Nobody will redo existing maps, so any ideas like "let's do decals differently" can be ignored immediately.

In this case, factor -2 is approximately equivalent to units -1500.
Which confirms that factor is usually A LOT stronger than units.


09.04.2021 17:44

administrator   ~0013830

Last edited: 10.04.2021 04:11

View 4 revisions

Basically, there are two conflicting goals:
  A) Making sure decal doesn't depth fight with the wall/floor it is on --- main property of decal
  B) If there is thin object on the wall/floor, it's desirable to avoiding decal being drawn on top of it --- the problem we have here

Copying some more information copied from forum thread:

1) Some decals are incorrectly placed by mappers.
I.e. decal is not exactly on the wall, but a bit inside it, even when looking in DR.
It works with larger offset, but it breaks when we try to reduce offset.
One such example is in Inn Business FM at: 384.2 -510.42 69.09 -12.2 -32.4 0.0

2) Sometimes it is hard to put decal exactly onto the floor, because floor is a patch.
One such minor example is in New Job FM at: 1252.02 -2161.64 -6.09 59.9 -27.4 0.0
Once again: it worked perfectly with larger offset, but when offset it reduced, it starts giving depth fighting, because decal is slightly inside floor.

3) Sometimes decal is precisely on the wall, but dmap changes geometry of the wall (so decal gets inside wall).
This happens e.g. in Business As Usual FM at: -30.57 966.73 108.64 -25.3 46.3 0.0
Added reduced map to SVN as: test/
Interestingly, this case does not work perfectly now, and becomes even worse if offset is reduced.

This is the worst thing, since the geometry is routinely changed by 0.01-0.02.
A very large polygon offset is needed to make decal look properly at close distance, and having same offset at large distance will be way too strong.
So it seems that we need a different mechanism to cope with this problem, which will offset depth by 0.1 world units regardless of distance.

The further analysis of case 3 showed that it comes from two sources:
  a) When dmap computes "windings" (polygons) of everything like brushes, it computes them with error of about 0.01 - 0.02 (see 0005580).
  b) Dmap often runs T-junction removal, which snaps all vertices to coordinates looking like "(integer+0.5)/32", which introduces error about 1/64 too (see 0005486).
I will fix both problems in respective issues, but there are more potential sources of geometric shifts in dmap:
  c) If some vertices happen to be close to each other, they get merged together.
  d) Maybe something else I cannot remember now =)
Aside from that, there are old maps (like Business As Usual), which most likely won't be recompiled.

So the best bet right now is to do custom depth offset in fragment shader, which will correspond to fixed distance 0.1 in world space.

Issue History

Date Modified Username Field Change
14.10.2017 07:46 stgatilov New Issue
14.10.2017 07:48 stgatilov File Added: broken_ambient_1.jpg
14.10.2017 07:48 stgatilov File Added: broken_ambient_2.jpg
14.10.2017 07:50 stgatilov Note Added: 0009466
14.10.2017 12:13 duzenko Note Added: 0009468
14.10.2017 12:13 duzenko File Added: Untitled.jpg
14.10.2017 12:14 duzenko Note Edited: 0009468 View Revisions
14.10.2017 12:15 duzenko File Deleted: Untitled.jpg
14.10.2017 12:16 duzenko File Added: Untitled.jpg
14.10.2017 12:32 stgatilov Note Added: 0009469
14.10.2017 12:33 stgatilov Note Added: 0009470
14.10.2017 12:34 duzenko Note Added: 0009471
14.10.2017 12:35 duzenko Note Edited: 0009471 View Revisions
14.10.2017 12:35 stgatilov Note Added: 0009472
14.10.2017 12:36 duzenko Note Edited: 0009471 View Revisions
14.10.2017 12:36 duzenko Note Added: 0009473
14.10.2017 12:39 stgatilov Note Added: 0009474
14.10.2017 12:40 stgatilov Note Added: 0009475
15.10.2017 10:16 duzenko Note Added: 0009480
15.10.2017 10:17 duzenko Note Edited: 0009480 View Revisions
15.10.2017 10:29 duzenko Note Edited: 0009480 View Revisions
15.10.2017 10:38 duzenko Note Edited: 0009480 View Revisions
15.10.2017 10:40 duzenko Note Edited: 0009480 View Revisions
15.10.2017 15:23 VanishedOne Note Added: 0009481
15.10.2017 15:25 VanishedOne Note Edited: 0009481 View Revisions
15.10.2017 16:27 stgatilov Note Added: 0009482
15.10.2017 16:40 duzenko Note Added: 0009483
15.10.2017 17:30 VanishedOne Note Added: 0009484
15.10.2017 17:43 VanishedOne Note Edited: 0009484 View Revisions
11.11.2017 15:35 stgatilov File Added: PatentlyDangerous_BrightnessIssue.jpg
11.11.2017 15:37 stgatilov Note Added: 0009569
11.11.2017 18:52 duzenko Note Added: 0009578
12.11.2017 21:46 VanishedOne Note Added: 0009587
14.11.2017 16:59 stgatilov Note Added: 0009614
14.11.2017 19:43 duzenko Note Added: 0009619
14.11.2017 19:43 duzenko Note Edited: 0009619 View Revisions
14.11.2017 19:46 duzenko Note Edited: 0009619 View Revisions
14.11.2017 19:48 duzenko Note Edited: 0009619 View Revisions
31.12.2017 07:24 stgatilov Relationship added related to 0004079
31.12.2017 07:41 stgatilov Note Added: 0009947
31.12.2017 07:42 stgatilov Note Edited: 0009947 View Revisions
28.03.2018 08:37 user81 Note Added: 0010173
28.03.2018 09:31 duzenko Note Added: 0010196
28.03.2018 09:32 duzenko Note Edited: 0010196 View Revisions
21.03.2020 17:47 stgatilov Product Version SVN => TDM 2.05
21.03.2020 17:47 stgatilov Target Version => TDM 2.09
21.03.2020 17:47 stgatilov Assigned To => stgatilov
21.03.2020 17:47 stgatilov Status new => assigned
05.12.2020 12:35 stgatilov Target Version TDM 2.09 => TDM 2.10
18.02.2021 12:00 stgatilov Summary Inn Business: ambient light on a rug in tavern is not smooth => Decal depth fighting (Inn Business: "rug in tavern is not smooth")
28.03.2021 05:06 stgatilov Note Added: 0013812
28.03.2021 05:16 stgatilov Note Edited: 0013812 View Revisions
28.03.2021 05:21 stgatilov Note Added: 0013813
28.03.2021 05:22 stgatilov Product Version TDM 2.05 => TDM 2.04
28.03.2021 06:48 stgatilov Note Added: 0013814
28.03.2021 09:37 duzenko Note Added: 0013815
28.03.2021 11:41 stgatilov Note Added: 0013816
09.04.2021 13:57 stgatilov Relationship added related to 0005580
09.04.2021 17:44 stgatilov Note Added: 0013830
09.04.2021 17:46 stgatilov Note Edited: 0013830 View Revisions
10.04.2021 04:10 stgatilov Note Edited: 0013830 View Revisions
10.04.2021 04:11 stgatilov Note Edited: 0013830 View Revisions