Skip to content

fix(truepbr): apply MATO rbg scalars through cbuffer#2310

Merged
alandtse merged 1 commit into
community-shaders:devfrom
soda3000:dev-2026-05-10
May 11, 2026
Merged

fix(truepbr): apply MATO rbg scalars through cbuffer#2310
alandtse merged 1 commit into
community-shaders:devfrom
soda3000:dev-2026-05-10

Conversation

@soda3000
Copy link
Copy Markdown
Contributor

@soda3000 soda3000 commented May 10, 2026

Previously, MATO RGB slider values from the TruePBR section of the menu were being passed to Lighting.hlsl via the PS constant EnvmapData, which meant only R was valid, and G and B were either corrupting the intended use for those slots, or were lost entirely.
This change creates a new dedicated PS constant specifically for the RGB slider scalars, which then is multiplied with the projected material color in the Lighting shader.

Summary by CodeRabbit

  • Refactor
    • Updated material color scaling handling in physically-based rendering shader processing.
    • Enhanced material parameter management for RGB color scale application in projected UV material workflows.
    • Restructured shader constant indexing to support the new material scaling parameter across rendering pipeline.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

📝 Walkthrough

Walkthrough

This PR adds a new shader constant MaterialObjectRGBScale to the lighting pipeline. The float3 constant is declared in the shader constant header, registered in the name-to-index mapping table, defined in the HLSL cbuffer, and applied to scale the projected base color in TRUE_PBR mode before being bound at runtime from the material setup code.

Changes

MaterialObjectRGBScale Shader Constant

Layer / File(s) Summary
Shader Constant Definition
src/ShaderCache.h
ShaderConstants::LightingPS declares MaterialObjectRGBScale as const int32_t (index 50) and registers it in GetVR() (value 58).
Constant Table Mapping
src/ShaderCache.cpp
"MaterialObjectRGBScale" string is added to the lightingPS constant variable lookup table.
Shader Definition and Usage
package/Shaders/Lighting.hlsl
Float3 member MaterialObjectRGBScale is added to PerMaterial cbuffer (packoffset c17) and applied to scale projBaseColor in TRUE_PBR projected-UV path.
Runtime Binding
src/TruePBR.cpp
Projected-UV constant upload is redirected from lightingPSConstants.EnvmapData to lightingPSConstants.MaterialObjectRGBScale.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • alandtse
  • doodlum

Poem

🐰 A scale for RGB, so fine and bright,
Through buffers and shaders in pixel light,
From constant to cbuffer, the journey flows,
Material colors in TRUE_PBR it shows! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main fix: applying MATO RGB scalars through a dedicated cbuffer parameter, which is the core change across all four modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.20.0)

OpenGrep fatal error (exit code 2): [00.14][ERROR]: Error: exception Unix_error: No such file or directory stat src/ShaderCache.cpp
Raised by primitive operation at UTmp.replace_named_pipe_by_regular_file_if_needed in file "libs/commons/UTmp.ml", line 145, characters 8-27
Called from Scan_CLI.replace_target_roots_by_regular_files_where_needed.(fun) in file "src/osemgrep/cli_scan/Scan_CLI.ml", lines 1086-1087, characters 19-65
Called from List_.fast_map in file "libs/commons/List_.ml", line 81, characters 17-20
Called from Scan_CLI

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

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

935-940: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Initialize PBRProjectedUVParams1 and PBRProjectedUVParams2 to avoid uninitialized values in constant buffers

Lines 935-940: PBRProjectedUVParams1 is declared as a 4-element array but only indices 0–2 are filled. The 4th element remains uninitialized garbage and gets uploaded to the cbuffer.

Additionally, PBRProjectedUVParams2 (lines 941–944) has the same issue: only indices 0–1 are filled, leaving indices 2–3 uninitialized.

Since GetProjectedMaterialBaseColorScale() returns only 3 floats and the other projected parameters are scalars, use 3-element and 2-element arrays respectively with {} initialization, or initialize the unused indices explicitly.

Suggested fix
-				std::array<float, 4> PBRProjectedUVParams1;
+				std::array<float, 3> PBRProjectedUVParams1{};
 				PBRProjectedUVParams1[0] = pbrMaterial->GetProjectedMaterialBaseColorScale()[0];
 				PBRProjectedUVParams1[1] = pbrMaterial->GetProjectedMaterialBaseColorScale()[1];
 				PBRProjectedUVParams1[2] = pbrMaterial->GetProjectedMaterialBaseColorScale()[2];
 				shadowState->SetPSConstant(PBRProjectedUVParams1, RE::BSGraphics::ConstantGroupLevel::PerMaterial, lightingPSConstants.MaterialObjectRGBScale);

-				std::array<float, 4> PBRProjectedUVParams2;
+				std::array<float, 2> PBRProjectedUVParams2{};
 				PBRProjectedUVParams2[0] = pbrMaterial->GetProjectedMaterialRoughness();
 				PBRProjectedUVParams2[1] = pbrMaterial->GetProjectedMaterialSpecularLevel();
 				shadowState->SetPSConstant(PBRProjectedUVParams2, RE::BSGraphics::ConstantGroupLevel::PerMaterial, lightingPSConstants.ParallaxOccData);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/TruePBR.cpp` around lines 935 - 940, PBRProjectedUVParams1 and
PBRProjectedUVParams2 are partially filled and leave elements uninitialized
before calling shadowState->SetPSConstant; fix by fully initializing the arrays
(e.g., use brace/init-zero or explicitly set the unused indices) so all 4
elements passed to SetPSConstant are deterministic; locate the declarations
PBRProjectedUVParams1 and PBRProjectedUVParams2 near the
GetProjectedMaterialBaseColorScale() calls and ensure index 3 (and indices 2–3
for PBRProjectedUVParams2) are set to 0.0f (or change the array size to match
the actual data if SetPSConstant supports smaller sizes) before invoking
shadowState->SetPSConstant with lightingPSConstants.MaterialObjectRGBScale and
the other constant slots.
🧹 Nitpick comments (1)
src/TruePBR.cpp (1)

1-1: PR metadata polish suggestion

Consider renaming the title to fix the typo (rbgrgb), e.g. fix(truepbr): apply mato rgb scalars via dedicated cbuffer.
If this resolves a tracked bug, add an issue keyword like Fixes #<id> / Closes #<id>.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/TruePBR.cpp` at line 1, Update the PR title to correct the typo "rbg" →
"rgb" (e.g., use "fix(truepbr): apply mato rgb scalars via dedicated cbuffer")
and, if this change closes a tracked bug, append the appropriate issue keyword
like "Fixes #<id>" or "Closes #<id>" to the title or PR description so GitHub
links the issue automatically; ensure the component name "truepbr" and wording
"mato rgb scalars" remain accurate in the revised title.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/TruePBR.cpp`:
- Around line 935-940: PBRProjectedUVParams1 and PBRProjectedUVParams2 are
partially filled and leave elements uninitialized before calling
shadowState->SetPSConstant; fix by fully initializing the arrays (e.g., use
brace/init-zero or explicitly set the unused indices) so all 4 elements passed
to SetPSConstant are deterministic; locate the declarations
PBRProjectedUVParams1 and PBRProjectedUVParams2 near the
GetProjectedMaterialBaseColorScale() calls and ensure index 3 (and indices 2–3
for PBRProjectedUVParams2) are set to 0.0f (or change the array size to match
the actual data if SetPSConstant supports smaller sizes) before invoking
shadowState->SetPSConstant with lightingPSConstants.MaterialObjectRGBScale and
the other constant slots.

---

Nitpick comments:
In `@src/TruePBR.cpp`:
- Line 1: Update the PR title to correct the typo "rbg" → "rgb" (e.g., use
"fix(truepbr): apply mato rgb scalars via dedicated cbuffer") and, if this
change closes a tracked bug, append the appropriate issue keyword like "Fixes
#<id>" or "Closes #<id>" to the title or PR description so GitHub links the
issue automatically; ensure the component name "truepbr" and wording "mato rgb
scalars" remain accurate in the revised title.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f42a64b8-560e-4db0-af03-4da3b2544074

📥 Commits

Reviewing files that changed from the base of the PR and between 52c493e and 2233e53.

📒 Files selected for processing (4)
  • package/Shaders/Lighting.hlsl
  • src/ShaderCache.cpp
  • src/ShaderCache.h
  • src/TruePBR.cpp

@github-actions
Copy link
Copy Markdown

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

@alandtse alandtse changed the title fix(truepbr): apply MATO rbg scalars via unique cbuffer param fix(truepbr): apply MATO rbg scalars through cbuffer May 11, 2026
@alandtse alandtse merged commit d026838 into community-shaders:dev May 11, 2026
13 checks passed
alandtse pushed a commit that referenced this pull request May 11, 2026
SkrubbySkrubInAShrub pushed a commit that referenced this pull request May 14, 2026
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 15, 2026
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 16, 2026
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