Skip to content

feat(lut): add basic LUT support for testing#1129

Merged
doodlum merged 4 commits into
devfrom
lut
Jun 8, 2025
Merged

feat(lut): add basic LUT support for testing#1129
doodlum merged 4 commits into
devfrom
lut

Conversation

@doodlum
Copy link
Copy Markdown
Collaborator

@doodlum doodlum commented Jun 8, 2025

Summary by CodeRabbit

  • New Features
    • Added support for loading and binding a LUT (Lookup Table) DDS texture for enhanced image-space shader effects in deferred rendering.
    • Improved tonemapping by integrating LUT texture binding into cinematic HDR shader techniques.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 8, 2025

Walkthrough

Support for loading and binding a DDS LUT texture was added to the Deferred rendering system. A new method binds the LUT to the pixel shader. Two hooks were introduced to ensure the LUT is bound during specific image-space shader technique setups by intercepting virtual function calls.

Changes

File(s) Change Summary
src/Deferred.cpp Added LUT DDS texture loading, storage, and a BindLUT method for shader resource binding.
src/Deferred.h Declared lutTexture, BindLUT, and two hook structs for shader technique setup interception.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Deferred
    participant DirectXTex
    participant Shader

    App->>Deferred: SetupResources()
    Deferred->>DirectXTex: CreateDDSTextureFromFile(LUT.dds)
    DirectXTex-->>Deferred: Returns lutTexture
    Deferred->>Deferred: Store lutTexture

    App->>Shader: SetupTechnique()
    Shader->>Deferred: BindLUT()
    Deferred->>Shader: Bind lutTexture to pixel shader slot 100
Loading
sequenceDiagram
    participant App
    participant Shader
    participant Deferred

    App->>Shader: Call SetupTechnique()
    Shader->>Deferred: Hooks call BindLUT()
    Deferred->>Shader: Bind LUT texture if valid
    Shader->>App: Continue original SetupTechnique()
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Pentalimbed
Copy link
Copy Markdown
Collaborator

Why in deferred?

@doodlum
Copy link
Copy Markdown
Collaborator Author

doodlum commented Jun 8, 2025

Why in deferred?

No reason. I am only making this PR so that when me and Bottle test things we can test on any CS build. If it's effectively test code I don't know that it matters where it goes. I could just add comments to mark that it's all test code?

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 (3)
src/Deferred.cpp (2)

181-181: Consider making the LUT file path configurable.

The hardcoded path "Data\\Shaders\\LUT.dds" limits flexibility for testing different LUT files. Since this is marked as testing code, consider making the path configurable through a setting or command line parameter.


728-728: Clarify the lifecycle of this testing code.

Since this is explicitly marked as "Testing code for imagespace shaders", consider adding documentation about when this code should be removed or converted to production code.

Add a comment clarifying the testing nature:

-// Testing code for imagespace shaders
+// Testing code for imagespace shaders - TODO: Remove or convert to configurable feature
src/Deferred.h (1)

133-151: Consider the scope limitation of targeting specific shaders.

The hooks only target BSImagespaceShaderHDRTonemapBlendCinematic and BSImagespaceShaderHDRTonemapBlendCinematicFade. This limits LUT usage to these specific shaders. If broader LUT support is desired in the future, you might need to hook additional shader types or use a more general approach.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 324a1fd and 0883e9f.

📒 Files selected for processing (2)
  • src/Deferred.cpp (3 hunks)
  • src/Deferred.h (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build plugin and addons
🔇 Additional comments (5)
src/Deferred.cpp (2)

3-3: Header inclusion looks good.

The DDSTextureLoader.h include is appropriate for the DDS texture loading functionality being added.


728-734: LUT binding implementation looks correct.

The null check and binding to slot 100 is appropriate. Slot 100 is high enough to avoid conflicts with typical shader resource bindings.

src/Deferred.h (3)

80-81: Member declarations look appropriate.

The winrt::com_ptr<ID3D11ShaderResourceView> type is correct for managing D3D11 shader resource views, and the BindLUT() method declaration is properly placed.


133-151: Hook implementations follow established patterns.

The hook structures correctly call BindLUT() before invoking the original function, which ensures the LUT is bound when these specific imagespace shaders are set up.


168-169:

Details

✅ Verification successful

Verify the vtable function index.

The hooks are installed at vtable index 0x2. Please verify that this corresponds to the SetupTechnique method in both BSImagespaceShaderHDRTonemapBlendCinematic and BSImagespaceShaderHDRTonemapBlendCinematicFade vtables.


🏁 Script executed:

#!/bin/bash
# Description: Search for SetupTechnique method usage and vtable references
# Expected: Find references to SetupTechnique method and verify vtable index usage

echo "Searching for SetupTechnique method references..."
rg -A 3 -B 3 "SetupTechnique"

echo -e "\nSearching for other vtable hooks with index 0x2..."
rg -A 2 -B 2 "write_vfunc.*0x2"

Length of output: 5666


Vtable index 0x2 correctly corresponds to SetupTechnique

Both BSImagespaceShaderHDRTonemapBlendCinematic and its Fade variant inherit from RE::BSShader, where
• ~BSShader() … // 00
• virtual bool SetupTechnique(…) = 0; // 02

The hooks in Deferred.h use stl::write_vfunc<0x2, …SetupTechnique>—exactly the same index used elsewhere (e.g. BSGrassShader_SetupTechnique). No adjustment is needed.

Comment thread src/Deferred.cpp
Comment on lines +180 to +186

// Testing code for imagespace shaders
{
auto device = globals::d3d::device;
auto context = globals::d3d::context;
DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\LUT.dds", nullptr, lutTexture.put());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for LUT file loading.

The hardcoded path and lack of error handling could cause issues if the LUT file doesn't exist or fails to load.

Consider adding proper error handling:

 // Testing code for imagespace shaders
 {
     auto device = globals::d3d::device;
     auto context = globals::d3d::context;
-    DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\LUT.dds", nullptr, lutTexture.put());
+    auto hr = DirectX::CreateDDSTextureFromFile(device, context, L"Data\\Shaders\\LUT.dds", nullptr, lutTexture.put());
+    if (FAILED(hr)) {
+        logger::warn("Failed to load LUT texture: Data\\Shaders\\LUT.dds (HRESULT: 0x{:08X})", static_cast<uint32_t>(hr));
+        lutTexture = nullptr;
+    }
 }
🤖 Prompt for AI Agents
In src/Deferred.cpp around lines 180 to 186, the code loads a LUT texture from a
hardcoded path without checking for errors, which can cause issues if the file
is missing or fails to load. Modify the code to capture the HRESULT returned by
CreateDDSTextureFromFile and check if the operation succeeded. If it fails, log
an appropriate error message or handle the failure gracefully to prevent silent
errors.

@doodlum doodlum changed the title feat(lut): add basic LUT support feat(lut): add basic LUT support for testing Jun 8, 2025
@doodlum doodlum merged commit 2bd216d into dev Jun 8, 2025
11 of 12 checks passed
soda3000 pushed a commit to soda3000/skyrim-community-shaders that referenced this pull request Jun 8, 2025
* chore: lut

* fix: do not bind if invalid texture

* chore: add testing code comments
davo0411 pushed a commit to davo0411/skyrim-community-shaders that referenced this pull request Jun 21, 2025
* chore: lut

* fix: do not bind if invalid texture

* chore: add testing code comments
alandtse pushed a commit to alandtse/open-shaders that referenced this pull request Jul 20, 2025
* chore: lut

* fix: do not bind if invalid texture

* chore: add testing code comments
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