Skip to content

feat(cloud shadows): add inner cloud shadowing#2050

Closed
InTheBottle wants to merge 5 commits into
community-shaders:devfrom
InTheBottle:inner-cloud-shadows
Closed

feat(cloud shadows): add inner cloud shadowing#2050
InTheBottle wants to merge 5 commits into
community-shaders:devfrom
InTheBottle:inner-cloud-shadows

Conversation

@InTheBottle
Copy link
Copy Markdown
Contributor

@InTheBottle InTheBottle commented Apr 3, 2026

Summary by CodeRabbit

  • New Features

    • Volumetric inner cloud shadow rendering for richer atmospheric shadows
    • New "Inner Cloud Shadow Opacity" slider in cloud shadow settings
  • Improvements

    • Increased precision of the main opacity slider and updated tooltip text
    • First-frame initialization to clear cloud shadow targets, reducing visual artifacts and improving stability

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 3, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84f1e712-7bf8-4ba6-83ad-783cabb867fd

📥 Commits

Reviewing files that changed from the base of the PR and between e29b12a and 44a9942.

📒 Files selected for processing (3)
  • package/Shaders/Sky.hlsl
  • src/Features/CloudShadows.cpp
  • src/Features/CloudShadows.h

📝 Walkthrough

Walkthrough

Introduces a volumetric inner-cloud shadow path: new shader texture VolumetricCloudShadowsTexture (t25), shifts existing CloudShadowsTexture to t26, adds InnerCloudShadowOpacity to shader and C++ settings, updates resource bindings and sky-pixel shader sampling to apply inner-cloud shadowing.

Changes

Cohort / File(s) Summary
Shader Resource Bindings
features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli
Added TextureCube<float> VolumetricCloudShadowsTexture : register(t25); and moved CloudShadowsTexture binding from t25t26.
Shared Shader Settings
package/Shaders/Common/SharedData.hlsli
Added float InnerCloudShadowOpacity; to SharedData::CloudShadowsSettings and adjusted padding (float3 pad0float2 pad0).
Sky Pixel Shader
package/Shaders/Sky.hlsl
Added a CLOUD_SHADOWS && CLOUDS path performing a 4-sample Poisson-disc volumetric ray sampling loop; computes rayShadow and modulates psout.Color.xyz by InnerCloudShadowOpacity.
Engine Settings & Bindings
src/Features/CloudShadows.h, src/Features/CloudShadows.cpp
Added InnerCloudShadowOpacity to CloudShadows::Settings (default 0.5) and adjusted padding/alignment; updated UI slider and tooltips; changed D3D11 SRV binding so the cubemap copy is bound to both slots 25/26 where appropriate and first-frame copy RTVs are cleared.

Sequence Diagram(s)

sequenceDiagram
    participant Engine as Engine (C++)
    participant SRV as Cubemap SRVs
    participant SkyPS as Sky Pixel Shader
    participant VolTex as VolumetricCloudShadowsTexture (t25)
    participant OccTex as CloudShadowsTexture (t26)
    Engine->>SRV: Bind texCubemapCloudOccCopy -> slot 25\nBind texCubemapCloudOcc / copy -> slot 26 (per pass)
    SkyPS->>VolTex: SampleLevel(…, 0) for raySample.z >= 0
    SkyPS->>OccTex: Sample for legacy shadowing
    SkyPS->>SkyPS: Accumulate 4-sample rayShadow, apply InnerCloudShadowOpacity
    SkyPS-->>Engine: Output modified psout.Color
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • doodlum
  • alandtse
  • jiayev

Poem

🐇 Through cirrus halls I softly tread,
Textures shifted, shadows spread,
Four tiny rays in Poisson play,
Inner dusk that dims the day,
A rabbit cheers—the sky's new thread.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 'feat(cloud shadows): add inner cloud shadowing' directly and clearly summarizes the main change—adding inner cloud shadow functionality to the cloud shadows system.

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

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

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

github-actions Bot commented Apr 3, 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)
src/Features/CloudShadows.h (1)

9-14: Add a compile-time layout guard for the shader settings struct.

This now has to stay byte-for-byte compatible with SharedData::CloudShadowsSettings; if the size or alignment drifts later, the rest of FeatureData shifts silently. A local static_assert would fail that fast.

♻️ Proposed guard
 	struct alignas(16) Settings
 	{
 		float Opacity = 0.8f;
 		float InnerCloudShadowOpacity = 0.5f;
 		float pad[2];
 	};
+
+	static_assert(sizeof(Settings) == 16, "CloudShadows::Settings must match SharedData::CloudShadowsSettings");
+	static_assert(alignof(Settings) == 16);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Features/CloudShadows.h` around lines 9 - 14, The Settings struct must be
byte-for-byte compatible with SharedData::CloudShadowsSettings to prevent silent
FeatureData layout shifts; add compile-time layout guards by inserting
static_asserts that compare sizeof(Settings) ==
sizeof(SharedData::CloudShadowsSettings) and alignof(Settings) ==
alignof(SharedData::CloudShadowsSettings) (and optionally check offsetof for
members if desired) so any size/alignment drift fails at compile time; place
these static_asserts after the struct definition referencing Settings and
SharedData::CloudShadowsSettings.
package/Shaders/Sky.hlsl (1)

246-273: Skip the ray-march when inner cloud shadows are effectively off.

With InnerCloudShadowOpacity == 0, this block still does four normalizations and up to four cubemap samples per cloud pixel for a no-op result. Guarding the branch with the setting lets users disable the cost as well as the visual effect.

♻️ Proposed tweak
-	if (baseColor.w > 0.0) {
+	if (baseColor.w > 0.0 && SharedData::cloudShadowsSettings.InnerCloudShadowOpacity > 0.0) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package/Shaders/Sky.hlsl` around lines 246 - 273, Skip the inner-cloud shadow
ray-march when the setting disables it by adding an early guard that checks
SharedData::cloudShadowsSettings.InnerCloudShadowOpacity > 0.0 before performing
the heavy work (the whole block that computes viewDir, rayStep, PoissonDisc, the
unrolled loop and the SampleLevel calls); only run the normalization, Poisson
sampling and CloudShadows::VolumetricCloudShadowsTexture.SampleLevel lookups
when InnerCloudShadowOpacity is non-zero, and otherwise leave psout.Color
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Features/CloudShadows.cpp`:
- Around line 139-147: The uninitialized texCubemapCloudOccCopy is bound in
EarlyPrepass (t25) before any rendering copies in ReflectionsPrepass, so
initialize/clear the cubemap in SetupResources: explicitly create or zero-clear
texCubemapCloudOccCopy (and texCubemapCloudOcc) or clear all
cubemapCloudOccCopyRTVs once during SetupResources so that ReflectionsPrepass
doesn't copy garbage; ensure this initialization runs before
ReflectionsPrepass/EarlyPrepass and reference texCubemapCloudOccCopy,
cubemapCloudOccCopyRTVs, SetupResources(), ReflectionsPrepass(), and
EarlyPrepass() when making the change.

---

Nitpick comments:
In `@package/Shaders/Sky.hlsl`:
- Around line 246-273: Skip the inner-cloud shadow ray-march when the setting
disables it by adding an early guard that checks
SharedData::cloudShadowsSettings.InnerCloudShadowOpacity > 0.0 before performing
the heavy work (the whole block that computes viewDir, rayStep, PoissonDisc, the
unrolled loop and the SampleLevel calls); only run the normalization, Poisson
sampling and CloudShadows::VolumetricCloudShadowsTexture.SampleLevel lookups
when InnerCloudShadowOpacity is non-zero, and otherwise leave psout.Color
unchanged.

In `@src/Features/CloudShadows.h`:
- Around line 9-14: The Settings struct must be byte-for-byte compatible with
SharedData::CloudShadowsSettings to prevent silent FeatureData layout shifts;
add compile-time layout guards by inserting static_asserts that compare
sizeof(Settings) == sizeof(SharedData::CloudShadowsSettings) and
alignof(Settings) == alignof(SharedData::CloudShadowsSettings) (and optionally
check offsetof for members if desired) so any size/alignment drift fails at
compile time; place these static_asserts after the struct definition referencing
Settings and SharedData::CloudShadowsSettings.
🪄 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: f60a47a2-e9e6-4902-bc0f-9f760c54b670

📥 Commits

Reviewing files that changed from the base of the PR and between 2017125 and e29b12a.

📒 Files selected for processing (5)
  • features/Cloud Shadows/Shaders/CloudShadows/CloudShadows.hlsli
  • package/Shaders/Common/SharedData.hlsli
  • package/Shaders/Sky.hlsl
  • src/Features/CloudShadows.cpp
  • src/Features/CloudShadows.h

Comment thread src/Features/CloudShadows.cpp
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 3, 2026

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

@doodlum doodlum closed this Apr 3, 2026
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