Skip to content

refactor(pbr): centralize constants#1437

Merged
alandtse merged 1 commit into
community-shaders:devfrom
soda3000:dev-28-08-2025_PBR
Aug 29, 2025
Merged

refactor(pbr): centralize constants#1437
alandtse merged 1 commit into
community-shaders:devfrom
soda3000:dev-28-08-2025_PBR

Conversation

@soda3000
Copy link
Copy Markdown
Contributor

@soda3000 soda3000 commented Aug 28, 2025

Relates to issue #1353

Summary by CodeRabbit

  • Refactor

    • Centralized tunable bounds for material roughness and glint parameters, replacing hard-coded limits with shared constants.
    • Standardized clamping ranges across lighting calculations for more consistent visuals.
  • Improvements

    • More predictable material appearance at parameter extremes (roughness and glint).
    • Enables easier global tuning of visual parameters without behavior changes for typical settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 28, 2025

Walkthrough

Introduces PBR::Constants in PBR.hlsli with eight float bounds for roughness and glint parameters. Updates Lighting.hlsl to replace hard-coded clamp literals with references to these constants. No control flow or external interfaces are changed.

Changes

Cohort / File(s) Summary
Shader constants centralization
package/Shaders/Common/PBR.hlsli
Added namespace PBR::Constants with float bounds: Min/MaxRoughness, Min/MaxGlintDensity, Min/MaxGlintRoughness, Min/MaxGlintDensityRandomization. Declarations only.
Clamp usage updates
package/Shaders/Lighting.hlsl
Replaced hard-coded clamp ranges for roughness and glint parameters with PBR::Constants::* equivalents; no logic or interface changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • doodlum
  • alandtse
  • Pentalimbed

Poem

A bunny hops through PBR’s glade,
Tidying bounds the shader made.
No magic numbers in the night—
Constants guide the glinting light.
With clamps aligned and neatly penned,
My whiskers twitch: review will end. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ 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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: d1a9f49
Using base ref: d1a9f49
Base commit date: 2025-08-28T11:57:10-07:00 (Thursday, August 28, 2025 11:57 AM)
No actionable suggestions for changed features.

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: 0

🧹 Nitpick comments (3)
package/Shaders/Common/PBR.hlsli (1)

50-60: Consider adding a constant for GlintScreenSpaceScale’s lower bound and use it at call sites.

You still have max(1, …) in Lighting.hlsl (Line 2113). Define a named constant to avoid reintroducing magic numbers downstream.

Apply this diff here:

 namespace Constants
 {
   static const float MinRoughness = 0.04f;
   static const float MaxRoughness = 1.0f;
+  // Prevents undersampling in screen-space glints
+  static const float MinGlintScreenSpaceScale = 1.0f;
   static const float MinGlintDensity = 1.0f;
   static const float MaxGlintDensity = 40.0f;
   static const float MinGlintRoughness = 0.005f;
   static const float MaxGlintRoughness = 0.3f;
   static const float MinGlintDensityRandomization = 0.0f;
   static const float MaxGlintDensityRandomization = 5.0f;
 }

And then use it in Lighting.hlsl (see my comment there).

package/Shaders/Lighting.hlsl (2)

2108-2117: Also replace max(1, glintParameters.x) with a named constant.

Keeps all glint-related thresholds in one place and prevents drift if defaults change.

Update Line 2113 as follows (requires adding MinGlintScreenSpaceScale in PBR::Constants as suggested in PBR.hlsli):

pbrSurfaceProperties.GlintScreenSpaceScale = max(PBR::Constants::MinGlintScreenSpaceScale, glintParameters.x);

2108-2117: Centralize magic-number clamp ranges
There are numerous literal clamp/min/max calls across shaders (e.g. Utility.hlsl:856, ISApplyVolumetricLighting.hlsl:47, Lighting.hlsl:2113). Consider moving common ranges (wetness, hair, coat, glint, etc.) into shared constants (e.g. PBR::Constants) for consistency.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d1a9f49 and b569c56.

📒 Files selected for processing (2)
  • package/Shaders/Common/PBR.hlsli (1 hunks)
  • package/Shaders/Lighting.hlsl (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,cxx,cc,c,h,hpp,hxx,hlsl,hlsli,fx,fxh,py}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Do not include TODO/FIXME placeholders; provide complete, working solutions

Files:

  • package/Shaders/Lighting.hlsl
  • package/Shaders/Common/PBR.hlsli
🧠 Learnings (1)
📚 Learning: 2025-08-03T18:37:19.690Z
Learnt from: jiayev
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-08-03T18:37:19.690Z
Learning: ISReflectionsRayTracing.hlsl and ISWorldMap.hlsl in the skyrim-community-shaders repository are image-space post-processing shaders that perform color sampling and blending operations that need proper linear color space handling for the linear lighting system. ISReflectionsRayTracing handles screen-space reflections and should use conditional Color::IrradianceToLinear/Gamma conversions similar to ISCompositeLensFlareVolumetricLighting.hlsl. ISWorldMap performs 7x7 color accumulation that should be done in linear space similar to the pattern used in ISSAOComposite.hlsl.

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 (2)
package/Shaders/Common/PBR.hlsli (1)

50-60: LGTM: Centralized PBR bounds improve readability and consistency.

Replacing magic numbers with PBR::Constants is a solid refactor with no behavior change.

package/Shaders/Lighting.hlsl (1)

2108-2117: LGTM: Magic-number clamps replaced with PBR::Constants.

Behavior preserved; improves maintainability and makes tuning easier.

@github-actions
Copy link
Copy Markdown

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

@alandtse alandtse changed the title refactor(shaders): replace some pbr magic numbers with named constants refactor(pbr): centralize constants Aug 29, 2025
@alandtse alandtse merged commit 5c8f17f into community-shaders:dev Aug 29, 2025
17 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