Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix r_forceAmbient comparison #1510

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

VReaperV
Copy link
Contributor

No description provided.

@DolceTriade
Copy link
Contributor

for the peanut gallery, why was the before comparison wrong?

@VReaperV
Copy link
Contributor Author

r_forceAmbient ranges in [0.0; 0.3], while tmpAmbient is in range of [0; 255].

@DolceTriade
Copy link
Contributor

I meant in the commit message or PR description.

@VReaperV
Copy link
Contributor Author

Oh, sure, I added it to the commit description.

@slipher
Copy link
Member

slipher commented Jan 22, 2025

Setting it to 0 ought to mean no modification to the light grid. But if I set r_forceAmbient to 0 it makes stuff way brighter anyway.

Before r_forceAmbient changes (with any cvar value as it makes no difference):

unvanquished-sokolov-alienbase

With this PR and r_forceAmbient 0:

unvanquished-sokolov-alienbase

Also I think the light factor handling should be different. IMO it should target the final light value, not the pre-lightfactor-scaling value. With the max value of .3 something even seems to overflow somehow and it is less bright than with 0.

@VReaperV
Copy link
Contributor Author

Setting it to 0 ought to mean no modification to the light grid. But if I set r_forceAmbient to 0 it makes stuff way brighter anyway.

Before r_forceAmbient changes (with any cvar value as it makes no difference):

The original code was supposed to set it to the value provided by the map in this case, it was just broken.

On hangar28 it works as you'd expect when the map doesn't set any value there:
0:
unvanquished_2025-01-23_005938_000
0.3:
unvanquished_2025-01-23_005958_000

Perhaps it should be changed such that this behaviour is used if the cvar is set to -1.0 instead?

Also I think the light factor handling should be different. IMO it should target the final light value, not the pre-lightfactor-scaling value. With the max value of .3 something even seems to overflow somehow and it is less bright than with 0.

That I agree with.

@VReaperV
Copy link
Contributor Author

I've added both of these changes here.

@slipher
Copy link
Member

slipher commented Jan 23, 2025

IIUC the worldspawn _color or ambientColor keyword is not supposed to do anything unless the map light grid is broken or missing. Is that correct?

@VReaperV
Copy link
Contributor Author

Not entirely.

This seems to be an XreaL feature, and from what I can tell:
If there's no lightGrid, either the worldspawn or r_forceAmbient value is used:
https://github.com/QuakeEngines/ET-XreaL/blob/7e5bcc9082d85ecf9cc3b29ccbddba21e80d7c06/src/engine/rendererGL3/tr_light.c#L375-L386
If the interpolated grid light average of the three colour channels is < r_forceAmbient (for ambient light), then r_forceAmbient value is used instead:
https://github.com/QuakeEngines/ET-XreaL/blob/7e5bcc9082d85ecf9cc3b29ccbddba21e80d7c06/src/engine/rendererGL3/tr_light.c#L266-L271

There might be a slight difference in doing this check on lightGrid points rather than the interpolated value, but I don't think it would make much of a difference.

@slipher
Copy link
Member

slipher commented Jan 23, 2025

If the interpolated grid light average of the three colour channels is < r_forceAmbient (for ambient light), then r_forceAmbient value is used instead:
https://github.com/QuakeEngines/ET-XreaL/blob/7e5bcc9082d85ecf9cc3b29ccbddba21e80d7c06/src/engine/rendererGL3/tr_light.c#L266-L271

Oh right, R_LightForPoint is also affected (not that this makes any sense, if you're not going to modify the light grid samples anywhere else). But for the vast majority of maps, which have a valid light grid and no realLight particles, nothing should be affected.

@VReaperV
Copy link
Contributor Author

Oh right, R_LightForPoint is also affected (not that this makes any sense, if you're not going to modify the light grid samples anywhere else).

I think that's because it was originally used for entities as well, but the r_forceAmbient use was lost with the GLSL transition.

@VReaperV
Copy link
Contributor Author

VReaperV commented Jan 26, 2025

Anyway, if there are no further concerns with these changes, I'll merge them a bit later.

Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some maps, with all default settings, this somehow makes the light grid darker rather than brighter. Before/after on nano
unvanquished-nano-overmind

unvanquished-nano-overmind

if ( tr.legacyOverBrightClamping )
{
R_ColorShiftLightingBytes( tmpAmbient );
R_ColorShiftLightingBytes( tmpDirected );
}

const byte forceAmbientNormalised = floatToUnorm8( r_forceAmbient.Get() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overbright is still not taken into account in non-clamped mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what the multiplication by lightFactor does in the shader?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we request minimum light of 0.4 then that should be applied as x = max(0.1, x) in the light grid since it will be multiplied later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.1 being 0.4 / tr.mapLightFactor? Or where does it come from?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that gives wrong results.
This pr without the scaling:
unvanquished_2025-01-27_023602_000
Dividing by tr.mapLightFactor:
unvanquished_2025-01-27_023954_000
Both are with default overbright values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the scaling is done after comparison, it's also wrong:
unvanquished_2025-01-27_023523_000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But beside that, I don't really see where the lightGrid values would be multiplied by anything extra in case of r_forceAmbient being < the value in the lightGrid. It's just substituting the values after they're normalised to [0; 1] range.

Cvar::Range<Cvar::Cvar<float>> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid", Cvar::NONE,
0.125f, 0.0f, 0.3f );
Cvar::Range<Cvar::Cvar<float>> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value", Cvar::NONE,
0.125f, -1.0f, 0.3f );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The _color keyword is used in a lot of extant maps, sometimes with pretty large values. I imagine it must have some meaning for q3map2 which is distinct from this XReal renderer's meaning. Maybe we should remove the _color worldspawn key (leaving just ambientColor) so that it doesn't mess up those maps.

Should probably be cheat, that's a big cheat to make models always displayed brightly. Maybe a bigger cheat even than r_gamma since you could make only the targets be bright, rather than everything

Copy link
Contributor Author

@VReaperV VReaperV Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's this in q3map:
https://github.com/id-Software/Quake-III-Arena/blob/dbe4ddb10315479fc00086f08e25d968b4b43c49/q3map/lightv.c#L4941
But I can't find any notion of that being used in the game's code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's what I'm saying. _color is intended for the map compiler and interpreting it like that in the renderer seems bad and wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the check for _color key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the cheat comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question... Maybe it should just be restricted to a lower range? The problem is that there are no real gameplay means of lighting up an area (firebomb with dynamic lights doesn't really count).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea, maybe this could be an alternative to r_gamma that degrades the map's aesthetics less.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking that too.

@VReaperV VReaperV force-pushed the fix-force-ambient branch 2 times, most recently from 420a9a8 to b8b0936 Compare January 26, 2025 23:01
@VReaperV
Copy link
Contributor Author

On some maps, with all default settings, this somehow makes the light grid darker rather than brighter. Before/after on nano unvanquished-nano-overmind

unvanquished-nano-overmind

Fixed.

@VReaperV VReaperV force-pushed the fix-force-ambient branch 2 times, most recently from fb9d9ca to 05e4367 Compare January 28, 2025 20:30
Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still getting altered grid lighting for all the maps I test (nano, plat23 and sokolov). Sokolov has the biggest difference (much brighter). I'm still confused why this is happening... reading the code it looks like there should be no difference as long as ambientColor and r_forceAmbient are not set.

src/engine/renderer/tr_bsp.cpp Outdated Show resolved Hide resolved
Cvar::Range<Cvar::Cvar<float>> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid", Cvar::NONE,
0.125f, 0.0f, 0.3f );
Cvar::Range<Cvar::Cvar<float>> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid; -1 to use map value", Cvar::NONE,
0.125f, -1.0f, 0.3f );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the cheat comment?

@VReaperV VReaperV force-pushed the fix-force-ambient branch 2 times, most recently from 779b491 to 3fd76e5 Compare January 29, 2025 23:05
@VReaperV
Copy link
Contributor Author

Still getting altered grid lighting for all the maps I test (nano, plat23 and sokolov). Sokolov has the biggest difference (much brighter). I'm still confused why this is happening... reading the code it looks like there should be no difference as long as ambientColor and r_forceAmbient are not set.

Any specific viewpos? I checked on Sokolov at spectator spawn after rebasing and fixing && to ||, looked the same to me compared to 0.55.2.

@slipher
Copy link
Member

slipher commented Jan 29, 2025

Any specific viewpos? I checked on Sokolov at spectator spawn after rebasing and fixing && to ||, looked the same to me compared to 0.55.2.

How are you going to check at the spectator spawn? There need to be players or buildables to see the light grid changes. I'm seeing the differences on buildables as in the screenshots posted upthread.

@VReaperV
Copy link
Contributor Author

Well, I just built the same buildings in that are on this branch and on 0.55.2.

@VReaperV
Copy link
Contributor Author

(it also affects the first-person weapon)

@slipher
Copy link
Member

slipher commented Jan 29, 2025

If I check out this PR and go to the alien base on Sokolov, it is still a lot brighter. Closer to the second screenshot than the first in #1510 (comment)

@VReaperV
Copy link
Contributor Author

I get this in alien base on Sokolov:
unvanquished_2025-01-30_024722_000
Do note though that r_forceAmbient should be set to -1 to disable it.

@slipher
Copy link
Member

slipher commented Jan 29, 2025

I see. I assumed -1 is supposed to be the default value. So is that an intentional change, to light everything up so it is easier to see for gameplay purposes or something?

@VReaperV
Copy link
Contributor Author

Not really, I just didn't touch the default value.

@slipher
Copy link
Member

slipher commented Jan 29, 2025

If that is not intentional then let's set it to -1

@VReaperV
Copy link
Contributor Author

VReaperV commented Jan 29, 2025

Yeah, that makes sense, changed now.

r_forceAmbient ranges in [0.0; 0.3], while tmpAmbient is in range of [0; 255].
Allow using 0 as an actual value.
Avoid overflow and incorrect results due to the overbright shift.

Also fix `r_forceAmbient` affecting lightGrid points inside of walls.
`_color` is used by q3map2 for some internal purposes, so don't use it here.
This cvar used to have no effect after lightGrid code was moved to GLSL, so disable it by default to keep the lighting the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants