Skip to content

feat(relight): add AI relighting panel with movable lights - #1854

Closed
fabian-co wants to merge 1 commit into
CyberTimon:mainfrom
fabian-co:feat/relight
Closed

fabian-co wants to merge 1 commit into
CyberTimon:mainfrom
fabian-co:feat/relight

Conversation

@fabian-co

@fabian-co fabian-co commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a Relight panel: you place up to six point lights on the photo and the image is re-lit from them, using AI-estimated normal and depth maps of the scene.

The maps come from MoGe-2 ONNX checkpoints, downloaded on first use and verified by SHA-256 the same way the other AI models are. They are generated once per image and cached, so moving lights and sliders afterwards is a normal adjustment with live preview.

Opened as a draft until I add screenshots / a short video of the panel.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Performance improvement
  • Code refactoring
  • Documentation update
  • UI/UX improvement
  • Build/CI or Dependency update

Changes Made

Backend (src-tauri)

  • relight.rs (new): the relight pass. Builds per-pixel surface maps (normal, coverage, depth, plus fine detail read from the photo's own texture), snaps them to the image edges with the guided filter already used by lens blur, and shades each pixel with diffuse + specular lighting, distance falloff, ambient level and softness.
  • ai_processing.rs: MoGe-2 loading and inference (run_normal_model), with two checkpoints: small (140 MB, default) and large (1.3 GB, sharper, about 3x slower).
  • ai_commands.rs: generate_relight_maps and generate_relight_normal_preview commands. Maps are cached on disk per image and quality (capped at 60 files).
  • Relight runs right before lens blur everywhere lens blur is applied (lib.rs, adjustment_utils.rs, file_management.rs), and its settings are part of the preview cache key (cache_utils.rs).
  • lens_blur.rs: the luma guide and guided-filter helpers are now pub(crate) so relight can reuse them. No behaviour change for lens blur.

Frontend (src)

  • RelightPanel.tsx (new) and a new entry in the panel switcher: enable switch, light list (add / remove / select), per-light intensity, depth, range and colour (Kelvin presets or custom), global ambient, softness, specular and detail, map quality, and an option to show the normal map over the image.
  • RelightHandle.tsx (new) + ImageCanvas.tsx: each light is a handle on the canvas; drag to move it, scroll to push it closer or farther.
  • adjustments.ts, relightUtils.ts, stores: the new adjustment keys, defaults and geometry helpers. Relight settings are saved in the sidecar like any other adjustment.
  • Translations for all 15 locales.

Screenshots/Videos

To be added before marking this ready for review.

Testing

  • These changes were tested locally by a human and confirmed to work.
  • I haven't added any automated tests to the code because the codebase currently lacks a test suite.

This PR does add unit tests (21, in relight.rs, ai_processing.rs and ai_commands.rs).

Test Configuration:

  • OS: Windows 10
  • Hardware: Nvidia RTX 3060 (12 GB)

Checklist

  • My code follows the project's code style
  • I haven't added unnecessary AI-generated code comments
  • My changes generate no new warnings or errors

Additional Notes

  • Checked locally on this branch, rebased on current main: cargo fmt -- --check and cargo clippy --all-targets -- -D warnings pass (without --all-features, since tethering needs libgphoto2, which I don't have on Windows); tsc reports no new errors; ESLint and Prettier are clean on the touched files; npm run i18n:check gives the same output as on main.
  • Only tested on Windows with an Nvidia GPU. macOS, Linux and Android are untested.
  • The Czech and Dutch strings were machine-translated (those locales were added after the feature was written) and would benefit from a native speaker's review.
  • The MoGe-2 checkpoints are fetched from the Ruicheng/moge-2-*-normal-onnx Hugging Face repositories, pinned to a revision. Happy to switch to a mirror under CyberTimon/RapidRAW-Models if you prefer to host them there like the other models.

AI Disclaimer:

Please state the involvement of AI in this PR:

  • This PR is created by an AI agent
  • This PR is mostly AI-generated but edited/merged together by a human
  • This PR was handwritten with AI assistance (spell check, logic suggestions, error resolving)
  • This PR contains only blood, sweat, and coffee (AI-free)

BEFORE
image

AFTER
image

Adds a Relight panel that lights the photo with up to six point lights placed
on the image. Normal and depth maps come from MoGe-2 (small or large ONNX
checkpoint, downloaded on first use like the other AI models) and are cached
per image. The relight pass runs before lens blur in the preview, export and
thumbnail pipelines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dwb4HkWbxjkmwpshwXd2zi
@fabian-co
fabian-co marked this pull request as ready for review October 6, 2026 14:51
@fabian-co
fabian-co requested a review from CyberTimon as a code owner October 6, 2026 14:51
@shsmad

shsmad commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@fabian-co looks great! for how long is relighting operation runs on your rtx?

@CyberTimon

Copy link
Copy Markdown
Owner

Looks very nice! Have you thought about integrating it behind a toggle in the main adjustments panel, like AI lens blur?

@fabian-co

Copy link
Copy Markdown
Contributor Author

@fabian-co looks great! for how long is relighting operation runs on your rtx?

Thank you! I have a rtx 3060 and take 1 minute or less depend if you use basic o high model to create a normal map, you can switch to both and works good!

@fabian-co

Copy link
Copy Markdown
Contributor Author

Looks very nice! Have you thought about integrating it behind a toggle in the main adjustments panel, like AI lens blur?

Thank you! Yes initially the effect was integrated in's effects panel, but then I thought that can be better under presets panel, because relight has many options to configure

@mmadesignerunknown

Copy link
Copy Markdown
Contributor

Looks very nice! Have you thought about integrating it behind a toggle in the main adjustments panel, like AI lens blur?

Thank you! Yes initially the effect was integrated in's effects panel, but then I thought that can be better under presets panel, because relight has many options to configure

+1, great work @fabian-co !, if possible can you please share a video of this new tool :)

Regards,

@fabian-co

Copy link
Copy Markdown
Contributor Author

u pleas

Sure, my English is a bit basic, but I can give it a try.

@fabian-co

Copy link
Copy Markdown
Contributor Author

Looks very nice! Have you thought about integrating it behind a toggle in the main adjustments panel, like AI lens blur?

Thank you! Yes initially the effect was integrated in's effects panel, but then I thought that can be better under presets panel, because relight has many options to configure

+1, great work @fabian-co !, if possible can you please share a video of this new tool :)

Regards,

Relight normal map models

The Relight normal map is generated with MoGe-2 (Ruicheng Wang / Microsoft), run as an ONNX model. There are two variants, selected by quality and defined in src-tauri/src/ai_processing.rs (NormalModelQuality::spec):

Quality Model Local file Hugging Face repo
Standard (default) MoGe-2 ViT-S normal (141 MB) moge2_vits_normal.onnx Ruicheng/moge-2-vits-normal-onnx
High MoGe-2 ViT-L normal (1.3 GB) moge2_vitl_normal.onnx Ruicheng/moge-2-vitl-normal-onnx

Both checkpoints take the same inputs and return the same outputs, so they are interchangeable. The large one resolves much finer geometry but is far heavier.

Relight.Example.10MB.mp4

I hope that with the video I have explained well.

@CyberTimon

Copy link
Copy Markdown
Owner

@fabian-co Thanks a lot for creating this showcase :)

@mmadesignerunknown

Copy link
Copy Markdown
Contributor
Relight.Example.10MB.mp4

I hope that with the video I have explained well.

Thanks for the great explanation @fabian-co !

Just some minor UI suggestions from ky side:

  • There shouldn't be a toggle inside the new Relight Panel to turn it on (I mean the relight panel should display the same things it displays with switch on condition but without the toggle, and there shouldn't be any switch off situation)

  • Ability to make duplicates of lights with same color.

  • Ability to add custom colors as "swatches".

Your thoughts on this are more than appreciated. :)

Regards,

@mmadesignerunknown

Copy link
Copy Markdown
Contributor

And one more thing, why not use the latest and more polished MoGe-3 model.

Regards,

@CyberTimon

Copy link
Copy Markdown
Owner

Hi @fabian-co,

Thank you so much for this PR and the great video demo! Your work proved that AI relighting works really well in RapidRAW.

I wanted this feature to live inside the existing Effects panel to keep the UI simpler and more streamlined. Making those changes required a very different structure across the UI, canvas, and backend, so I decided to implement it directly on main instead of asking you to rewrite everything.

I am sorry for not merging your branch directly after all the work you put into it.

Here is a quick overview of what I changed compared to your PR:

  • UI Placement: I put it inside the Effects section instead of creating a new separate panel.
  • Canvas Controls: I built the light handles directly into our canvas engine (Konva).
  • Light Types: In addition to point lights, I added spot lights (with cone size and feather) and directional lights (with angle and elevation).
  • Shadows: I added cast shadows with an adjustable softness slider.
  • Color Controls: I added temperature and tint sliders for each individual light, plus color swatches.
  • Model and Speed: I used a single model hosted on my own repository and packed both normals and depth into one image, which makes it faster and lighter on memory.
image

Please pull main and try it out when you have time. Since you know this feature so well, I would really love to hear your feedback on how it runs on your machine!

Thank you again for your contribution!

Timon

@CyberTimon CyberTimon closed this Oct 7, 2026
@CyberTimon

Copy link
Copy Markdown
Owner

And one more thing, why not use the latest and more polished MoGe-3 model.

@mmadesignerunknown It's too large :/

@mmadesignerunknown

Copy link
Copy Markdown
Contributor

And one more thing, why not use the latest and more polished MoGe-3 model.

@mmadesignerunknown It's too large :/

Sad... Anyways...

Thanks for implementing this, if possible, can you please consider these suggestions as I described.

  • Ability to duplicate lights with same color and settings (so it's easier and faster to use same lights in different places)

  • Ability to add custom colors as permanent swatches (so you don't have to type/drag-and-adjust the color you use frequently on each new light everytime)

Regards,

@fabian-co

Copy link
Copy Markdown
Contributor Author

Hi @fabian-co,

Thank you so much for this PR and the great video demo! Your work proved that AI relighting works really well in RapidRAW.

I wanted this feature to live inside the existing Effects panel to keep the UI simpler and more streamlined. Making those changes required a very different structure across the UI, canvas, and backend, so I decided to implement it directly on main instead of asking you to rewrite everything.

I am sorry for not merging your branch directly after all the work you put into it.

Here is a quick overview of what I changed compared to your PR:

  • UI Placement: I put it inside the Effects section instead of creating a new separate panel.
  • Canvas Controls: I built the light handles directly into our canvas engine (Konva).
  • Light Types: In addition to point lights, I added spot lights (with cone size and feather) and directional lights (with angle and elevation).
  • Shadows: I added cast shadows with an adjustable softness slider.
  • Color Controls: I added temperature and tint sliders for each individual light, plus color swatches.
  • Model and Speed: I used a single model hosted on my own repository and packed both normals and depth into one image, which makes it faster and lighter on memory.
image Please pull main and try it out when you have time. Since you know this feature so well, I would really love to hear your feedback on how it runs on your machine!

Thank you again for your contribution!

Timon

Hi Timon,

Thanks for the update! No worries at all about not merging the PR directly—I totally understand needing to fit it properly into the Effects panel and the existing architecture. It makes perfect sense.

The additions you made sound awesome, especially the spot lights, shadows, and the model optimization. It looks like a huge step up!

I’ll pull main soon, play around with it, and let you know how it runs on my end. Really glad my initial work helped kickstart this feature!

Cheers,
Fabian

@CyberTimon

Copy link
Copy Markdown
Owner

Thanks a lot for the response. Looking forward to your testing :)

@fabian-co
fabian-co deleted the feat/relight branch October 7, 2026 14:18
@fabian-co

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the response. Looking forward to your testing :)

I checked religth and it's amazing the new features that you added, now I send a new pr whit improves for spot and directional light you can see in this url #1865

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.

4 participants