Skip to content

fix: terrain variation height blend fix#1320

Merged
alandtse merged 1 commit into
community-shaders:devfrom
davo0411:tv-fix
Jul 28, 2025
Merged

fix: terrain variation height blend fix#1320
alandtse merged 1 commit into
community-shaders:devfrom
davo0411:tv-fix

Conversation

@davo0411
Copy link
Copy Markdown
Collaborator

@davo0411 davo0411 commented Jul 28, 2025

last commit broke height blend operator on PBR landscapes. This restores the backup luminence blend calculations.

Summary by CodeRabbit

  • Improvements
    • Enhanced terrain texture blending for more natural transitions by implementing full height-based blending with improved contrast and influence controls.
    • Terrain visuals now benefit from smoother and more detailed texture transitions, especially in areas with varied elevation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 28, 2025

Walkthrough

The blending logic in the StochasticEffect function within TerrainVariation.hlsli was reworked to implement a comprehensive height-based blending approach for terrain textures. This includes new contrast adjustment for blend weights, a unified luminance/alpha-based height calculation, and removal of mip-level-dependent conditional branches.

Changes

Cohort / File(s) Change Summary
Terrain Variation Shader Logic
features/Terrain Variation/Shaders/TerrainVariation/TerrainVariation.hlsli
Refactored StochasticEffect to use full height-based blending, contrast-adjusted weights, unified luminance/alpha height calculation, and simplified normalization logic. Removed mip-level-based conditional branches.

Sequence Diagram(s)

sequenceDiagram
    participant CPU
    participant GPU
    participant StochasticEffect

    CPU->>GPU: Dispatch terrain rendering
    GPU->>StochasticEffect: Call with texture samples, weights, mip level
    StochasticEffect->>StochasticEffect: Compute luminance/alpha-based heights
    StochasticEffect->>StochasticEffect: Adjust blend weights with contrast
    StochasticEffect->>StochasticEffect: Apply height influence to weights
    StochasticEffect->>StochasticEffect: Normalize weights
    StochasticEffect->>GPU: Output blended terrain color
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • doodlum

Poem

A rabbit hopped through code so bright,
Blending heights with newfound might.
Contrast sharpened, colors fused,
Luminance and alpha, wisely used.
No more branches—logic clean!
The terrain now blends serene.
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f18aee and 4034729.

📒 Files selected for processing (1)
  • features/Terrain Variation/Shaders/TerrainVariation/TerrainVariation.hlsli (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-06-24T07:17:36.604Z
Learning: When reviewing PRs, always clarify the scope if there are multiple related features or dependencies. WeatherPicker was a separate PR that was already merged, while this PR focuses specifically on WetnessEffects climate preset system enhancements.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-05T05:20:45.823Z
Learning: In the skyrim-community-shaders repository, file deletion error handling improvements that replace existence checks and try-catch blocks with std::filesystem::remove error-code-based approaches are considered bug fixes rather than refactoring, as they address inadequate error handling and misleading log messages.
Learnt from: jiayev
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-18T15:21:03.641Z
Learning: In the skyrim-community-shaders rendering pipeline, materials with alpha < 1 or alpha blending enabled are rendered in non-deferred mode rather than deferred mode. This means issues with dynamic cubemaps on transparent materials are actually non-deferred rendering issues.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: features/Wetness Effects/Shaders/WetnessEffects/WetnessEffects.hlsli:57-61
Timestamp: 2025-06-17T05:40:22.785Z
Learning: Default parameter values are supported in the HLSL compiler used by the skyrim-community-shaders project, contrary to standard HLSL (FXC/DXC) limitations.
features/Terrain Variation/Shaders/TerrainVariation/TerrainVariation.hlsli (1)

Learnt from: alandtse
PR: #577
File: features/Wetness Effects/Shaders/WetnessEffects/WetnessEffects.hlsli:57-61
Timestamp: 2025-06-17T05:40:22.785Z
Learning: Default parameter values are supported in the HLSL compiler used by the skyrim-community-shaders project, contrary to standard HLSL (FXC/DXC) limitations.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Validate shader compilation (VR, .github/configs/shader-validation-vr.yaml)
  • GitHub Check: Validate shader compilation (Flatrim, .github/configs/shader-validation.yaml)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (1)
features/Terrain Variation/Shaders/TerrainVariation/TerrainVariation.hlsli (1)

151-170: LGTM! Solid implementation of height-based terrain blending.

This implementation correctly restores the luminance-based height calculations as mentioned in the PR objectives. The approach cleverly combines luminance-derived heights from RGB channels with alpha channel data when available, using a proper mask-based selection. The mathematical formulation is sound:

  • Contrast adjustment using pow(saturate(offsets.weights), contrastFactor)
  • Proper sRGB luminance weights (0.2126, 0.7152, 0.0722)
  • Smart alpha/luminance blending with step(0.001, alphaValues) mask
  • Correct final weight normalization and height influence integration

The fix addresses the broken height blend operator on PBR landscapes mentioned in the PR description.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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.

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.

@github-actions
Copy link
Copy Markdown

Using provided base ref: 6f18aee
Using base ref: 6f18aee
Base commit date: 2025-07-27T15:38:04+01:00 (Sunday, July 27, 2025 03:38 PM)
No actionable suggestions for changed features.

@github-actions
Copy link
Copy Markdown

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

@alandtse alandtse merged commit 54ddd11 into community-shaders:dev Jul 28, 2025
15 checks passed
@davo0411 davo0411 deleted the tv-fix branch July 28, 2025 14:53
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