Skip to content

refactor(volumetric-lighting): use constant for threshold#2257

Merged
alandtse merged 2 commits into
community-shaders:devfrom
davo0411:volcleanup
May 3, 2026
Merged

refactor(volumetric-lighting): use constant for threshold#2257
alandtse merged 2 commits into
community-shaders:devfrom
davo0411:volcleanup

Conversation

@davo0411
Copy link
Copy Markdown
Collaborator

@davo0411 davo0411 commented May 2, 2026

small fix i saw when doing hdr sun

Summary by CodeRabbit

  • Refactor
    • Tuned volumetric lighting computation for more consistent rendering results and improved stability of light thresholds, reducing subtle artifacts in volumetric effects.

Copilot AI review requested due to automatic review settings May 2, 2026 00:50
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

📝 Walkthrough

Walkthrough

A local constant kVLThresholdBias (set to 1.0 / 128.0) was added and the adjustedVl computation in ISApplyVolumetricLighting.hlsl now subtracts kVLThresholdBias instead of the hardcoded 0.0078125.

Changes

Volumetric Lighting Threshold Bias Constant

Layer / File(s) Summary
Constant Declaration
package/Shaders/ISApplyVolumetricLighting.hlsl
Introduces kVLThresholdBias = 1.0 / 128.0 inside main.
Bias Application
package/Shaders/ISApplyVolumetricLighting.hlsl
adjustedVl now subtracts kVLThresholdBias instead of the literal 0.0078125, retaining max(0.0, ...) clamp.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested reviewers

  • jiayev

Poem

🐰 I nibble code beneath the sky,
A tiny constant hops nearby.
From number fixed to name so neat,
Volumetric light feels tidy and sweet. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title 'refactor(volumetric-lighting): use constant for threshold' accurately describes the main change: replacing a hardcoded magic number (0.0078125) with a named constant (kVLThresholdBias) in the volumetric lighting shader.

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

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

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

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

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

1-1: 💤 Low value

Conventional commit title suggestion (optional).

Your current title looks close to conventional commits; consider making it more specific about the actual change: e.g. refactor(vol lighting): replace VL bias magic (and keep the body under 72 chars describing the 0.0078125kVLThresholdBias replacement).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package/Shaders/ISApplyVolumetricLighting.hlsl` at line 1, Update the commit
title to follow conventional commits and be specific about the change (e.g.,
"refactor(vol lighting): replace VL bias magic"), and shorten the commit body to
<=72 characters describing the replacement of the magic constant (0.0078125)
with a named constant (kVLThresholdBias) so the title and body clearly
communicate the refactor affecting volumetric lighting bias.

34-38: 💤 Low value

Move kVLThresholdBias to file scope (optional).

Behavior should be unchanged, but putting the constant at file scope (instead of inside main) improves readability and avoids any ambiguity about per-entry duplication.

Suggested tweak
+static const float kVLThresholdBias = 1.0 / 128.0;

 PS_OUTPUT main(PS_INPUT input)
 {
 	PS_OUTPUT psout;
-	static const float kVLThresholdBias = 1.0 / 128.0;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package/Shaders/ISApplyVolumetricLighting.hlsl` around lines 34 - 38, The
constant kVLThresholdBias is declared inside the PS_ENTRY function main(PS_INPUT
input), which can imply per-call duplication; move the declaration of static
const float kVLThresholdBias = 1.0 / 128.0; out of main to file scope (top of
the shader) and remove the in-function declaration so main continues to
reference the same symbol but the constant lives at file scope for clarity and
no behavioral change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package/Shaders/ISApplyVolumetricLighting.hlsl`:
- Line 53: The call to max in the adjustedVl computation uses an integer literal
which can cause implicit int→float coercion; update the expression in the
adjustedVl assignment (the line computing float adjustedVl = max(...)) to use a
floating-point literal such as 0.0 or 0.0f (e.g., max(0.0, noiseGrad + vl -
kVLThresholdBias)) so the types remain consistent and avoid shader validation
warnings/errors.

---

Nitpick comments:
In `@package/Shaders/ISApplyVolumetricLighting.hlsl`:
- Line 1: Update the commit title to follow conventional commits and be specific
about the change (e.g., "refactor(vol lighting): replace VL bias magic"), and
shorten the commit body to <=72 characters describing the replacement of the
magic constant (0.0078125) with a named constant (kVLThresholdBias) so the title
and body clearly communicate the refactor affecting volumetric lighting bias.
- Around line 34-38: The constant kVLThresholdBias is declared inside the
PS_ENTRY function main(PS_INPUT input), which can imply per-call duplication;
move the declaration of static const float kVLThresholdBias = 1.0 / 128.0; out
of main to file scope (top of the shader) and remove the in-function declaration
so main continues to reference the same symbol but the constant lives at file
scope for clarity and no behavioral change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 993b0e4f-426d-43fb-ba69-b362d7167089

📥 Commits

Reviewing files that changed from the base of the PR and between 2cdb354 and d3ed0e5.

📒 Files selected for processing (1)
  • package/Shaders/ISApplyVolumetricLighting.hlsl

Comment thread package/Shaders/ISApplyVolumetricLighting.hlsl Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the volumetric lighting apply pixel shader to replace an inline “magic number” threshold with a named constant, improving readability/maintainability while preserving the numeric value.

Changes:

  • Introduced a named constant for the VL threshold bias (1/128).
  • Replaced the hard-coded 0.0078125 with the named constant in the VL adjustment computation.

Comment thread package/Shaders/ISApplyVolumetricLighting.hlsl
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@alandtse
Copy link
Copy Markdown
Collaborator

alandtse commented May 2, 2026

Where did your magic number come from? I believe the number you're replacing came from vanilla.

@SkrubbySkrubInAShrub
Copy link
Copy Markdown
Collaborator

SkrubbySkrubInAShrub commented May 2, 2026

The magic number is exactly 1/128.

@alandtse alandtse changed the title refactor(vol lighting): magic number fix refactor(volumetric-lighting): magic number fix May 3, 2026
@alandtse alandtse changed the title refactor(volumetric-lighting): magic number fix refactor(volumetric-lighting): use constant for threshold May 3, 2026
@alandtse alandtse merged commit 28b0a1a into community-shaders:dev May 3, 2026
17 checks passed
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 15, 2026
…shaders#2257)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 15, 2026
…shaders#2257)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
ParticleTroned pushed a commit to ParticleTroned/skyrim-community-shaders that referenced this pull request May 16, 2026
…shaders#2257)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
IgorAlanAlbuquerque pushed a commit to IgorAlanAlbuquerque/skyrim-community-shaders that referenced this pull request May 29, 2026
…shaders#2257)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

4 participants