Skip to content

Removing block that prevented volumetric and background nebulae from rendering simultaneously #6853

Merged
BMagnu merged 9 commits into
scp-fs2open:masterfrom
combatlombax:master
Sep 5, 2025
Merged

Removing block that prevented volumetric and background nebulae from rendering simultaneously #6853
BMagnu merged 9 commits into
scp-fs2open:masterfrom
combatlombax:master

Conversation

@combatlombax

Copy link
Copy Markdown
Contributor

Incredibly simple change that removes a logical condition that prevented volumetric nebulae and background nebulae from rendering at the same time. Line 525 of gropengldeferred.cpp.

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Incredibly simple change, indeed, but I'd like @BMagnu to review this one. It's entirely possible the exclusion was deliberate.

@BMagnu BMagnu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not quite as simple here.
Mainly, because the fog step (both normal and volumetrics) also does image compositing in FSO. To understand that, have a look at the else block, if no type of fog is active:
It copies the image from GL_COLOR_ATTACHMENT5 (which, in FSO, is the result of the lighting pass, also called the composite buffer) to GL_COLOR_ATTACHMENT0, also called the color buffer, which is used to further draw the frame.
The fog works the same way. Both types of fog will read from the composite buffer (and some others) to then draw into the color buffer. If both fogs were active like this, they would both write into the color buffer in a way that overrides each other.

We could have both fogs active, but we need to take some precautions here:

  1. First render the fullneb fog if its requested.
  2. If we did have fullneb active, and we need to do volumetrics after, then we need to take the result of the fullneb fog, and copy it back to the composite buffer (this works by calling glBlitFramebuffer as done in the else block here, but with the draw framebuffer set to GL_COLOR_ATTACHMENT5, and the read framebuffer set to GL_COLOR_ATTACHMENT0)
  3. Then we can do the volumetrics fog as it was done before.
  4. Only if neither of the two fog types were active, perform the manual composite step in the original else block with the // Transfer the resolved lighting back to the color texture comment

If we do it like this, we can probably have both fogs working correctly in parallel.
It might also be possible to change both fog shaders to work with additive blending to avoid that copy in step 2, but that's probably more trouble than its worth.

And just as an aside:
nebula_handle_alpha in neb.cpp, L1140 would probably need to be adjusted accordingly, though I'm not fully sure how both alpha's would combine if we render the nebulae as proposed above.

@wookieejedi wookieejedi added discussion This issue has (or wants) a discussion graphics A feature or issue related to graphics (2d and 3d) labels Jul 22, 2025

@combatlombax combatlombax left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alrighty! I think this should do what you need it to now. FWIW, I realized also, I messed up the boolean logic for the "else" case, so I cached out both those checks you had in there and if both are false, then we fall back into that case, so hopefully nothing gets messed up.

@BMagnu

BMagnu commented Sep 5, 2025

Copy link
Copy Markdown
Member

Yup, the nebula render section looks good now.
Have you tested this with something that has both types of nebula to make sure it behaves correctly?
Also, remember that the nebula_handle_alpha function in nep.cpp, at line 1145 needs to be adjusted.
That if currently switches between the nebula types, but if both are on it's probably fine to just multiply the two alphas.

@BMagnu BMagnu merged commit 31d73b7 into scp-fs2open:master Sep 5, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion This issue has (or wants) a discussion graphics A feature or issue related to graphics (2d and 3d)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants