Incorrect darkness in "software" sector light mode (easy fix included)

Bugs that have been resolved.

Moderator: Graf Zahl

Locked
Doom_user
Posts: 14
Joined: Tue Feb 21, 2006 5:07

Incorrect darkness in "software" sector light mode (easy fix included)

Post by Doom_user »

I'd like to propose and submit a bugfix code submission for the "software" sector light mode that emulates the software renderer's lighting in the gl renderer.

At lower light levels the "software" sector light mode incorrectly makes the area in front of the player literally 100% black and 0% visible. This is something that the software renderer does not do. It also makes things significantly harder for the player. I took some screenshots in a simple test level to demonstrate what I'm talking about.


"software" sector light mode
Image


software renderer
Image


The fix I propose is very simple

In "gzdoom.pk3" -> "shaders" -> "glsl" -> "main.fp" change this section

#ifdef SOFTLIGHT
float newlightlevel = 1.0 - R_DoomLightingEquation(lightlevel, gl_FragCoord.z);
color.rgb *= clamp(vec3(newlightlevel) + dlightcolor, 0.0, 1.0);
#endif

to this

#ifdef SOFTLIGHT
float newlightlevel = 1.0 - R_DoomLightingEquation(lightlevel, gl_FragCoord.z);
color.rgb *= clamp(vec3(newlightlevel) + dlightcolor, 0.03, 1.0);
#endif

and the result is

Image

Now the visibility in the darkness matches the software renderer 100%.

Edit:Just to show how accurate this fix is, if I force the gl shot into the doom palette, I get this

Image

Which is pretty much indistinguishable from the software renderer shot.
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Graf Zahl »

Can you attach the map the screenshots are from?
User avatar
Rachael
Developer
Developer
Posts: 3651
Joined: Sat May 13, 2006 10:30

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Rachael »

I've noticed that GZDoom incorrectly enforces pitch black on all sector light settings at "0". This would apply correctly for Heretic and Hexen since their colormap definitions actually fade to black, but in Doom it does not.

I've quickly hacked together a map that looks very much like the screenshot.
LightTest.wad
(1.09 KiB) Downloaded 70 times
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Graf Zahl »

Forcing black for 0 was necessary, The way OpenGL lighting works makes it very hard to get black with anything else.
Doom_user
Posts: 14
Joined: Tue Feb 21, 2006 5:07

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Doom_user »

Here's the test map I used for the screenshots.
Attachments
test.wad
(11.86 KiB) Downloaded 69 times
User avatar
Rachael
Developer
Developer
Posts: 3651
Joined: Sat May 13, 2006 10:30

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Rachael »

Well, here is the problem:

GZDoom assumes that 0 is absolute blackness in Doom. While that is true for Heretic, Hexen, and Strife, it is not true for Doom. (And it seems, for Heretic, it's not even black, just the darkest available gray)

However, 0 brightness for Doom is actually really really dark. So dark, that most CRT monitors of its day do see it as pitch black without gamma correction. So that leaves a little bit of a dillema:

If you correct the problem for Doom, it will break both Heretic and Hexen. If you leave it as is, obviously, it breaks Doom.

And another problem is, you cannot just release one shader file to fix the problem. The shader has to be recustomized for both GZDoom 2.x and 1.x variants. (The calculations will remain the same, however the code itself will not). Do note, however, that the end screen result will look the same with both GZDoom versions, it's only the code under the hood that's changed.

Personally, I think it would be better to just support a user option, which defaults one way in Doom and another way everywhere else, but can be recustomized with any game.

I've noticed that ZDoom has the opposite problem: It actually assumes that 0 blackness is the same in other games as it is in Doom. Which complicates things even more.

Unfortunately, the spoiler tags break the Lightbox mod on this forum (dunno how I wanna fix that, yet) but you can still right-click each image and download them for a full view. I think even their small size is enough to show the problem though. If not, turn up your display's gamma correction to see it.
Spoiler: Screenshots Side-by-side - Doom 2 - ZDoom, then GZDoom
Spoiler: Screenshots Side-by-side - Heretic - ZDoom, then GZDoom
Here's the level used to generate these shots: (It's the same one I posted before, except the sector brightness is now 0)
BlackTest.wad
(1.09 KiB) Downloaded 64 times
For reference, Hexen had the same output as Heretic, and Strife had a rather humorous result (due to the texture being unavailable).
Spoiler: Attachments (to not break this post's functionality):
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Graf Zahl »

Well, it all looks pitch black to me.
User avatar
Rachael
Developer
Developer
Posts: 3651
Joined: Sat May 13, 2006 10:30

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Rachael »

Graf Zahl wrote:Well, it all looks pitch black to me.
Here it is with a horrible looking 3.0 gamma correction then.
NotPitchBlack-Gamma3.0.png
NotPitchBlack-Gamma3.0.png (198.92 KiB) Viewed 1386 times
At any rate, yes it is somewhat important to me because I do play using monitors that show darker color values differently than pitch black. I can't imagine playing with a monitor that does not get those correct.

But, I can always just customize the shader myself, anyway.
User avatar
Graf Zahl
GZDoom Developer
GZDoom Developer
Posts: 7148
Joined: Wed Jul 20, 2005 9:48
Location: Germany
Contact:

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Graf Zahl »

Ok, added the new value. But since the shader in GZdoom 2.x has changed, the results can be a bit different.
Doom_user
Posts: 14
Joined: Tue Feb 21, 2006 5:07

Re: Incorrect darkness in "software" sector light mode (easy fix included)

Post by Doom_user »

Graf Zahl wrote:Ok, added the new value. But since the shader in GZdoom 2.x has changed, the results can be a bit different.
Sorry for the slow response. There's a problem with the way you implemented this fix in GZdoom 2.x. You implemented the 0.03 value in the wrong section. As a result, the absolute darkness in front of the player remains.

Image

To fix this, you need to undo the incorrect implementation (commit 3334b28a02da663b904280de951b3a158c75aace), and then, In "gzdoom.pk3" -> "shaders" -> "glsl" -> "main.fp" change this section



#endif
color.rgb = clamp(color.rgb + desaturate(dynlight).rgb, 0.0, 1.4);

// prevent any unintentional messing around with the alpha.
return vec4(color.rgb, vColor.a);



to this



#endif
color.rgb = clamp(color.rgb + desaturate(dynlight).rgb, 0.03, 1.4);

// prevent any unintentional messing around with the alpha.
return vec4(color.rgb, vColor.a);



which results in this

Image

which is 100% identical to the software renderer and the GZdoom 1.x fix from the first post.
Locked

Return to “Closed Bugs”