Skip to content

fix(linear lighting): fix horizon seam#1718

Closed
Dlizzio wants to merge 6 commits into
community-shaders:devfrom
Dlizzio:fix(LL)-clear-render-conversion
Closed

fix(linear lighting): fix horizon seam#1718
Dlizzio wants to merge 6 commits into
community-shaders:devfrom
Dlizzio:fix(LL)-clear-render-conversion

Conversation

@Dlizzio
Copy link
Copy Markdown
Contributor

@Dlizzio Dlizzio commented Jan 15, 2026

Pushes the clear render (horizon seam) through linear conversion. Added slider for clear render with default set at 1.62.

Summary by CodeRabbit

  • New Features

    • Added "Clear Render Gamma" setting with a default of 1.62 and an adjustable slider in the settings UI to control gamma correction of the renderer background when linear lighting is enabled.
  • Bug Fixes

    • Prevents repeated or incorrect gamma conversions of the background color to keep rendered clear color stable and accurate.

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

Pushes the clear render (horizon seam) through linear conversion.
Added slider for clear render with default set at 1.62
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds a configurable clear-render gamma and applies gamma-correction to the renderer clear color during prepass/reflections when linear lighting is enabled; exposes the setting in UI and caches converted values to avoid repeated conversions.

Changes

Cohort / File(s) Summary
LinearLighting Feature - Header
src/Features/LinearLighting.h
Added float clearRenderGamma (default 1.62f) to LinearLighting::Settings; added lastConvertedClearColor[3], lastOriginalClearColor[3], and lastConvertedClearGamma fields; declared EarlyPrepass(), ReflectionsPrepass(), and ConvertClearColor()
LinearLighting Feature - Implementation
src/Features/LinearLighting.cpp
Included clearRenderGamma in JSON serialization; added UI slider for Clear Render Gamma; implemented EarlyPrepass() and ReflectionsPrepass() hooks that call ConvertClearColor(); implemented ConvertClearColor() to gamma-correct renderer clear color (RGB only) and cache conversions to avoid repeated application

Sequence Diagram(s)

mermaid
sequenceDiagram
participant UI as UI
participant LL as LinearLighting
participant Renderer as RendererData
participant Prepass as PrepassSystem

UI->>LL: user adjusts clearRenderGamma
Prepass->>LL: EarlyPrepass() / ReflectionsPrepass() called
LL->>LL: ConvertClearColor() checks settings & lastConvertedClearColor
alt needs conversion
    LL->>Renderer: read renderer.clearColor (RGBA)
    LL->>LL: gamma-correct RGB using clearRenderGamma
    LL->>Renderer: write converted clearColor (RGB only)
    LL->>LL: update lastOriginalClearColor / lastConvertedClearColor / lastConvertedClearGamma
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jiayev
  • doodlum
  • alandtse

Poem

🐰 In sliders and prepass I hop and hide,
Gamma whispers secrets I gently apply,
Clear skies shift from gamma to line,
Colors align, the renderings shine,
I nibble code and watch pixels glide.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: fixing the horizon seam in linear lighting by converting the clear render color through gamma correction.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

Automated formatting by clang-format, prettier, and other hooks.
See https://pre-commit.ci for details.
@github-actions
Copy link
Copy Markdown

Using provided base ref: 7ee4c02
Using base ref: 7ee4c02
Base commit date: 2026-01-15T15:11:03Z (Thursday, January 15, 2026 03:11 PM)
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: 1

🤖 Fix all issues with AI agents
In `@src/Globals.cpp`:
- Around line 267-278: The thunk function may dereference a null
pRenderTargetView and crash; add a null check at the start of thunk (before
calling pRenderTargetView->GetResource) to return early if pRenderTargetView is
nullptr. Locate the static void thunk(ID3D11DeviceContext* This,
ID3D11RenderTargetView* pRenderTargetView, const FLOAT ColorRGBA[4]) and ensure
it guards pRenderTargetView (and optionally rtvResource usage) so GetResource is
only called when pRenderTargetView is valid.
🧹 Nitpick comments (1)
src/Features/LinearLighting.cpp (1)

52-52: Consider adding a tooltip to explain this setting.

The "Clear Render Gamma" label may not be immediately clear to users. A tooltip explaining that this affects the background color visible at worldspace edges and in water reflections would improve discoverability.

💡 Optional: Add tooltip
 	ImGui::SliderFloat("Clear Render Gamma", &settings.clearRenderGamma, 0.1f, 3.0f, "%.2f");
+	if (ImGui::IsItemHovered())
+		ImGui::SetTooltip("Gamma correction for the clear color visible at worldspace edges and in water reflections.");
📜 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 7ee4c02 and d60a74f.

📒 Files selected for processing (3)
  • src/Features/LinearLighting.cpp
  • src/Features/LinearLighting.h
  • src/Globals.cpp
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{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:

  • src/Features/LinearLighting.h
  • src/Features/LinearLighting.cpp
  • src/Globals.cpp
src/**/*.{cpp,cxx,cc,h,hpp,hxx}

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

src/**/*.{cpp,cxx,cc,h,hpp,hxx}: Ensure SE/AE/VR runtime compatibility; use runtime detection patterns (e.g., REL::RelocateMember())
Include robust error handling and resource management with graceful degradation in the plugin code

Files:

  • src/Features/LinearLighting.h
  • src/Features/LinearLighting.cpp
  • src/Globals.cpp
**/*

⚙️ 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:

    • "Fixes #123" or "Closes #123" for bug fixes
    • "Implements #123" or "Addresses #123" for features
    • "Related to #123" for partial implementations

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

Files:

  • src/Features/LinearLighting.h
  • src/Features/LinearLighting.cpp
  • src/Globals.cpp
🧠 Learnings (3)
📓 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.
Learnt from: ThePagi
Repo: doodlum/skyrim-community-shaders PR: 1369
File: src/Features/SnowCover.cpp:260-260
Timestamp: 2025-08-05T18:13:03.123Z
Learning: In the skyrim-community-shaders SnowCover feature, the time calculation uses division by 61.0 instead of 60.0 for seconds conversion in the perFrame.Month calculation. The original author ThePagi indicated this was intentional and makes no discernible difference to the snow cover functionality, suggesting it may be related to game-specific timing mechanics or balance considerations.
📚 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:

  • src/Features/LinearLighting.h
  • src/Features/LinearLighting.cpp
  • src/Globals.cpp
📚 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:

  • src/Features/LinearLighting.h
⏰ 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). (1)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (4)
src/Globals.cpp (2)

280-310: LGTM!

The resource comparison logic correctly identifies render targets by their underlying texture rather than RTV pointer. The gamma-to-linear conversion using std::pow is appropriate, and the COM resource reference is properly released. Good defensive coding with the null check on rtvResource before Release().


317-322: Hook registration is correct. The vtable indices 14 (Map), 15 (Unmap), and 50 (ClearRenderTargetView) are accurate per the D3D11 interface specification. The hooks are properly structured using REL::Relocation for runtime compatibility and installed alongside existing D3D device hooks.

src/Features/LinearLighting.h (1)

31-31: LGTM!

The new clearRenderGamma setting is appropriately placed in the Settings struct. The default value of 1.62f (as mentioned in the PR description) differs from other gamma values (1.8f) which appears intentional for the horizon seam correction. Correctly excluded from PerFrameData since it's only used CPU-side in the ClearRenderTargetView hook.

src/Features/LinearLighting.cpp (1)

7-7: LGTM!

The clearRenderGamma field is correctly added to the JSON serialization macro, enabling proper save/load of the setting.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment thread src/Globals.cpp Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 15, 2026

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

@doodlum doodlum changed the title fix(Linear Lighting): Clear render (horizon seam) conversion fix(linear lighting): fix horizon seam Jan 16, 2026
Copy link
Copy Markdown
Collaborator

@doodlum doodlum left a comment

Choose a reason for hiding this comment

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

Looks like nonsense. This should be fixed by converting weather colors on the CPU. Converting everything externally is a waste of performance and bloats code.

@Dlizzio
Copy link
Copy Markdown
Contributor Author

Dlizzio commented Jan 17, 2026

Clear render uses fog far color from weather but needs to be converted differently from fog.

@Dlizzio Dlizzio requested a review from doodlum January 17, 2026 12:51
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: 1

🤖 Fix all issues with AI agents
In `@src/Features/LinearLighting.cpp`:
- Around line 108-137: The current skip logic in
LinearLighting::ConvertClearColor only compares rendererData.clearColor to
lastConvertedClearColor so changes to settings.clearRenderGamma are ignored; fix
by caching the original (pre-conversion) clear color and the lastAppliedGamma,
detect when either the renderer's original clear color or
settings.clearRenderGamma has changed, and then recompute: if originalClearColor
is uninitialized capture the current rendererData.clearColor as
originalClearColor, if settings.clearRenderGamma != lastAppliedGamma or
rendererData.clearColor differs from lastConvertedClearColor restore from
originalClearColor then apply std::pow(originalClearColor[i],
settings.clearRenderGamma) into rendererData.clearColor[i], and update
lastConvertedClearColor and lastAppliedGamma accordingly; reference
LinearLighting::ConvertClearColor, settings.clearRenderGamma,
rendererData.clearColor, lastConvertedClearColor and introduce
originalClearColor and lastAppliedGamma fields.

Comment thread src/Features/LinearLighting.cpp
@doodlum
Copy link
Copy Markdown
Collaborator

doodlum commented Jan 17, 2026

This is nonsense. Not going to review PRs that are just using AI slop.

@doodlum doodlum closed this Jan 17, 2026
@Dlizzio Dlizzio deleted the fix(LL)-clear-render-conversion branch February 6, 2026 12:02
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