View Issue Details

IDProjectCategoryView StatusLast Update
0004825The Dark ModGraphicspublic21.05.2020 03:45
Reporterstgatilov Assigned Tostgatilov  
PrioritynormalSeveritytweakReproducibilityalways
Status assignedResolutionopen 
Product VersionTDM 2.06 
Target 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.

Activities

stgatilov

stgatilov

04.08.2018 10:46

developer  

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;
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

developer   ~0010740

Last edited: 06.08.2018 15:10

View 5 revisions

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

developer   ~0012058

Last edited: 05.01.2020 12:32

View 2 revisions

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

developer   ~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

developer   ~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.

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 View Revisions
06.08.2018 15:10 stgatilov Note Edited: 0010740 View Revisions
06.08.2018 15:10 stgatilov Note Edited: 0010740 View Revisions
06.08.2018 15:10 stgatilov Note Edited: 0010740 View Revisions
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 View Revisions
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