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

Max draw distance setting #2695

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

Conversation

dileepvr
Copy link
Contributor

@dileepvr dileepvr commented Sep 3, 2024

Added the ability to not draw any node in the BSP whose bounding box is farther from the viewpoint than a maxdrawdist value from struct Flevellocals. Works in both hardware and software renderer modes.

Demo of speed up in Frozen Time bridge scene on a 12-year old CPU: https://www.youtube.com/watch?v=2oUUpMxDngc
maxdrawdist can be supplied from MAPINFO lump as well as changed from console live. It will persist through saved games. Default is set to -1, and won't activate unless greater than 0.

The absence of drawn regions will show up as void space with clearbuffer color (normally controlled by the existing CVar r_clearbuffer). If using fog, this color can be set to match the local or global fog fade color by either setting the LEVEL3_VOIDFADETOFOG flag (set voidfadetofog in MAPINFO lump) or setting r_clearbuffer to 5.

I wish I knew how to just replace the void space with a sky box but couldn't figure it out.

…culling. Can chang from console. Works for both hardware and software rendering, but with different effects. Test with something like Frozen Time wad.
…ibly exposed to zscript (verify). Added a mode to CVar r_clearbuffer (== 5) where the void gets the fog fade color.
…ing in some subsectors within distance not being rendered). Centered the camera for orthographic projection.
@MajorCooke
Copy link
Contributor

MajorCooke commented Sep 3, 2024

Uh, wrong video?

Also if it isn't already, I'd recommend the ability to set this via mapinfo with the cvar overriding it if it's not at 0 or something like that.

@dileepvr
Copy link
Contributor Author

dileepvr commented Sep 3, 2024

Err... fixed. (That could have gotten so wrong)

Yes. Both maxdrawdist (float) and voidfadetofog (flag) can be set in mapinfo.

@MajorCooke
Copy link
Contributor

Watching the video, a couple things came to mind.

  1. I think the fog options should be moved to Display options, gameplay options is for affecting actual gameplay and not visuals.
  2. Can those cvars be made as options in the menus as well? Could be another option set in the display menus, along with a simple toggle cvar switch to quickly turn it on/off?

@dileepvr
Copy link
Contributor Author

dileepvr commented Sep 3, 2024

The Fog Effect thing is just a mod I was using. It isn't part of the commit.

I'll need to think about a menu option for toggling maxdrawdist and clearbuffer color and get back to you. Trivially done of course, but I hope others chime in as well. I stumbled on r_clearbuffer already existing.

@MajorCooke
Copy link
Contributor

Oh! Can you show me where that mod is?

@dileepvr
Copy link
Contributor Author

dileepvr commented Sep 3, 2024

Fog Effects by Sergeant Mark IV (standalone version of whatever BD uses, I think): https://www.moddb.com/mods/brutal-doom/addons/fog-effects

@MajorCooke
Copy link
Contributor

MajorCooke commented Sep 3, 2024

Thanks!

The Fog Effect thing is just a mod I was using. It isn't part of the commit.

I'll need to think about a menu option for toggling maxdrawdist and clearbuffer color and get back to you. Trivially done of course, but I hope others chime in as well. I stumbled on r_clearbuffer already existing.

That's fair, it's merely a suggestion because it fits with being able to toggle fog on and off. Just figured having an easy switch would be nice. "On", "Off", and "Map Based" (or "Default" if you want to keep to the naming convention for Allow Jump/Crouch)

Also this feature has me thinking about the above issue I made but no need to address here, unless you want to. Just planting the seed for improving fog is all.

@inkoalawetrust
Copy link
Contributor

So does the fog not automatically turn on if the subsector cull distance is enabled? The map needs to either have VOIDFADETOFOG or you need to type r_clearbuffer 5 to the console?

Because if that's how it works right now then it feels like an oversight IMO. The game looks pretty bad with just the plain culling. And most maps won't have the flag to replace culled geometry with fog on. Which is a problem because people will use this to make otherwise large and slow maps run faster. You basically demonstrated this with Frozen Time, it obviously doesn't have the map flag on, but people will use the render distance CVAR/setting to run the map faster, and it'll have no fog unless they know to type a very specific command in, which they probably WON'T know how to do.

So I think the behavior of VOIDFADETOFOG should probably be on by default whenever a maximum render distance is set.

@dileepvr
Copy link
Contributor Author

It is actually a little worse than that. It is setting the void color to viewPoint.sector->Colormap.FadeColor. So unless the map maker put some fog in, or a mod was used to put fog in like I did, the void will be black not matter what CVARs are set. But you are right. VOIDFADETOFOG should probably be on by default.

I don't know if the engine should be fogging up the map by itself (after checking for existing fog density to be zero, and setting it to one everywhere). That is how mid-late 90s' 3D games did it I think?

…amps to maximum of computed fog density versus that set by mapper.
…ys painting the void with fog/fade color by default (in HW renderer).
@dileepvr
Copy link
Contributor Author

The void now gets the fog/fade color by default (as per request) unless a level flag is set or gl_fogmode == 0. I even add a maxdrawdist dependent weak fog density to all sectors that don't explicitly have an even higher fogdensity set. And I add a black FadeColor to all sector colormaps that don't have one if maxdrawdist > 0.0. It reverts to regular defaults if maxdrawdist is reset to <= 0.0 at any time through the console.

I am also setting a maximum value for skyfog (density) in the level when maxdrawdist > 0.0. This "solved" the sky pop-in problem by making it invisible.

@MajorCooke
Copy link
Contributor

Can you record a quick video to show it in action? I'm curious.

@SafinW
Copy link

SafinW commented Sep 14, 2024

I accidently pressed the approve button sorry lol.

@dileepvr
Copy link
Contributor Author

Video of auto-fog/fade effect: https://youtu.be/hfmrBEGH9Dg

I am not happy with this. I need to make the fog only turn on in the last 10% of the draw distance, and work with enhanced vision modes. But that will require intervention in the shader code.

…aggressively kick in at half the maxdrawdist. This allowed for nearby fogdensity to be a lot less.
@dileepvr
Copy link
Contributor Author

Soft, late-kick-in fog boundary, so the closer fog density is lower by 10x: https://youtu.be/n4GktOPwp_w

Required an if-block in the main fragment shader.
I can't make lightAmp and other enhanced vision modes see the fog since isFullbrightScene() gets called in too many places.

@RicardoLuis0
Copy link
Collaborator

would it be at all possible to, optionally, make the render distance adjust itself based on current FPS vs monitor refresh rate?

@dileepvr
Copy link
Contributor Author

You mean an actual performance mode that can be toggled from the options menu? I don't know how to read the monitor refresh rate, but could probably copy the CalcFps() from d_main.cpp to wherever I need and adjust the draw distance every second (or every tic) by some percentage until a lower threshold is satisfied. Or it has two rates, and it is always slowly trying to get bigger over time, but aggressively shrinks when fps drops.

What does this look like from a UI perspective? The Options menu has an On/Off option for "Performance Mode", a number value for "Minimum FPS," and a color picker for "fog color"? And should I allow maxdrawdist to become -1.0 to disable it if the fps is high enough? Because disabling will cause the skybox to show up again, making it visually jarring. We could declare, "no skies in performance mode" even though rendering skies themselves were never the performance killer.

@dileepvr
Copy link
Contributor Author

The other issue might be the something like nuts.wad isn't slow because of geometry, but merely because of too many actors. And a naive user toggling the performance mode will see no difference. I don't want any of this to affect playsim. Would a simple renaming like "performance rendering" help?

@RicardoLuis0
Copy link
Collaborator

RicardoLuis0 commented Sep 16, 2024

something like nuts.wad isn't slow because of geometry, but merely because of too many actors

it's not slow because of too many actors ticking, but because of too many actors rendering, so yes, this would help (you can verify it's the renderer by running it in software mode (without software mode lights enabled) at 320x200, it'll run fine)

@RicardoLuis0
Copy link
Collaborator

always slowly trying to get bigger over time, but aggressively shrinks when fps drops.

yeah, that

We could declare, "no skies in performance mode" even though rendering skies themselves were never the performance killer.

oh, i didn't realize that this completely disabled skyboxes, that might be a deal breaker yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants