Skip to content

fix(VL): potential negative vl values#1423

Merged
Pentalimbed merged 1 commit into
community-shaders:devfrom
Pentalimbed:vl-neg-fix
Aug 21, 2025
Merged

fix(VL): potential negative vl values#1423
Pentalimbed merged 1 commit into
community-shaders:devfrom
Pentalimbed:vl-neg-fix

Conversation

@Pentalimbed
Copy link
Copy Markdown
Collaborator

@Pentalimbed Pentalimbed commented Aug 21, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Eliminated negative values in volumetric lighting, reducing unintended darkening, banding, and flicker in fog and light shafts.
    • Improved stability during temporal accumulation, delivering smoother frame-to-frame transitions with fewer artifacts.
    • Enhances visual consistency in low-light and high-noise scenes without impacting performance or requiring user settings changes.
    • Applies across both immediate and temporally smoothed rendering paths for more reliable lighting results.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 21, 2025

Walkthrough

Clamps volumetric lighting accumulation to non-negative values in ISApplyVolumetricLighting.hlsl by computing adjustedVl = max(0, noiseGrad + vl - 0.0078125). This affects both non-temporal and temporal VL assignment paths; overall control flow and interfaces remain unchanged.

Changes

Cohort / File(s) Summary
Volumetric lighting clamp update
package/Shaders/ISApplyVolumetricLighting.hlsl
Replace raw sum-minus-bias with clamped computation: adjustedVl = max(0, noiseGrad + vl - 0.0078125). Use adjustedVl in both non-temporal path (direct assign) and temporal path (lerp with previousVl). No other logic or interface changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit peers through shader night,
Taps bias down, keeps values bright.
No negatives in VL’s gleam,
A gentle clamp to guide the beam.
With whiskers twitching, code runs tight—
Hop, hop! The fog now treats us right.

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 @coderabbitai in a new review comment at the desired location with your query.
  • 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 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 @coderabbitai help to get the list of available commands.

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.

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: dcdbaf3
Using base ref: dcdbaf3
Base commit date: 2025-08-17T20:52:19+01:00 (Sunday, August 17, 2025 08:52 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: 0

Caution

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

⚠️ Outside diff range comments (1)
package/Shaders/ISApplyVolumetricLighting.hlsl (1)

67-67: Clamp temporal blend weight to [0,1] and harden VL ≥ 0 invariant

Please apply the following refactors in package/Shaders/ISApplyVolumetricLighting.hlsl to avoid extrapolation or negative lighting values:

• At line 84 (compute blend weight):

-    float temporalContribution = g_IntensityX_TemporalY.y 
-        * (1 - smoothstep(0, 1, min(1, 100 * abs(depth - previousDepth))));
+    // Prevent overshoot when temporal weight >1
+    float temporalContribution = saturate(
+        g_IntensityX_TemporalY.y
+        * (1 - smoothstep(0, 1, min(1, 100 * abs(depth - previousDepth))))
+    );

• At line 85 (final VL write):

-    psout.VL = lerp(adjustedVl, previousVl, temporalContribution * isValid);
+    // Enforce non-negative volumetric lighting
+    psout.VL = max(
+        0.0,
+        lerp(adjustedVl, previousVl, temporalContribution * isValid)
+    );

(Optional) If you foresee cases where previousVl may come from an untrusted source, you can also clamp it immediately after sampling:

previousVl = max(0.0, previousVl);

Please confirm whether the rendering invariant “VL is always ≥ 0 across frames” is intended; if so, the above ensures that negative history or over-driven temporal weights cannot introduce invalid values.

🧹 Nitpick comments (2)
package/Shaders/ISApplyVolumetricLighting.hlsl (2)

52-52: Use a float literal and express the bias as a fraction for clarity.

Avoid implicit int→float promotions in HLSL and make the bias self-documenting.

-	float adjustedVl = max(0, noiseGrad + vl - 0.0078125);
+	float adjustedVl = max(0.0, noiseGrad + vl - (1.0/128.0));

17-17: Minor naming cleanup: drop the duplicated “Sampler” suffix.

Purely cosmetic, but improves readability and consistency with other samplers.

-SamplerState NoiseGradSamplerSampler : register(s4);
+SamplerState NoiseGradSampler : register(s4);
@@
-	float noiseGrad = 0.03125 * NoiseGradSamplerTex.Sample(NoiseGradSamplerSampler, 0.125 * input.Position.xy).x;
+	float noiseGrad = 0.03125 * NoiseGradSamplerTex.Sample(NoiseGradSampler, 0.125 * input.Position.xy).x;

Also applies to: 50-50

📜 Review details

Configuration used: .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 dcdbaf3 and 166866e.

📒 Files selected for processing (1)
  • package/Shaders/ISApplyVolumetricLighting.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/ISApplyVolumetricLighting.hlsl
🧠 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/ISApplyVolumetricLighting.hlsl
🔇 Additional comments (1)
package/Shaders/ISApplyVolumetricLighting.hlsl (1)

52-52: Clamp-to-zero is correct and keeps VL physically plausible.

Clamping the accumulation to non-negative at the source prevents underflow-induced negative VL. This is a safe, targeted fix with minimal side effects.

@Pentalimbed Pentalimbed merged commit 9ccf889 into community-shaders:dev Aug 21, 2025
9 of 10 checks passed
sicsix pushed a commit to sicsix/skyrim-community-shaders that referenced this pull request Sep 1, 2025
@Pentalimbed Pentalimbed deleted the vl-neg-fix branch October 7, 2025 15:32
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