ComfyUI Extension: Advanced_Relight_Img

Authored by tritant

Created

Updated

0 stars

A custom node for ComfyUI that provides advanced 2D relighting capabilities.

Custom Nodes (0)

    README

    Advanced Relight Node

    A custom node for ComfyUI that provides advanced 2D relighting capabilities. It uses a normal map and a depth map to simulate 3D lighting effects on a source image, with support for multiple configurable light sources.

    https://github.com/user-attachments/assets/6859bfee-5ba2-486e-b868-4727358ddb58

    Interactive Preview

    This node features an interactive preview slider that allows you to adjust light positions in real-time.

    Important: Due to the way ComfyUI processes data, the preview of your input image will only appear in the slider after you have run the workflow at least once.

    To achieve this, the node starts a dedicated local preview server. This is a necessary workaround to bypass issues in some ComfyUI environments where the standard preview API does not work reliably. This server is highly secure: it is only accessible from your own computer (127.0.0.1), can only read the single preview image from the temporary folder, and has no permission to write or access any other files.

    Parameters

    The node is divided into several sections for clarity.

    Main Inputs

    • image (IMAGE): The source image to be relit.
    • normal_map (IMAGE): The normal map corresponding to the source image. This map provides directional lighting information.
    • depth_map (IMAGE): The depth map for the image. This is used to create a 3D parallax effect for the lighting.
    • mask (MASK): An optional mask input. When mask_enabled is on, a "virtual dome" normal map is generated from this mask and blended with the main lighting.

    Global Lighting Controls

    • preserve_color (BOOLEAN): If true, the node will only affect the luminosity of the original image, preserving its original hues and saturation.
    • ambient_light (FLOAT): Sets the base light level for the entire scene. Can be set to negative values to darken shadows instead of just adding light.
    • gamma (FLOAT): Controls the falloff curve of the light. Higher values result in sharper, more focused highlights, while lower values create a softer, broader light.
    • light_color (STRING): Sets the color (in hex format, e.g., #FFFFFF) for all active light sources.
    • depth_scale (FLOAT): A multiplier for the depth map's effect. Higher values create a more pronounced 3D effect, making the light appear to shift more as it moves.
    • median_filter_size (INT): Applies a median blur to the final computed light map. This is useful for reducing noise and smoothing out gradients. A value of 1 disables the filter.
    • dithering_strength (FLOAT): Adds a small amount of noise to the final image to help reduce color banding in smooth gradients.

    Masking Controls (Virtual Normals)

    These controls are only active when a mask is provided and mask_enabled is checked.

    • mask_enabled (BOOLEAN): Activates the lighting effect generated from the mask input.
    • brush_intensity (FLOAT): Controls the opacity or blend strength of the mask's lighting effect when it's combined with the main lighting from the normal map.
    • brush_softness (FLOAT): Controls the feathering (blur) applied to the edge of the mask before blending, creating a softer transition.
    • mask_intensity_mult (FLOAT): A dedicated multiplier for light intensity that applies only to the effect generated by the mask's virtual normals.
    • mask_gamma_mult (FLOAT): A dedicated multiplier for the gamma that applies only to the effect generated by the mask's virtual normals.

    Light Controls (1 & 2)

    Parameters are identical for Light 1 and Light 2.

    • enable_light_2 (BOOLEAN): Toggles the second light source on or off.
    • light_type_1/2 (COMBO): Sets the light source shape.
      • Point: An omnidirectional light source.
      • Neon: A linear light source (a line).
    • light_z_1/2 (FLOAT): Controls the perceived distance of the light from the image surface (the Z-axis). Lower values bring it closer, making highlights smaller and sharper.
    • intensity_1/2 (FLOAT): The brightness of the light source.
    • point_size_1/2 (FLOAT): (For Point lights only) This value controls both the lighting calculation in the backend and the visual halo effect in the interactive preview slider. It simulates a larger light source area, making the light "softer" and less harsh.
    • neon_length_1/2 (FLOAT): (For Neon lights only) Controls the length of the line source.
    • neon_angle_1/2 (FLOAT): (For Neon lights only) Controls the rotation of the line source.

    Debugging

    • debug_view (COMBO): Allows you to output intermediate stages of the process instead of the final image. This is useful for troubleshooting and understanding how the lighting is constructed. Options include Lighting Map Only, Mask Lighting Only, Mask Virtual Normals, etc.