Skip to content

feat(llf): restore JSON-scaled Particle Lights#45

Merged
alandtse merged 5 commits into
devfrom
claude/restore-particle-lights-4V8KW
May 30, 2026
Merged

feat(llf): restore JSON-scaled Particle Lights#45
alandtse merged 5 commits into
devfrom
claude/restore-particle-lights-4V8KW

Conversation

@alandtse
Copy link
Copy Markdown
Owner

@alandtse alandtse commented May 26, 2026

Summary

Restores the Particle Lights feature that was previously removed from upstream Community Shaders, ported from ParticleTroned/skyrim-community-shaders@cs-1.5-PL-VR and adapted to our current LLF / contact-shadows shape.

  • Particle effects whose source texture matches an entry in Data\ParticleLights\*.ini (with optional Gradients/*.ini overrides) are queued during render passes, clustered, and emitted as dynamic lights through LLF's existing pipeline.
  • AIProcess::CalculateLightValue hook feeds particle lights into NPC light-level detection, so they affect stealth gameplay the way the legacy feature did.
  • BSBatchRenderer::RenderPassImmediately hooks let an INI's Cull = true suppress the original particle draw once it's been recognized as a light source.
  • Adds a sanitization pass (ClampFiniteOrDefault / SanitizeSettings) over all new tunables so malformed user JSON can't propagate NaN into the particle pipeline.
  • Bundles JSON Placed Lights intensity scaling (gated on Inverse Square Lighting runtime metadata) and an opt-in EnableParticleContactShadows toggle that routes through the new Particle light-flag bit.
  • Bumps Light Limit Fix/Shaders/Features/LightLimitFix.ini 3-1-0 → 3-2-0.

Files of note

  • New: src/Features/LightLimitFix/ParticleLights.{h,cpp} — INI loader, legacy first-win conflict policy
  • src/Features/LightLimitFix.{h,cpp} — queue/cluster/cache + queue, hooks, settings, sanitization, JSON-placed scaling
  • src/Hooks.{h,cpp}BSBatchRenderer_RenderPassImmediately1/2/3 thunks + SEH-guarded ShouldSkipRenderPassForParticleLights
  • package/Shaders/Common/SharedData.hlsliEnableParticleContactShadows replaces a pad slot
  • package/Shaders/Lighting.hlsl — particle-aware contact-shadow gate
  • features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsliLightFlags::Particle bit

Co-author

Test plan

  • CI build is green on SE/AE/VR presets (no Windows toolchain available in the agent container)
  • In-game: drop the Data\ParticleLights\*.ini configs from a particle-light pack (Embers HD, Lanterns of Skyrim, etc.); verify candles/braziers/torches emit light
  • In-game: confirm NPCs detect the player illuminated by a particle light (e.g., stand next to a brazier in a dark interior)
  • Settings: toggle Enable Particle Lights / Culling / Detection / Optimization; verify counter in Statistics panel changes
  • Cluster Threshold / Max Particles per Emitter / Max Particle Distance sliders behave as described in their tooltips
  • Contact Shadows: with Enable Particle Contact Shadows ON, particle lights cast short screen-space shadows; with it OFF, they do not (other point lights unaffected)
  • JSON Placed Lights: with Inverse Square Lighting loaded and a Light Placer mod, Intensity Scale 0–8 visibly scales those lights; without ISL, the controls are disabled
  • No regression to the existing Enable Contact Shadows toggle on non-particle point lights (VR-stable noise check from feat(llf): restore contact shadows with VR-aware noise #36 still holds)
  • LightLimitFix.json round-trips with the new fields after Save/Load; malformed values (NaN, out-of-range) get clamped to defaults

Heads-up for reviewers

  • BSEffectShaderProperty::unk88 and the two-arg REL::Relocate offsets on the BSBatchRenderer::RenderPassImmediately hooks are inherited verbatim from ParticleTroned's cs-1.5-PL-VR branch — they're known to work there but our extern/CommonLibSSE-NG revision should be confirmed to expose unk88.
  • The existing EffectExtensions::BSEffectShader_SetupGeometry hook in src/Hooks.cpp still co-exists with LightLimitFix::Hooks::BSEffectShader_SetupGeometry, so ExternalEmittance::UpdatePermutation runs twice per effect pass. Pre-existing condition, idempotent, not addressed here — worth a follow-up to delete the LLF-side call.

https://claude.ai/code/session_01SoyystxDs66Via3eZreNfU


Generated by Claude Code

Summary by CodeRabbit

  • New Features

    • Particle light support with configurable INI-driven presets and gradients
    • JSON-placed light intensity scaling controls
  • Improvements

    • Toggleable particle contact shadows and stricter contact-shadow gating
    • Expanded in-game UI: particle light settings, contact-shadow controls, and statistics
  • Stability/Performance

    • Safer runtime handling and cache/queue management to reduce crashes and improve robustness

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 02:33
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@alandtse, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 12 minutes and 54 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 31c036fc-22d9-4b3e-b1d4-568bad22390e

📥 Commits

Reviewing files that changed from the base of the PR and between 0fcfaa1 and 5113746.

📒 Files selected for processing (11)
  • extern/CommonLibSSE-NG
  • features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli
  • package/Shaders/Common/SharedData.hlsli
  • package/Shaders/Lighting.hlsl
  • src/Features/LightLimitFix.cpp
  • src/Features/LightLimitFix.h
  • src/Features/LightLimitFix/Particle.cpp
  • src/Features/LightLimitFix/ParticleLights.cpp
  • src/Features/LightLimitFix/ParticleLights.h
  • src/Hooks.cpp
  • src/Hooks.h
📝 Walkthrough

Walkthrough

This PR adds configurable particle-light support to the LightLimitFix shader feature. It includes shader-side light-type flagging and contact-shadow gating, INI-based particle configuration loading, CPU-side luminance computation and clustering, JSON-placed light intensity scaling, and render-pass culling hooks.

Changes

Particle Lights Feature Addition

Layer / File(s) Summary
Shader contracts and particle light flag
features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli, package/Shaders/Common/SharedData.hlsli, package/Shaders/Lighting.hlsl
LightFlags adds a Particle bit flag; LightLimitFixSettings constant buffer adds EnableParticleContactShadows; Lighting.hlsl gates contact-shadow tracing to exclude Simple lights and require the new particle-contact-shadow setting for Particle lights.
Particle lights configuration system
src/Features/LightLimitFix/ParticleLights.h, src/Features/LightLimitFix/ParticleLights.cpp, src/Globals.h, src/Globals.cpp
New ParticleLights class with Config and GradientConfig; GetConfigs() loads INI files from Data\ParticleLights and Data\ParticleLights\Gradients, sanitizes values, applies first-entry-wins policy, and exposes a global instance.
Type system and core expansion
src/Features/LightLimitFix.h
Adds LightFlags::Particle, PerFrame cbuffer field EnableParticleContactShadows, cached/queued particle-light types with mutexes, helper and hook declarations, and expands Settings with particle and JSON-placed-light controls.
Feature lifecycle, settings, and UI
src/Features/LightLimitFix.cpp
Adds Reset() to clear particle state, sanitizes settings on load/save/restore, reorganizes ImGui with Contact Shadows and Particle Lights controls, and adds a Statistics tree.
Strict-light setup and JSON-placed light handling
src/Features/LightLimitFix.cpp
Hardens BSLightingShader setup with guards and exception handling, refreshes JSON-placed-light cache per frame, detects JSON-placed lights with caching, and applies conditional intensity scaling for interior/portal-strict filters.
Light collection and clustered lighting updates
src/Features/LightLimitFix.cpp
Rewrites UpdateLights to add GPU/context guards, refresh JSON cache per frame, explicitly populate room/portal flags for portal-strict lights, and process queued particle lights before GPU upload (only memcpy_s when bytes>0).
Particle detection and configuration
src/Features/LightLimitFix/Particle.cpp
Detect particle sources via texture-stem matching, extract emissive tints from geometry/material/vertex data with fallback ordering, cache per-geometry references with versioning, and produce ParticleLightReference values used for enqueueing.
Particle clustering and caching
src/Features/LightLimitFix/Particle.cpp
Enqueue particle lights with refcounting, aggregate non-billboard particles into clustered lights, convert billboards to single entries, apply distance/fade culling and relocations-backed dimming, populate lightsData and cachedParticleLights, and hook AI luminance to include particle contributions.
Rendering hooks and pass culling
src/Hooks.h, src/Hooks.cpp
Declare/install two additional BSBatchRenderer::RenderPassImmediately hook variants; add ShouldSkipRenderPassForParticleLights() with SEH fails-open guard; update all three thunks to early-return when a pass should be skipped.
Submodule pin
extern/CommonLibSSE-NG
Update submodule commit pin to a newer SHA.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • alandtse/open-shaders#43: Both PRs modify the same contact-shadow shader path—updating package/Shaders/Common/SharedData.hlsli’s LightLimitFixSettings constant-buffer layout and changing package/Shaders/Lighting.hlsl’s contact-shadow eligibility/gating logic (main PR adds particle-light + EnableParticleContactShadows, retrieved PR adds tuning-driven step/count and MinIntensity gating).
  • alandtse/open-shaders#36: Both PRs modify the LightLimitFix contact-shadow shader path—SharedData.hlsli adds different contact-shadow toggles and package/Shaders/Lighting.hlsl changes how contactShadow is computed/gated and applied to light shadowing—so the main PR’s particle contact-shadow work is directly related to the retrieved PR’s restored contact-shadow implementation.

Poem

🐰 I hopped through config files at night,

INI glows and particles bright,
Shader flags and clustered beams,
Luminance woven into dreams,
Hooks keep passes tidy and light. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.41% 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 'feat(llf): restore JSON-scaled Particle Lights' clearly and accurately summarizes the main change: restoring particle lights functionality with JSON-placed light scaling integration. It is concise, specific, and directly relates to the primary objective of the PR.
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
  • Commit unit tests in branch claude/restore-particle-lights-4V8KW

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

No actionable suggestions for changed features.

Copy link
Copy Markdown

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

This PR restores Light Limit Fix’s “Particle Lights” functionality by recognizing configured particle effects during rendering, emitting them as dynamic lights through LLF’s pipeline, and optionally feeding them into NPC light-level/stealth detection. It also adds JSON-placed light intensity scaling (gated by Inverse Square Lighting metadata) and extends LLF contact shadows to optionally include particle lights.

Changes:

  • Add particle-light config loading (Data\\ParticleLights\\*.ini + Gradients\\*.ini) and a render-pass hook path to queue/cull recognized particle emitters.
  • Extend LLF runtime lighting to cluster/emit particle lights, support particle-contact-shadows, and add JSON-placed light intensity scaling + settings sanitization.
  • Update shader cbuffers and light-flag bits to support particle-specific contact shadow gating; bump LLF feature version to 3-2-0.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Hooks.h Declares additional BSBatchRenderer::RenderPassImmediately hook thunks used for particle-light culling.
src/Hooks.cpp Implements render-pass skip logic (SEH-guarded) and installs the new render-pass hooks.
src/Globals.h Forward-declares ParticleLights and exposes it under globals::features::llf.
src/Globals.cpp Instantiates the global ParticleLights manager.
src/Features/LightLimitFix/ParticleLights.h Adds ParticleLights config structs and config maps.
src/Features/LightLimitFix/ParticleLights.cpp Loads particle-light configs and gradient overrides from INI files.
src/Features/LightLimitFix.h Adds LLF state for particle lights + JSON placed-light cache, new settings fields, and new hook declarations.
src/Features/LightLimitFix.cpp Implements particle light detection/queueing, clustering/emission, NPC luminance injection, JSON placed-light scaling, and settings sanitization.
package/Shaders/Lighting.hlsl Gates contact shadows for particle lights via a new Particle light-flag + setting.
package/Shaders/Common/SharedData.hlsli Extends LLF settings cbuffer with EnableParticleContactShadows.
features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli Adds LightFlags::Particle bit.
features/Light Limit Fix/Shaders/Features/LightLimitFix.ini Bumps LLF shader feature version 3-1-0 → 3-2-0.

Comment thread src/Features/LightLimitFix.cpp Outdated
Comment thread src/Features/LightLimitFix.cpp
Comment thread src/Features/LightLimitFix.cpp Outdated
Comment thread src/Features/LightLimitFix/ParticleLights.cpp Outdated
Comment thread src/Features/LightLimitFix.cpp Outdated
Copy link
Copy Markdown

@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: 3

🤖 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.

Inline comments:
In `@src/Features/LightLimitFix.cpp`:
- Around line 1026-1035: The current block treats a non-empty
material->greyscaleTexturePath as fatal if ExtractTextureStem or a matching
entry in particleLights.particleLightGradientConfigs isn't found (calling
cacheInvalidReference(node)); change it so a missing/invalid gradient is treated
as an optional override instead: call
ExtractTextureStem(material->greyscaleTexturePath.c_str()), and if the stem is
empty or gradientConfigs.find(textureName) == gradientConfigs.end(), do NOT
return cacheInvalidReference(node) but simply leave hasGradientConfig false and
continue; only set hasGradientConfig = true when a matching itGradient is found.

In `@src/Features/LightLimitFix.h`:
- Around line 334-335: The hook installation for
AIProcess_CalculateLightValue_GetLuminance uses REL::Relocate with only two
offsets (SE/AE) but lacks the VR offset; update the stl::write_thunk_call
invocation in LightLimitFix.h to include the VR relocation (or follow the
pattern used by other hooks: use REL::Relocate with three offsets or a
VR-specific relocation branch) so the REL::RelocationID(...).address() +
REL::Relocate(...) resolves correctly for VR builds; reference the symbol
AIProcess_CalculateLightValue_GetLuminance and the existing
stl::write_thunk_call/REL::RelocationID call to add the third VR offset or
conditional path consistent with the rest of the codebase.

In `@src/Features/LightLimitFix/ParticleLights.cpp`:
- Around line 62-67: The INI numeric fields read into ParticleLightData
(data.colorMult.red/green/blue, data.radiusMult, data.saturationMult) are not
validated and can be NaN/inf or out-of-range; before assigning values returned
from ini.GetDoubleValue, validate with std::isfinite and clamp to safe ranges
(e.g., color multipliers >=0 and capped to a reasonable max like 100.0,
radiusMult >=0 and capped to a sane max, saturationMult within [0, 10] or
similar) and fall back to the default (1.0) when invalid; update the reads in
ParticleLights.cpp to sanitize each value and only store the validated/clamped
floats into data.* to avoid propagating malformed values into rendering math.
🪄 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

Run ID: be901d39-2499-466a-ba69-a7d18771de66

📥 Commits

Reviewing files that changed from the base of the PR and between 0f307d2 and 0fcfaa1.

📒 Files selected for processing (12)
  • features/Light Limit Fix/Shaders/Features/LightLimitFix.ini
  • features/Light Limit Fix/Shaders/LightLimitFix/Common.hlsli
  • package/Shaders/Common/SharedData.hlsli
  • package/Shaders/Lighting.hlsl
  • src/Features/LightLimitFix.cpp
  • src/Features/LightLimitFix.h
  • src/Features/LightLimitFix/ParticleLights.cpp
  • src/Features/LightLimitFix/ParticleLights.h
  • src/Globals.cpp
  • src/Globals.h
  • src/Hooks.cpp
  • src/Hooks.h

Comment thread src/Features/LightLimitFix.cpp Outdated
Comment thread src/Features/LightLimitFix.h
Comment thread src/Features/LightLimitFix/ParticleLights.cpp Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

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

@alandtse alandtse force-pushed the claude/restore-particle-lights-4V8KW branch from 0fcfaa1 to 8f00f64 Compare May 26, 2026 03:25
Copilot AI review requested due to automatic review settings May 26, 2026 03:43
Copy link
Copy Markdown

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Comment thread src/Features/LightLimitFix/Particle.cpp Outdated
Comment thread src/Hooks.cpp
Comment thread src/Features/LightLimitFix.h Outdated
@alandtse alandtse changed the title feat(llf): restore Particle Lights with JSON-placed light scaling feat(llf): restore JSON-scaled Particle Lights May 29, 2026
Copilot AI review requested due to automatic review settings May 29, 2026 03:32
@alandtse alandtse force-pushed the claude/restore-particle-lights-4V8KW branch from d8b678d to 32c9bc0 Compare May 29, 2026 03:32
Copy link
Copy Markdown

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Comment thread src/Features/LightLimitFix/Particle.cpp
Comment thread src/Features/LightLimitFix/Particle.cpp
Restores the Particle Lights feature removed from upstream Community
Shaders, ported from ParticleTroned's cs-1.5-PL-VR branch and adapted to
the current LLF / contact-shadows shape. Particle effects matching a
Data\ParticleLights\*.ini entry are queued, clustered, and emitted as
dynamic lights through LLF's pipeline, fed into AIProcess light-level
detection for stealth, and optionally culled from their original draw.
Adds JSON-placed light intensity scaling (gated on Inverse Square
Lighting metadata) and an opt-in particle contact-shadow toggle.

Co-authored-by: ParticleTroned <248299730+ParticleTroned@users.noreply.github.com>
@alandtse alandtse force-pushed the claude/restore-particle-lights-4V8KW branch from 32c9bc0 to 12de972 Compare May 29, 2026 06:41
alandtse and others added 2 commits May 28, 2026 23:54
Restructures the Particle Lights / Placed Lights settings to match the
SeparatorText + subsection-tree convention used elsewhere:

- Adds an intro noting particle lights are additive emitters that don't
  cast shadow-map shadows (so they never appear in the caster table) and
  require a Data\ParticleLights\*.ini config pack to do anything.
- De-duplicates the "Particle Lights" header (separator + identically
  named tree) and splits the controls into Performance / Appearance
  subsection trees, mirroring the Contact Shadows layout.
- Promotes "Placed Lights (JSON)" to its own section with a short intro.
- Fills in missing tooltips (Saturation, Particle/Billboard
  Brightness/Radius).

UI text and layout only; no behavior change.
CommonLibVR 4.19.0 names BSEffectShaderProperty's previously-unknown
member (PR alandtse/CommonLibVR#154). Switch the particle-light tint
code from shaderProperty->unk88 to ->emittanceColor; no behavior change
(same offset 0x88). Also trims the now-redundant explanatory comments
and merges the duplicate anonymous namespace in ParticleLights.cpp.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 29, 2026 08:39
Copy link
Copy Markdown

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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 12 comments.

Comment thread src/Features/LightLimitFix.cpp
Comment thread src/Features/LightLimitFix/ParticleLights.cpp
Comment thread src/Features/LightLimitFix.cpp
Comment thread src/Hooks.cpp
Comment thread src/Features/LightLimitFix.cpp
Comment thread src/Hooks.cpp
Comment thread src/Features/LightLimitFix.cpp
Comment thread src/Features/LightLimitFix/ParticleLights.cpp
Comment thread src/Features/LightLimitFix.cpp
Comment thread src/Hooks.cpp
alandtse and others added 2 commits May 29, 2026 01:53
The ParticleLights config holder was only ever read by LightLimitFix code
(its own TUs), so it doesn't need to live in globals::features::llf. Move
it to a LightLimitFix member and drop the Globals.h/Globals.cpp churn
(forward decl, extern, include, definition). Unlike the depth-buffer
globals in that namespace, no file-scope/cross-TU code consumes it.

No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…y-out

GetCommonBufferData() never set perFrame.EnableContactShadows (lost in the
dev merge), so the shader saw it as 0 and contact shadows were disabled
outright. Restore the assignment.

Also clear cachedParticleLights in UpdateLights()'s context/buffer early-out
so AddParticleLightLuminance (gameplay thread) can't feed stale lights into
NPC detection — matching the existing clearAndUpdate path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alandtse alandtse merged commit 5f5baf4 into dev May 30, 2026
19 checks passed
@alandtse alandtse deleted the claude/restore-particle-lights-4V8KW branch May 30, 2026 05:29
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