View Issue Details

IDProjectCategoryView StatusLast Update
0005862The Dark ModGraphicspublic17.11.2024 10:13
ReporterSpooks Assigned Tostgatilov  
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
OSWindowsOS Version7 
Product VersionTDM 2.09 
Target VersionTDM 2.10Fixed in VersionTDM 2.10 
Summary0005862: Backface lighting + bumpmapping broken
DescriptionA long time back, as far as TDM 2.03, Arcturus or rich_is_bored, I forget who, posted a material snippet on the forums that I found could be used as a trick for faking translucency in materials, cloth for instance. It involves taking a material's bump map stage and flipping it with the "scale" keyword so that it appears that lights hit it from the reverse side. This doesn't make the material visibly translucent to the player, obviously, but it makes it look like it is thin enough for lights to pass through it.

I used this trick to make materials/skins for the curtains in my WIPs. These worked fine as late as 2.08, but the material definition doesn't work anymore in 2.09 (or 2.10).

It's somewhat hard to explain how the whole setup works and looks, and to my knowledge no FM actually has used it yet. This is why I'll include a .pk4 for testing where you can see how the curtains interact with lights. At any rate, this is based on functionality that was present before and isn't now. I've tried different values in the second <exp> parameter of the "scale" line in the material, and while there are some visible differences, the light hitting the curtain won't flip like it does in 2.08.
Steps To ReproduceCompare the appearance of the blue curtains in the test map, "mech", between TDM 2.08 and 2.09. The material that stops working is "curtain01_blue_translucent" in "translucent.mtr".
TagsNo tags attached.
Attached Files
WIP_story_depr.pk4 (229,001 bytes)

Relationships

related to 0005718 closedorbweaver Vertex blended model material unable to support two bumpmaps. 
related to 0003382 assignedSpringheel Check out Rich's translucent textures 

Activities

nbohr1more

nbohr1more

01.01.2022 16:45

developer   ~0014624

This probably broke when we switched to forcing RGTC compression in 2.09.
There is no blue channel to invert.

Using "forceHighQuality" in the material def should prevent this conversion but it doesn't seem to work?
stgatilov

stgatilov

02.01.2022 05:18

administrator   ~0014625

Last edited: 03.01.2022 09:34

scale(models/darkmod/props/textures/curtain01_local, 1, 1, 0, 1)

It does not invert anything, it simply removes blue component.
That's not a good thing to do, because normal map is no longer normalized, and it is up to receiver to decide how to treat it.
That's what is usually described as "undefined/unspecified behavior".

One can either ignore blue channel (that's the most natural thing to do for RGTC compressor) so that the scaling has no effect.
Or one can normalize all pixels (by Euclidean norm) and obtain normal map with all normals parallel to surface.
Even in the latter case, nothing is inverted, instead surfaces are bent to set maximum slope (90 degrees) of every surface fragment while saving its direction.
Doom 3 engine originally used DXT5nm normal maps compression, and probably DXT5nm compressors treated unnormalized normal maps in yet another way, but that was dependent on OpenGL driver.

Anyway, I am against restoring or guaranteeing any specific behavior for unnormalized normal maps.
But if someone knows exact math, we can add a new image program function that would normalize normal map as desired.

UPDATE: Here I forgot that [0..1] color is remapped to [-1..1] vector coordinate.
So setting blue to 0 means changing vector (x, y, z) to (x, y, -1)
Given that z is usually very close to 1, (x, y, -1) is very close to (x, y, -z), which means mirroring bumpmap by surface's plane.
nbohr1more

nbohr1more

02.01.2022 05:45

developer   ~0014626

Last edited: 02.01.2022 05:47

See the "Back Lighting Example" on this Polycount wiki:

http://wiki.polycount.com/wiki/Normal_map

That wiki claims that inverting the blue channel would be the desired design.

Rich_is_Bored implemented this in Doom 3 via the scale changes above:

https://forums.thedarkmod.com/index.php?/topic/11515-real-translucency-anyone/

https://www.youtube.com/watch?v=KOZdTo1EmOY

I suppose another way to accomplish this is to simple create another normal map image and point the material def at both.
The scale hack was to reduce the number of textures needed.
duzenko

duzenko

02.01.2022 09:01

developer   ~0014627

Can't you simply slap an ambient light there?
stgatilov

stgatilov

02.01.2022 11:22

administrator   ~0014629

Last edited: 02.01.2022 11:43

Unfortunately, we cannot inverse blue channel.
RGTC compression assumes that Z is always positive, there is no way to put sign to Z coordinate of normal.
I'm afraid back-face lighting has to be achieved by some other means.

UPDATE: on the other hand, there is no reason for it not to work with forceHighQuality.
nbohr1more

nbohr1more

02.01.2022 12:38

developer   ~0014632

I think we need to determine whether the forceHighQuality keyword is broken or whether vertex blending no longer
works for normal maps ( issue 5718 )... the latter being a much larger issue.
stgatilov

stgatilov

03.01.2022 12:34

administrator   ~0014635

I found that forceHighQuality indeed does not work in the perfect way.
Our current code always treats bumpmap as saved in RGTC format (even if it has plain RGB8 format), and thus shaders compute Z as sqrt(1 - x*x - z*z).
I have found a way to fix it for old backend right now.
Another issue is that old backend shaders take normal vector from AGB colors instead of RGB for non-RGTC inputs (new backend shaders does not even have such a case).

Second problem which blocks back-lighting is the fix I introduced in 0004825 (it can be disabled by r_useBumpmapLightTogglingFix).
It is the one which gradually reduced NdotL term as the angle between light rays and mesh interpolated normal gets closer to 90 degrees.
When light is on the other side of the surface, it zeros NdotL term.
I think the solution would be to use this hack only for single-sided surfaces, and to not use it for double-sided ones.
stgatilov

stgatilov

03.01.2022 15:21

administrator   ~0014636

Fixed in the following revisions:
  r9776. Support uncompressed normal maps in old backend.
  r9777. Disable useBumpmapLightTogglingFix for two-sided materials (also old backend).
  r9778. Fixed non-RGTC textures and bumpmap-toggling fix on new backend too.

Basically, I restored non-RGTC (uncompressed) bumpmaps, along with the natural way of normalizing vectors.
Then I disabled "bumpmapping light toggling fix" for surfaces with two-sided material.
nbohr1more

nbohr1more

03.01.2022 23:36

developer   ~0014639

I have confirmed that adding "forceHighQuality" to the material in the test map fixes the issue.
"Real translucency" works again! Thank you!
translucent.mtr (775 bytes)   
curtain01_blue_translucent
{
	twosided

    // first pass

    {
        blend    bumpmap
        map      models/darkmod/props/textures/curtain01_local
	forceHighQuality
    }
	specularmap	models/darkmod/props/textures/curtain01_s
    {
        blend    diffusemap
        map    models/darkmod/props/textures/curtain01_blue_d
        rgb    1
    }

    // second pass
    // the scale function here is "inverting" the normal map so that it catches light from the opposite side.

    {
        blend    bumpmap
        map    scale(models/darkmod/props/textures/curtain01_local, 1, 1, 0, 1)
	forceHighQuality
    }
	
    {
        blend    diffusemap
        map    models/darkmod/props/textures/curtain01_blue_d
        rgb    0.4
    }
}
translucent.mtr (775 bytes)   
nbohr1more

nbohr1more

12.11.2024 00:13

developer   ~0016913

Last edited: 12.11.2024 00:46

Regression in 2.13 Dev Build 10890
Last known working build 10869

Under investigation...

10874 works
10883 broken

Regression happened in 10875
nbohr1more

nbohr1more

12.11.2024 01:56

developer   ~0016914

Reverting the single line 37 in interaction.shadowmap.fs.glsl fixes it:

old (working):
vec3 worldNormal = mat3(u_modelMatrix) * (var_TangentBitangentNormalMatrix * props.localN);

new (broken)
vec3 worldNormal = mat3(u_modelMatrix) * var_TangentBitangentNormalMatrix[2];

maybe we need a branch for non-POM materials here?
stgatilov

stgatilov

17.11.2024 10:13

administrator   ~0016917

I added copying of the sign from bumpmap normal in svn rev 10901.
Works fine now.

Thank you!

Issue History

Date Modified Username Field Change
01.01.2022 13:46 Spooks New Issue
01.01.2022 13:46 Spooks File Added: WIP_story_depr.pk4
01.01.2022 16:40 nbohr1more Assigned To => duzenko
01.01.2022 16:40 nbohr1more Status new => confirmed
01.01.2022 16:40 nbohr1more Description Updated
01.01.2022 16:45 nbohr1more Note Added: 0014624
01.01.2022 16:52 nbohr1more Target Version => TDM 2.10
02.01.2022 05:18 stgatilov Note Added: 0014625
02.01.2022 05:18 stgatilov Severity normal => feature
02.01.2022 05:45 nbohr1more Note Added: 0014626
02.01.2022 05:47 nbohr1more Note Edited: 0014626
02.01.2022 09:01 duzenko Note Added: 0014627
02.01.2022 11:22 stgatilov Note Added: 0014629
02.01.2022 11:43 stgatilov Note Edited: 0014629
02.01.2022 12:36 nbohr1more Relationship added related to 0005718
02.01.2022 12:38 nbohr1more Note Added: 0014632
03.01.2022 09:34 stgatilov Note Edited: 0014625
03.01.2022 12:34 stgatilov Note Added: 0014635
03.01.2022 15:18 stgatilov Summary "scale <exp>, <exp>" material keyword broken => Backface lighting + bumpmapping broken
03.01.2022 15:19 stgatilov Assigned To duzenko => stgatilov
03.01.2022 15:19 stgatilov Status confirmed => assigned
03.01.2022 15:21 stgatilov Status assigned => resolved
03.01.2022 15:21 stgatilov Resolution open => fixed
03.01.2022 15:21 stgatilov Fixed in Version => TDM 2.10
03.01.2022 15:21 stgatilov Note Added: 0014636
03.01.2022 23:36 nbohr1more Note Added: 0014639
03.01.2022 23:36 nbohr1more File Added: translucent.mtr
01.02.2022 04:43 nbohr1more Category Script/Def => Graphics
22.12.2022 04:35 nbohr1more Relationship added related to 0003382
12.11.2024 00:13 nbohr1more Note Added: 0016913
12.11.2024 00:29 nbohr1more Note Edited: 0016913
12.11.2024 00:35 nbohr1more Note Edited: 0016913
12.11.2024 00:46 nbohr1more Note Edited: 0016913
12.11.2024 01:56 nbohr1more Note Added: 0016914
17.11.2024 10:13 stgatilov Note Added: 0016917