Skip to content

fix: support seasons swaps in PBR and TerrainHelper#1099

Merged
alandtse merged 10 commits into
community-shaders:devfrom
hakasapl:pbr-seasons-fix
Jun 17, 2025
Merged

fix: support seasons swaps in PBR and TerrainHelper#1099
alandtse merged 10 commits into
community-shaders:devfrom
hakasapl:pbr-seasons-fix

Conversation

@hakasapl
Copy link
Copy Markdown
Contributor

@hakasapl hakasapl commented May 27, 2025

This allows the vanilla function to execute and create the vanilla materials and shaders. We technically do not need the materials and shaders to be created for PBR but it allows hooks from other plugins to run.

This enables PBR to see the updated swaps from seasons of skyrim for example. There is a 2nd part of fixing seasons with PBR which is in this PR for seasons of skyrim: powerof3/SeasonsOfSkyrim#7

Let me know if there is a better way to avoid the entire vanilla function running in addition to PBR, but I couldn't think of one where PBR would work with seasons.

Tested with a PBR landscape retexture, seasonal swaps work fine now including special features like glint on the swapped parts.

Other Attempted Fixes

  • Reading the vanilla material directly after it is created to get the swap info. This is problematic because we only have texture names and not actual TextureSet forms so it would be impossible to match with required PBR jsons.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced seasonal texture swapping for landscape and terrain materials, enhancing visual variety based on seasons.
  • Refactor
    • Optimized material setup order to ensure consistent texture application without altering user experience.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2025

"""

Walkthrough

The control flow in the TESObjectLAND_SetupMaterial::thunk function was adjusted so that the original function call occurs before the PBR material setup check. The result of this call is now stored and used to determine subsequent logic. A new utility function Util::GetSeasonalSwap was introduced and applied to texture set references in terrain and PBR material setup functions to enable seasonal texture swapping. No public interface changes were made besides the addition of the new helper function declaration.

Changes

File(s) Change Summary
src/Hooks.cpp Moved the original function call before the PBR material setup check and stored its result for later use.
src/Features/TerrainHelper.cpp Wrapped all assigned texture sets with Util::GetSeasonalSwap() to apply seasonal texture swapping.
src/TruePBR.cpp Replaced direct texture set usage with Util::GetSeasonalSwap() for PBR texture detection and setup.
src/Utils/Game.cpp Added Util::GetSeasonalSwap() function to return a seasonal swapped texture set based on form ID.
src/Utils/Game.h Declared the new Util::GetSeasonalSwap() helper function for seasonal texture swapping.

Poem

A hop before the shimmer, a leap before the light,
The function calls a little sooner, making timing right.
With logic gently shifted, the flow now feels more neat—
A bunny’s careful planning keeps code and land complete!
🐇✨

Suggested reviewers

  • alandtse

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e05b2a and 45974f8.

📒 Files selected for processing (1)
  • src/Utils/Game.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Utils/Game.h
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hakasapl hakasapl changed the title refactor: moved vanilla terrain function call above PBR fix: moved vanilla terrain function call above PBR May 27, 2025
Copy link
Copy Markdown
Collaborator

@alandtse alandtse left a comment

Choose a reason for hiding this comment

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

Please confirm with test builds.

@hakasapl hakasapl marked this pull request as draft May 27, 2025 22:22
@alandtse
Copy link
Copy Markdown
Collaborator

There's also the test that nothing breaks with the changes. You don't need seasons for that.

@hakasapl hakasapl changed the title fix: moved vanilla terrain function call above PBR fix: implement support for seasons swapps in PBR and TerrainHelper Jun 3, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/TruePBR.cpp (1)

1062-1070: ⚠️ Potential issue

Seasonal swap is fetched but then ignored for PBR detection
textureSetData is still queried with the original landTexture.textureSet, meaning PBR configs are silently missed when a seasonal swap is active.

-    auto* textureSetData = truePBR->GetPBRTextureSetData(landTexture.textureSet);
+    auto* textureSetData = truePBR->GetPBRTextureSetData(textureSet);

Without this fix, swapped landscapes render with non-PBR materials even when a PBR JSON exists for the swapped set.

🧹 Nitpick comments (2)
src/Utils/Game.h (1)

81-85: Add minimal contract & const-correctness to the new helper
The helper neither mutates nor takes ownership of the texture set, yet the signature accepts/returns a mutable raw pointer. Consider tightening the contract:

-RE::BGSTextureSet* GetSeasonalSwap(RE::BGSTextureSet* textureSet);
+[[nodiscard]]
+const RE::BGSTextureSet* GetSeasonalSwap(const RE::BGSTextureSet* textureSet);

Benefits: documents intent, enables the compiler to catch accidental writes, and nudges callers to respect the returned pointer’s lifetime.

src/TruePBR.cpp (1)

1098-1116: Minor: avoid redundant seasonal-swap calls inside hot loop
Util::GetSeasonalSwap is called twice per texture in the quad loops. Cache the result once per pointer to reduce call overhead and make intent clearer:

auto* txst = land->loadedData->defQuadTextures[quadIndex]->textureSet;
if (singleton->IsPBRTextureSet(Util::GetSeasonalSwap(txst))) { … }

auto* txst = Util::GetSeasonalSwap(land->loadedData->defQuadTextures[quadIndex]->textureSet);
if (singleton->IsPBRTextureSet(txst)) { … }

Same applies to quadTextures[quadIndex][textureIndex].

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7ceb77 and 0b59647.

📒 Files selected for processing (5)
  • src/Features/TerrainHelper.cpp (2 hunks)
  • src/Hooks.cpp (1 hunks)
  • src/TruePBR.cpp (3 hunks)
  • src/Utils/Game.cpp (1 hunks)
  • src/Utils/Game.h (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/Features/TerrainHelper.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Hooks.cpp

Comment thread src/Utils/Game.cpp
@alandtse
Copy link
Copy Markdown
Collaborator

@hakasapl the bot had some interesting thoughts on code outside your changes that seem related to some of the swapping issues you mentioned. You should take a look and see if it makes sense.

hakasapl added 2 commits June 10, 2025 23:01
added nodiscard to GetSeasonalSwap
fixed PBR meta not being used in SetupLandscapeTexture
@hakasapl
Copy link
Copy Markdown
Contributor Author

@alandtse do you know why this would crash on startup (just after bethesda logo)? I tried debugging but I guess the crash happens outside CS because the debugger doesn't catch anything. It only crashes now that it is up to date with dev, it was not crashing before so I tried looking at some of those commits but I can't seem to pin down what would cause it.

@alandtse
Copy link
Copy Markdown
Collaborator

Git bisect. Are you sure it's not happening in regular dev?

@hakasapl hakasapl marked this pull request as ready for review June 16, 2025 05:03
@hakasapl
Copy link
Copy Markdown
Contributor Author

hakasapl commented Jun 16, 2025

@alandtse this should be ready now, users report test build working

I've also pushed this code to the ENB version of terrain helper and I have no complaints from nexus users there thus far

@hakasapl hakasapl requested a review from alandtse June 16, 2025 05:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 16, 2025

✅ A pre-release build is available for this PR:
Download

@alandtse alandtse changed the title fix: implement support for seasons swapps in PBR and TerrainHelper fix: support seasons swaps in PBR and TerrainHelper Jun 17, 2025
Copy link
Copy Markdown
Collaborator

@alandtse alandtse left a comment

Choose a reason for hiding this comment

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

Very close.

Comment thread src/Utils/Game.cpp
Comment thread src/Utils/Game.h Outdated
hakasapl and others added 2 commits June 17, 2025 02:26
Automated formatting by clang-format, prettier, and other hooks.
See https://pre-commit.ci for details.
@alandtse alandtse merged commit b33edcb into community-shaders:dev Jun 17, 2025
10 checks passed
alandtse pushed a commit that referenced this pull request Jun 20, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
davo0411 pushed a commit to davo0411/skyrim-community-shaders that referenced this pull request Jun 21, 2025
…s#1099)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@hakasapl
Copy link
Copy Markdown
Contributor Author

Closes #891

alandtse pushed a commit to alandtse/open-shaders that referenced this pull request Jul 20, 2025
…s#1099)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@hakasapl hakasapl deleted the pbr-seasons-fix branch April 1, 2026 18:46
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.

2 participants