feat: lighting for rain and snow
Summary by CodeRabbit
- New Features
- Enhanced particle lighting with per-fragment lighting accumulation for richer visuals.
- Added clustered light sampling and optional inverse-square lighting for more accurate illumination.
- Improved light attenuation and shadow-aware contributions for more realistic particle appearance.
- Particles now incorporate directional and ambient lighting data for consistent scene integration.
Walkthrough
Added per-fragment lighting to the particle shader: vertex shader now outputs view-space position, and pixel shader accumulates directional, ambient, and clustered light contributions with conditional attenuation and compile-time includes.
Changes
| Cohort / File(s) | Summary |
|---|---|
Particle shader package/Shaders/Particle.hlsl |
Added float3 ViewPositionVS : TEXCOORD2 to VS_OUTPUT. Vertex shader propagates view-space position. Pixel shader replaced single ColorScale path with per-fragment lighting: reads directional & ambient from SharedData.hlsli, computes world position, conditionally samples clustered lights via LightLimitFix.hlsli and applies attenuation via InverseSquareLighting.hlsli when enabled. Added conditional include directives and light accumulation loop. |
Sequence Diagram
sequenceDiagram
participant VS as Vertex Shader
participant PS as Pixel Shader
participant Cluster as Light Cluster (LightLimitFix)
participant Math as Lighting Math
VS->>VS: compute finalViewPosition
VS->>VS: vsout.ViewPosition = finalViewPosition.xyz
VS-->>PS: emit VS_OUTPUT (with ViewPositionVS)
PS->>PS: sample baseColor
PS->>PS: read directional & ambient (SharedData)
PS->>PS: propertyColor = dir+ambient
PS->>PS: worldPos = ViewToWorld * ViewPositionVS
rect rgb(235,245,255)
Note over PS,Cluster: if LIGHT_LIMIT_FIX defined
PS->>Cluster: fetch lights for fragment/cluster
Cluster-->>PS: list of lights
end
loop for each light
PS->>Math: compute lightDir, distance
alt ISL enabled
Math-->>PS: inverse-square attenuation
else
Math-->>PS: quadratic falloff attenuation
end
PS->>PS: accumulate propertyColor += lightContribution
end
PS->>PS: finalColor = propertyColor * baseColor
PS-->>PS: output final fragment color
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
🐇 I nudged view pos into the vertex stream,
Collected suns within each tiny gleam,
Direction, ambient, clusters in a swirl,
Each particle now catches light and twirls,
Shader hops brighter — a luminous dream.
Pre-merge checks and finishing touches
✅ 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 succinctly conveys the primary change of this pull request, which is adding lighting support specifically for rain and snow particles in the shader. It aligns with the code modifications that introduce per-fragment lighting, directional and ambient contributions, and cluster light integration for particle effects. Therefore, it accurately captures the main purpose of the changes without unnecessary detail. |
| Docstring Coverage | ✅ Passed | No functions found in the changes. Docstring coverage check skipped. |
✨ Finishing touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
particle-lighting
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Using provided base ref: 79aebb6df5a67064a4380ac3763965f400afbe58 Using base ref: 79aebb6df5a67064a4380ac3763965f400afbe58 Base commit date: 2025-10-18T22:52:09+01:00 (Saturday, October 18, 2025 10:52 PM) No actionable suggestions for changed features.