-
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97207db
commit 4906ba4
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
backend/src/packages/chaiNNer_standard/material_textures/normal_map/strengthen_normals.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
|
||
import navi | ||
from nodes.impl.normals.addition import AdditionMethod, strengthen_normals | ||
from nodes.impl.normals.util import xyz_to_bgr | ||
from nodes.properties.inputs import EnumInput, ImageInput, SliderInput | ||
from nodes.properties.outputs import ImageOutput | ||
|
||
from .. import normal_map_group | ||
|
||
|
||
@normal_map_group.register( | ||
schema_id="chainner:image:strengthen_normals", | ||
name="Strengthen Normals", | ||
description=[ | ||
"Strengths and weakens the normals in the given normal map. Only the R and G channels of the input image will be used. The output normal map is guaranteed to be normalized.", | ||
"Conceptually, this node is equivalent to `chainner:image:add_normals` with the strength of the second normal map set to 0.", | ||
], | ||
icon="MdExpand", | ||
inputs=[ | ||
ImageInput("Normal Map", channels=[3, 4]), | ||
SliderInput("Strength", maximum=400, default=100), | ||
EnumInput( | ||
AdditionMethod, | ||
label="Method", | ||
default=AdditionMethod.PARTIAL_DERIVATIVES, | ||
), | ||
], | ||
outputs=[ | ||
ImageOutput( | ||
"Normal Map", | ||
image_type=navi.Image(size_as="Input0"), | ||
channels=3, | ||
), | ||
], | ||
) | ||
def strengthen_normals_node( | ||
n: np.ndarray, strength: int, method: AdditionMethod | ||
) -> np.ndarray: | ||
return xyz_to_bgr(strengthen_normals(method, n, strength / 100)) |