View Issue Details

IDProjectCategoryView StatusLast Update
0004825The Dark ModGraphicspublic13.01.2021 03:46
Reporterstgatilov Assigned Tostgatilov  
PrioritynormalSeveritytweakReproducibilityalways
Status resolvedResolutionfixed 
Product VersionTDM 2.06 
Target VersionTDM 2.09Fixed in VersionTDM 2.09 
Summary0004825: Investigate approach to avoid/reduce light toggling on surfaces
DescriptionThis issue is about the following topic on forum:
  http://forums.thedarkmod.com/topic/19139-nonsmooth-graphics-due-to-bumpmapping/

Right now, whenever a guard with a torch moves through a doorway, there is a moment when the nearby wall toggles from "partly lit" to "completely unlit" (it happens when light source crosses the wall's plane).
Since this is a nonsmooth change in visual appearance, it is very noticeable. It would be great to remove or reduce this effect.
Additional InformationSome initial attempts failed (see forum): they made low-polygon look of apples much more apparent.

The goal is to continue discussion and if some acceptable hack exists, add it to interaction shader.
TagsNo tags attached.
Attached Files
light_toggling_counter.patch (941 bytes)   
Index: glprogs/interaction.fs
===================================================================
--- glprogs/interaction.fs	(revision 15253)
+++ glprogs/interaction.fs	(working copy)
@@ -114,7 +114,15 @@
 
 	vec3 specularColor = specularCoeff * fresnelCoeff * specular * (diffuse * 0.25 + vec3(0.75));
 	float R2f = clamp(localL.z * 4.0, 0.0, 1.0);
-	float light = clamp(rimLight * R2f + NdotL, 0.0, 1.5);
+
+	float diffuseCoeff = NdotL;
+	//hacky coefficient to make lighting smooth when L is almost in surface tangent plane
+	vec3 meshNormal = normalize(var_TangentBitangentNormalMatrix[2]);
+	float MNdotL = dot(meshNormal, L);
+	if (MNdotL < min(0.25, NdotL))
+		diffuseCoeff = mix(MNdotL, NdotL, MNdotL / 0.25);
+
+	float light = clamp(rimLight * R2f + diffuseCoeff, 0.0, 1.5);
 	vec3 totalColor = (specularColor * R2f + diffuse) * light * u_diffuseColor.rgb * lightColor() * var_Color.rgb;
 
 	return totalColor;

Activities

nbohr1more

nbohr1more

06.08.2018 03:18

developer   ~0010738

Hmm.

This is a mixed result.

On one hand, the example wood table in the mission Inn Business seems to
work much better than the default interaction.

On the other hand, the new shader has reduced the rim lighting effect which
has decreased the apparent depth of the normals.

Then finally, the intended behavior works as expected on the stone top table
in the Noble's room regardless of which interaction.fs I choose.

That points to the stone table having good smoothing groups whereas the wood table has some sort of smoothing group problem?

(Eg. It's possible to fix this problem by fixing the assets?)
stgatilov

stgatilov

06.08.2018 15:09

administrator   ~0010740

Last edited: 06.08.2018 15:10

The attached patch fixes (interpolated normal <--> bumpmapped normal) transition.

It means that:
1. If you have a mesh without bumpmapping, then the change will have no effect.
2. If you have a bumpmapped mesh with bad face groups (large faces with non-constant normal), then the issue will still remain. It will look a bit different, but the toggling will still happen. And near the edge of toggling the face starts looking flatter.
3. If you have a bumpmapped mesh with good face groups, then this patch will solve the toggling problem perfectly.

Ideally, large faces with non-constant normal should be removed by editing such models.

BTW, the effect of the change depends on the angle between light rays and surface. It has no effect when the angle is larger than 15 degrees. At angle = 0, the bumpmapping normals are completely ignored. During transition from 15 degrees to 0 degrees, the bumpmapped normals are gradually smoothened.
Strictly speaking, it works a bit differently, but the end results is about the same =)

stgatilov

stgatilov

04.01.2020 05:57

administrator   ~0012058

Last edited: 05.01.2020 12:32

Committed my change in svn rev 8495.
It can be enabled by cvar: r_testBumpmapLightTogglingFix 1 (disabled by default)

Not sure yet if this will be enabled or dropped.

stgatilov

stgatilov

05.01.2020 12:36

administrator   ~0012072

Committed another hack in svn rev 8502.

It should workaround triangle normal vs mesh normal issues (also known as stencil self-shadowing / popping).
Took point 2 from this post:
  https://forums.thedarkmod.com/index.php?/topic/19971-thief3-vs-doom3-stencil-shadows-polygon-popping-solutions/&do=findComment&comment=442623

Enabled with "r_testStencilSelfShadowFix 1".
Note that it forces soft shadows, since implementation is done in fragment shader.
nbohr1more

nbohr1more

09.05.2020 19:07

developer   ~0012485

Some artifacts for off angle rendering in 2.08 SVN:

https://forums.thedarkmod.com/index.php?/topic/19139-nonsmooth-graphics-due-to-bumpmapping/&do=findComment&comment=446918
nbohr1more

nbohr1more

20.05.2020 17:09

developer   ~0012527

Mostly working in 2.08

Moving to 2.09 for further fixes.
stgatilov

stgatilov

21.05.2020 03:45

administrator   ~0012538

Actually, nothing is working in 2.08.
There are a few experimental cvars which are all disabled by default.
And I guess it's better to remove at least the r_testStencilSelfShadowFix.
stgatilov

stgatilov

26.07.2020 06:28

administrator   ~0012676

Removed r_testStencilSelfShadowFix in svn rev 8884, leaving it forever disabled.
It was too bad.
stgatilov

stgatilov

26.07.2020 07:03

administrator   ~0012677

Speaking of this:
   Some artifacts for off angle rendering in 2.08 SVN:
   https://forums.thedarkmod.com/index.php?/topic/19139-nonsmooth-graphics-due-to-bumpmapping/&do=findComment&comment=446918
The problem was that light value computed from mesh normal could be negative, which caused surfaces to be darkened.
I fixed it in svn rev 8885.
stgatilov

stgatilov

26.07.2020 07:31

administrator   ~0012678

svn rev 8887:
1) renamed r_testBumpmapLightTogglingFix to r_useBumpmapLightTogglingFix
2) fixed its usage on new backend
3) enabled it by default

So now this fix is enabled for everyone. Let's see what would be feedback.

P.S. Note that the main problem (interpolated normal vs geometric normal difference and self-shadowing) is not solved at all.
I don't think I know a realistic way to improve it.
So I'll put the task to feedback, and mark is as resolved at 2.09.
nbohr1more

nbohr1more

13.01.2021 03:46

developer   ~0013453

As I can tell, there has been no negative feedback about the look of lighting and normal maps in 2.09 beta.

For my own feedback, it does reduce the strength of some normal maps a little but is very subtle and does not degrade
the overall visual impact of TDM in any significant way.

The benefits outweigh whatever minor drawbacks someone might perceive.

Issue History

Date Modified Username Field Change
05.06.2018 17:13 stgatilov New Issue
05.06.2018 17:13 stgatilov Status new => assigned
05.06.2018 17:13 stgatilov Assigned To => stgatilov
04.08.2018 10:46 stgatilov File Added: light_toggling_counter.patch
06.08.2018 03:18 nbohr1more Note Added: 0010738
06.08.2018 15:09 stgatilov Note Added: 0010740
06.08.2018 15:09 stgatilov Note Edited: 0010740
06.08.2018 15:10 stgatilov Note Edited: 0010740
06.08.2018 15:10 stgatilov Note Edited: 0010740
06.08.2018 15:10 stgatilov Note Edited: 0010740
20.12.2018 17:11 stgatilov Target Version TDM 2.07 => TDM 2.08
04.01.2020 05:57 stgatilov Note Added: 0012058
05.01.2020 12:32 stgatilov Note Edited: 0012058
05.01.2020 12:36 stgatilov Note Added: 0012072
09.05.2020 19:07 nbohr1more Note Added: 0012485
20.05.2020 17:09 nbohr1more Note Added: 0012527
20.05.2020 17:09 nbohr1more Target Version TDM 2.08 => TDM 2.09
21.05.2020 03:45 stgatilov Note Added: 0012538
26.07.2020 06:28 stgatilov Note Added: 0012676
26.07.2020 07:03 stgatilov Note Added: 0012677
26.07.2020 07:31 stgatilov Note Added: 0012678
26.07.2020 07:31 stgatilov Status assigned => feedback
13.01.2021 03:46 nbohr1more Note Added: 0013453
13.01.2021 03:46 nbohr1more Status feedback => resolved
13.01.2021 03:46 nbohr1more Resolution open => fixed
13.01.2021 03:46 nbohr1more Fixed in Version => TDM 2.09