feat: always use worldspace lighting#1266
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe patch updates the memory patching logic in Changes
Sequence Diagram(s)sequenceDiagram
participant GameRuntime
participant HooksPatch
participant BSLightingShader
GameRuntime->>HooksPatch: Initialize patch for SetupGeometry
HooksPatch->>BSLightingShader: Write 4-byte instruction at module-specific offset
BSLightingShader-->>GameRuntime: Always uses world space for rendering
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Automated formatting by clang-format, prettier, and other hooks. See https://pre-commit.ci for details.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
src/Hooks.cpp (1)
1148-1150: Use optimized NOP instruction for better performance.The SE module currently uses basic NOPs, but could benefit from using optimized multi-byte NOPs for better instruction cache performance.
Apply this diff to use optimized NOPs:
- std::uint8_t patch[] = { 0x90, 0x90, 0x90, 0x90 }; // 4 NOPs + std::uint8_t patch[] = { 0x0F, 0x1F, 0x40, 0x00 }; // 4-byte optimized NOP
🧹 Nitpick comments (1)
src/Hooks.cpp (1)
1135-1137: Clarify the comment about what's being patched.The comment mentions
updateEyePositionbut based on the PR objectives and AI summary, this patch is actually modifying render space usage to force world space instead of view space, not specifically the eye position update logic.Consider updating the comment to be more accurate:
- // Patch render space in BSLightingShader::SetupGeometry to always use world space - // The variable updateEyePosition is set to 1 when not skinned. By patching to be 0 it will always use world space - // We offset from the base address of the containing function to the start of the patch + // Patch render space in BSLightingShader::SetupGeometry to always use world space + // This patches the instruction that controls render space selection to force world space usage + // We offset from the base address of the containing function to the start of the patch
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package/Shaders/Lighting.hlslis excluded by!**/*.hlsl
📒 Files selected for processing (1)
src/Hooks.cpp(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-05T05:20:45.823Z
Learning: In the skyrim-community-shaders repository, file deletion error handling improvements that replace existence checks and try-catch blocks with std::filesystem::remove error-code-based approaches are considered bug fixes rather than refactoring, as they address inadequate error handling and misleading log messages.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-06-24T07:17:36.604Z
Learning: When reviewing PRs, always clarify the scope if there are multiple related features or dependencies. WeatherPicker was a separate PR that was already merged, while this PR focuses specifically on WetnessEffects climate preset system enhancements.
Learnt from: jiayev
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-18T15:21:03.641Z
Learning: In the skyrim-community-shaders rendering pipeline, materials with alpha < 1 or alpha blending enabled are rendered in non-deferred mode rather than deferred mode. This means issues with dynamic cubemaps on transparent materials are actually non-deferred rendering issues.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent 4-byte size, proper 16-byte alignment in constant buffers, and cross-platform compatibility when passing data between C++ and HLSL shaders.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent size, alignment, and cross-platform compatibility when passing data to shader constant buffers.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: features/Wetness Effects/Shaders/WetnessEffects/WetnessEffects.hlsli:57-61
Timestamp: 2025-06-17T05:40:22.785Z
Learning: Default parameter values are supported in the HLSL compiler used by the skyrim-community-shaders project, contrary to standard HLSL (FXC/DXC) limitations.
src/Hooks.cpp (3)
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-05T05:20:45.823Z
Learning: In the skyrim-community-shaders repository, file deletion error handling improvements that replace existence checks and try-catch blocks with std::filesystem::remove error-code-based approaches are considered bug fixes rather than refactoring, as they address inadequate error handling and misleading log messages.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent 4-byte size, proper 16-byte alignment in constant buffers, and cross-platform compatibility when passing data between C++ and HLSL shaders.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: src/Features/WetnessEffects.h:36-36
Timestamp: 2025-06-08T11:25:14.536Z
Learning: In the skyrim-community-shaders project, boolean flags in C++ structs that interface with HLSL shaders use `uint` type instead of `bool` for compatibility reasons. This ensures consistent size, alignment, and cross-platform compatibility when passing data to shader constant buffers.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Validate shader compilation (Flatrim, .github/configs/shader-validation.yaml)
- GitHub Check: Validate shader compilation (VR, .github/configs/shader-validation-vr.yaml)
- GitHub Check: Build plugin and addons
🔇 Additional comments (1)
src/Hooks.cpp (1)
1138-1151: Verification complete – memory patch addresses and byte sequences are correct
- src/Hooks.cpp (Lines 1138–1151):
REL::RelocationID(100565, 107300).address() + REL::Relocate(0x76, 0x71, 0x65)and the four-byte patches (0x41,0x83,0xE7,0x00/0x41,0x83,0xE4,0x00/0x90,0x90,0x90,0x90) match the patterns and usage ofREL::safe_writefound elsewhere (InteriorSunShadows, VR, VolumetricLighting).No inconsistencies detected—approving these changes.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Patches the game to only use worldspace lighting in BSLighting. This skips a lot of multiplication, checks and removes a lot of variables which should help reduce the total register usage and math used. As well as making the code simpler to understand.
Note that this breaks vanilla shaders completely. Using xbyak to hook the relevant code would be extremely messy.
Summary by CodeRabbit