Skip to content

fix(linear lighting): Fix projected diffuse with linear lighting#1710

Merged
doodlum merged 1 commit into
community-shaders:devfrom
Dlizzio:fix(LL)-projected-diffuse-fix-for-linear-lighting
Jan 15, 2026
Merged

fix(linear lighting): Fix projected diffuse with linear lighting#1710
doodlum merged 1 commit into
community-shaders:devfrom
Dlizzio:fix(LL)-projected-diffuse-fix-for-linear-lighting

Conversation

@Dlizzio
Copy link
Copy Markdown
Contributor

@Dlizzio Dlizzio commented Jan 13, 2026

Fixes PBR single pass projected diffuse and non PBR single pass projected diffuse linear lighting conversion.

Summary by CodeRabbit

  • Graphics & Rendering
    • Improved diffuse lighting calculations and color accuracy for surfaces with projected textures
    • Enhanced environment map influence on material appearance and reflections
    • Optimized level-of-detail blending transitions with refined color-space handling for smoother visual consistency across varying distances

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes PBR single pass projected diffuse and non PBR single pass projected diffuse linear lighting conversion.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 13, 2026

📝 Walkthrough

Walkthrough

This PR modifies projection-based diffuse color computation in the lighting shader, adjusting color-space linearization for projected UV contributions and envmap influence. It introduces a new LOD blending fallback path and changes base color assignment when projecting UVs.

Changes

Cohort / File(s) Summary
Lighting Shader Color Processing
package/Shaders/Lighting.hlsl
Modified projBaseColor computation to multiply diffuse by Color::ColorToLinear(ProjectedUVParams2.xyz) instead of previous approach; adjusted EnvmapData application to skip ColorToLinear linearization; introduced new LOD blending fallback path with Color::VanillaDiffuseColorMult() multiplication; changed baseColor.xyz assignment to use Color::Diffuse() instead of Color::ColorToLinear(); reformatted conditional blocks with explicit endif markers for LOD_BLENDING and LODOBJECTSHD scope delineation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #1558: Modifies color-space handling for vanilla/PBR diffuse in the same lighting shader, adjusting diffuse linearization in PBR paths.
  • #1410: Makes changes to PS_OUTPUT main in the same shader file, affecting different color computation paths and non-PBR branch handling.

Suggested reviewers

  • jiayev
  • doodlum

Poem

🐰✨ Colors shift and blend with care,
Linear spaces now are fair,
LOD paths rejoin the flow,
Envmaps reap what diffuse sows! 🎨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: addressing projected diffuse color-space handling in linear lighting paths, which is the core change across color computation, base color assignment, and LOD blending.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8aa7a2 and 8dcb920.

📒 Files selected for processing (1)
  • package/Shaders/Lighting.hlsl
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{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
**/*

⚙️ CodeRabbit configuration file

**/*: When reviewing PRs, please provide suggestions for:

  1. Conventional Commit Titles (if not following https://www.conventionalcommits.org/ or
    if the existing title does not describe the code changes):
    Format: type(scope): description
    Length: 50 characters limit for title, 72 for body
    Style: lowercase description, no ending period
    Examples:

    • feat(vr): add cross-eye sampling
    • fix(water): resolve flowmap bug
    • docs: update shader documentation
  2. Issue References (if PR fixes bugs or implements features):
    Suggest adding appropriate GitHub keywords:

Otherwise, use your standard review approach focusing on code quality.

Files:

  • package/Shaders/Lighting.hlsl
🧠 Learnings (10)
📓 Common learnings
Learnt from: jiayev
Repo: doodlum/skyrim-community-shaders PR: 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.
Learnt from: alandtse
Repo: doodlum/skyrim-community-shaders PR: 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.
📚 Learning: 2025-08-03T18:37:19.690Z
Learnt from: jiayev
Repo: doodlum/skyrim-community-shaders PR: 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
📚 Learning: 2025-06-17T05:40:22.785Z
Learnt from: alandtse
Repo: doodlum/skyrim-community-shaders 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.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: 2025-08-17T18:37:35.839Z
Learnt from: CR
Repo: doodlum/skyrim-community-shaders PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T18:37:35.839Z
Learning: Applies to features/*/Shaders/**/*.{hlsl,hlsli,fx,fxh} : Avoid GPU register/buffer conflicts in HLSL; verify register usage (e.g., with hlslkit buffer scanning)

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: 2025-07-01T18:01:07.079Z
Learnt from: alandtse
Repo: doodlum/skyrim-community-shaders PR: 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: 2025-06-08T11:25:14.536Z
Learnt from: alandtse
Repo: doodlum/skyrim-community-shaders PR: 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: 2025-08-05T17:40:44.828Z
Learnt from: ThePagi
Repo: doodlum/skyrim-community-shaders PR: 1369
File: package/Shaders/Lighting.hlsl:0-0
Timestamp: 2025-08-05T17:40:44.828Z
Learning: In the skyrim-community-shaders repository, ultra trees (object LOD trees) are detected using a compound shader define condition `defined(DO_ALPHA_TEST) && defined(LOD_BLENDING) && defined(RIM_LIGHTING) && defined(SOFT_LIGHTING)` because "they have no define" according to the comment. The `ExtraFlags::IsTree` flag is used for different tree handling (AO removal in skylighting) and may not apply to ultra trees specifically. Before replacing the compound condition with `IsTree`, verification is needed to ensure the flag covers ultra trees.

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: 2025-06-08T11:25:14.536Z
Learnt from: alandtse
Repo: doodlum/skyrim-community-shaders PR: 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: 2025-08-17T18:37:35.839Z
Learnt from: CR
Repo: doodlum/skyrim-community-shaders PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-17T18:37:35.839Z
Learning: Applies to features/*/Shaders/**/*.{hlsl,hlsli,fx,fxh} : Place all feature shaders under features/YourFeature/Shaders/

Applied to files:

  • package/Shaders/Lighting.hlsl
📚 Learning: 2025-07-05T05:20:45.823Z
Learnt from: alandtse
Repo: doodlum/skyrim-community-shaders PR: 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
⏰ 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). (4)
  • GitHub Check: Validate shader compilation (VR, .github/configs/shader-validation-vr.yaml)
  • GitHub Check: Run Shader Unit Tests
  • GitHub Check: Build plugin and addons
  • GitHub Check: Validate shader compilation (Flatrim, .github/configs/shader-validation.yaml)
🔇 Additional comments (3)
package/Shaders/Lighting.hlsl (3)

2012-2012: Correct linearization of both operands for projected diffuse.

Both the sampled diffuse texture and ProjectedUVParams2.xyz are now properly linearized before multiplication, ensuring consistent color space handling for the projected UV contribution in linear lighting mode.


2015-2028: Clean separation of PBR and non-PBR projected diffuse paths.

The restructuring correctly:

  1. Applies EnvmapData.xyz directly in TRUE_PBR (since projBaseColor is already linear)
  2. Adds the missing VanillaDiffuseColorMult() for the non-PBR path
  3. Separates LOD_BLENDING gamma/brightness adjustment to apply independently of the PBR flag

The preprocessor structure is well-organized.


2037-2037: Correct use of Color::Diffuse for conditional linear lighting.

Using Color::Diffuse() is the appropriate abstraction here as it handles the gamma-to-linear conversion conditionally based on whether linear lighting is enabled, consistent with the pattern used elsewhere in this shader (e.g., lines 1779, 1786).


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

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

@github-actions
Copy link
Copy Markdown

Using provided base ref: f8aa7a2
Using base ref: f8aa7a2
Base commit date: 2026-01-13T15:11:17Z (Tuesday, January 13, 2026 03:11 PM)
No actionable suggestions for changed features.

@github-actions
Copy link
Copy Markdown

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

@doodlum doodlum merged commit fb5d0dd into community-shaders:dev Jan 15, 2026
16 checks passed
@Dlizzio Dlizzio deleted the fix(LL)-projected-diffuse-fix-for-linear-lighting branch March 27, 2026 14:05
@coderabbitai coderabbitai Bot mentioned this pull request Apr 12, 2026
6 tasks
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