Skip to content

fix(pbr): clamp roughness at a bigger value#1351

Merged
alandtse merged 1 commit into
community-shaders:devfrom
jiayev:clamp-roughness-bigger
Aug 3, 2025
Merged

fix(pbr): clamp roughness at a bigger value#1351
alandtse merged 1 commit into
community-shaders:devfrom
jiayev:clamp-roughness-bigger

Conversation

@jiayev
Copy link
Copy Markdown
Collaborator

@jiayev jiayev commented Aug 2, 2025

clamp roughness at a bigger value. 0.005 is still too small for ggx to generate visible specular.

Summary by CodeRabbit

  • Refactor
    • Adjusted the minimum roughness value used in rendering calculations, which may affect the visual appearance of surfaces in scenes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 2, 2025

Walkthrough

The change updates the minimum clamping value for the roughness parameter in the physically based rendering (PBR) surface property initialization within a pixel shader. The lower bound for roughness is increased from 0.005 to 0.04, affecting the rendering calculations for material appearance. No other properties or function signatures are modified.

Changes

Cohort / File(s) Change Summary
Shader Roughness Clamp Update
package/Shaders/Lighting.hlsl
Adjusted the lower clamp bound for roughness from 0.005 to 0.04 in the PBR surface initialization.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Suggested reviewers

  • alandtse

Poem

A shader’s tweak, so small yet bright,
Roughness raised to new delight.
From 0.005 to 0.04 we hop,
Reflecting change with every drop.
In pixel lands where photons play,
A bunny cheers this shiny day!
🐇✨

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 7e0c32f and 4aaab40.

📒 Files selected for processing (1)
  • package/Shaders/Lighting.hlsl (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 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.
Learnt from: davo0411
PR: doodlum/skyrim-community-shaders#1070
File: src/State.cpp:79-83
Timestamp: 2025-05-30T11:44:15.542Z
Learning: In the Skyrim Community Shaders project, the `smoothDrawCalls` array in the `State` class is declared as type `double` in `src/State.h`, which is the correct floating-point type for performing exponential moving average smoothing calculations.
📚 Learning: default parameter values are supported in the hlsl compiler used by the skyrim-community-shaders pro...
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.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: in the skyrim-community-shaders project, simple scalar constants in hlsl shaders use #define (e.g., ...
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-01T18:01:07.079Z
Learning: In the skyrim-community-shaders project, simple scalar constants in HLSL shaders use #define (e.g., #define NTHREADS 128), while more complex constants use static const within namespaces (e.g., Math namespace in Math.hlsli). For epsilon standardization, #define is the appropriate choice since epsilon values are simple scalar constants.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: in the skyrim-community-shaders project, boolean flags in c++ structs that interface with hlsl shade...
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent 4-byte size, proper 16-byte alignment in constant buffers, and cross-platform compatibility when passing data between C++ and HLSL shaders.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: in the skyrim-community-shaders project, boolean flags in c++ structs that interface with hlsl shade...
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent size, alignment, and cross-platform compatibility when passing data to shader constant buffers.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: in the skyrim-community-shaders repository, file deletion error handling improvements that replace e...
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.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: in the skyrim community shaders project, the `smoothdrawcalls` array in the `state` class is declare...
Learnt from: davo0411
PR: doodlum/skyrim-community-shaders#1070
File: src/State.cpp:79-83
Timestamp: 2025-05-30T11:44:15.542Z
Learning: In the Skyrim Community Shaders project, the `smoothDrawCalls` array in the `State` class is declared as type `double` in `src/State.h`, which is the correct floating-point type for performing exponential moving average smoothing calculations.

Applied to files:

  • package/Shaders/Lighting.hlsl
⏰ 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)
package/Shaders/Lighting.hlsl (1)

2108-2108: LGTM! Valid fix for GGX specular highlight visibility.

This change correctly addresses the issue where the previous minimum roughness value of 0.005 was too small for the GGX microfacet model to generate visible specular highlights. The new minimum of 0.04 maintains smooth surface appearance while ensuring proper specular reflection calculations.

✨ 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.

@jiayev jiayev requested a review from Copilot August 2, 2025 18:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR increases the minimum roughness clamp value in the PBR shader from 0.005 to 0.04 to ensure that GGX specular highlights remain visible.

  • Increased minimum roughness value from 0.005 to 0.04 in the roughness clamping operation

pbrSurfaceProperties.Noise = screenNoise;

pbrSurfaceProperties.Roughness = clamp(rawRMAOS.x, 0.005, 1.0);
pbrSurfaceProperties.Roughness = clamp(rawRMAOS.x, 0.04, 1.0);
Copy link

Copilot AI Aug 2, 2025

Choose a reason for hiding this comment

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

The magic number 0.04 should be defined as a named constant to improve code maintainability and make the physical reasoning behind this value clearer.

Suggested change
pbrSurfaceProperties.Roughness = clamp(rawRMAOS.x, 0.04, 1.0);
pbrSurfaceProperties.Roughness = clamp(rawRMAOS.x, PBR_MIN_ROUGHNESS, 1.0);

Copilot uses AI. Check for mistakes.
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.

@coderabbitai let's make this an issue assigned to @jiayev for this constant.

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.

🧩 Analysis chain

@alandtse I'll create an issue for defining the magic number as a named constant and assign it to @jiayev.


🏁 Script executed:

#!/bin/bash
gh issue create \
  --title "Define PBR minimum roughness as named constant" \
  --body "## Description

The recent change in PR #1351 updated the minimum roughness clamp value from 0.005 to 0.04 for the GGX microfacet model to ensure visible specular highlights. However, this magic number should be defined as a named constant to improve code maintainability and make the physical reasoning behind this value clearer.

## Context

Currently in \`package/Shaders/Lighting.hlsl\` line 2108:
\`\`\`hlsl
pbrSurfaceProperties.Roughness = clamp(rawRMAOS.x, 0.04, 1.0);
\`\`\`

This magic number should be replaced with a descriptive named constant like \`PBR_MIN_ROUGHNESS\`.

## Benefits

- Improved code readability and maintainability
- Makes the physical reasoning behind the value more explicit
- Easier to adjust if needed in the future
- Follows best practices for avoiding magic numbers

## References

- PR: https://github.com/doodlum/skyrim-community-shaders/pull/1351
- Comment: https://github.com/doodlum/skyrim-community-shaders/pull/1351#discussion_r2249344753" \
  --assignee jiayev

Length of output: 1137


Perfect! I've successfully created issue #1353 "Define PBR minimum roughness as named constant" and assigned it to @jiayev. The issue includes:

  • A clear description of the need to replace the magic number 0.04 with a named constant
  • Context about the recent change in this PR
  • Benefits of making this improvement
  • References to both this PR and the comment discussion

The issue is now tracked at: #1353

This will help improve code maintainability by making the physical reasoning behind the minimum roughness value more explicit and following best practices for avoiding magic numbers in the codebase.

🐰✨


🧠 Learnings used
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.

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#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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 2, 2025

Using provided base ref: 7e0c32f
Using base ref: 7e0c32f
Base commit date: 2025-08-01T00:49:21-07:00 (Friday, August 01, 2025 12:49 AM)
No actionable suggestions for changed features.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Aug 2, 2025

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

Copy link
Copy Markdown
Contributor

@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.

Bot has a good point about magic numbers. Please define a constant in a good place. If I accept the bot suggestion I can't approve.

@alandtse alandtse merged commit 99d6e17 into community-shaders:dev Aug 3, 2025
15 checks passed
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.

3 participants