Skip to content

Commit

Permalink
chore: shader constants
Browse files Browse the repository at this point in the history
  • Loading branch information
saturday06 committed Jun 8, 2024
1 parent 78c41a7 commit 8ab756c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/io_scene_vrm/common/shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,20 @@
OUTLINE_GEOMETRY_GROUP_NAME: Final = "VRM Add-on MToon 1.0 Outline Geometry Revision 1"

UV_GROUP_NAME: Final = "VRM Add-on MToon 1.0 UV Revision 1"

UV_ANIMATION_GROUP_NAME: Final = "VRM Add-on MToon 1.0 UV Animation Revision 1"

NORMAL_GROUP_NAME: Final = "VRM Add-on MToon 1.0 Normal Revision 1"
NORMAL_GROUP_SCALE_LABEL: Final = "Normal Map Texture Scale"

OUTPUT_GROUP_NAME: Final = "VRM Add-on MToon 1.0 Output Revision 1"
OUTPUT_GROUP_EMISSIVE_FACTOR_LABEL: Final = "Emissive Factor"
OUTPUT_GROUP_EMISSIVE_FACTOR_DEFAULT: Final = (0, 0, 0)
OUTPUT_GROUP_OUTLINE_COLOR_FACTOR_LABEL: Final = "Outline Color"
OUTPUT_GROUP_OUTLINE_COLOR_FACTOR_DEFAULT: Final = (0, 0, 0)
OUTPUT_GROUP_OUTLINE_WIDTH_FACTOR_LABEL: Final = "Outline Width"
OUTPUT_GROUP_PARAMETRIC_RIM_LIFT_FACTOR_LABEL: Final = "Parametric Rim Lift"
OUTPUT_GROUP_PARAMETRIC_RIM_LIFT_FACTOR_DEFAULT: Final = 1.0

SHADER_NODE_GROUP_NAMES: Final = (
UV_GROUP_NAME,
Expand Down
36 changes: 25 additions & 11 deletions src/io_scene_vrm/editor/mtoon1/property_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,11 @@ class Mtoon1NormalTextureInfoPropertyGroup(Mtoon1TextureInfoPropertyGroup):
)

def update_scale(self, _context: Context) -> None:
self.set_value(shader.NORMAL_GROUP_NAME, "Normal Map Texture Scale", self.scale)
self.set_value(
shader.NORMAL_GROUP_NAME,
shader.NORMAL_GROUP_SCALE_LABEL,
self.scale,
)
material = self.find_material()
principled_bsdf = PrincipledBSDFWrapper(material, is_readonly=False)
principled_bsdf.normalmap_strength = self.scale
Expand Down Expand Up @@ -2108,14 +2112,14 @@ def update_parametric_rim_fresnel_power_factor(self, _context: Context) -> None:
def update_parametric_rim_lift_factor(self, _context: Context) -> None:
self.set_value(
shader.OUTPUT_GROUP_NAME,
"Parametric Rim Lift",
shader.OUTPUT_GROUP_PARAMETRIC_RIM_LIFT_FACTOR_LABEL,
self.parametric_rim_lift_factor,
)

parametric_rim_lift_factor: FloatProperty( # type: ignore[valid-type]
name="Parametric Rim Lift",
name=shader.OUTPUT_GROUP_PARAMETRIC_RIM_LIFT_FACTOR_LABEL,
soft_min=0.0,
default=1.0,
default=shader.OUTPUT_GROUP_PARAMETRIC_RIM_LIFT_FACTOR_DEFAULT,
soft_max=1.0,
update=update_parametric_rim_lift_factor,
)
Expand Down Expand Up @@ -2149,12 +2153,14 @@ def update_outline_geometry(self, _context: Context) -> None:

def update_outline_width_factor(self, context: Context) -> None:
self.set_value(
shader.OUTPUT_GROUP_NAME, "Outline Width", self.outline_width_factor
shader.OUTPUT_GROUP_NAME,
shader.OUTPUT_GROUP_OUTLINE_WIDTH_FACTOR_LABEL,
self.outline_width_factor,
)
self.update_outline_geometry(context)

outline_width_factor: FloatProperty( # type: ignore[valid-type]
name="Outline Width",
name=shader.OUTPUT_GROUP_OUTLINE_WIDTH_FACTOR_LABEL,
min=0.0,
soft_max=0.05,
update=update_outline_width_factor,
Expand All @@ -2166,7 +2172,10 @@ def update_outline_width_factor(self, context: Context) -> None:

def update_outline_color_factor(self, context: Context) -> None:
self.set_rgb(
shader.OUTPUT_GROUP_NAME, "Outline Color", self.outline_color_factor
shader.OUTPUT_GROUP_NAME,
shader.OUTPUT_GROUP_OUTLINE_COLOR_FACTOR_LABEL,
self.outline_color_factor,
shader.OUTPUT_GROUP_OUTLINE_COLOR_FACTOR_DEFAULT,
)
self.update_outline_geometry(context)

Expand All @@ -2187,10 +2196,10 @@ def update_outline_color_factor(self, context: Context) -> None:
)

outline_color_factor: FloatVectorProperty( # type: ignore[valid-type]
name="Outline Color",
name=shader.OUTPUT_GROUP_OUTLINE_COLOR_FACTOR_LABEL,
size=3,
subtype="COLOR",
default=(0, 0, 0),
default=shader.OUTPUT_GROUP_OUTLINE_COLOR_FACTOR_DEFAULT,
min=0,
max=1,
update=update_outline_color_factor,
Expand Down Expand Up @@ -2501,7 +2510,12 @@ def set_alpha_cutoff(self, value: float) -> None:
)

def update_emissive_factor(self, _context: Context) -> None:
self.set_rgb(shader.OUTPUT_GROUP_NAME, "Emissive Factor", self.emissive_factor)
self.set_rgb(
shader.OUTPUT_GROUP_NAME,
shader.OUTPUT_GROUP_EMISSIVE_FACTOR_LABEL,
self.emissive_factor,
shader.OUTPUT_GROUP_EMISSIVE_FACTOR_DEFAULT,
)

material = self.find_material()
principled_bsdf = PrincipledBSDFWrapper(material, is_readonly=False)
Expand Down Expand Up @@ -2551,7 +2565,7 @@ def update_emissive_factor(self, _context: Context) -> None:
emissive_factor: FloatVectorProperty( # type: ignore[valid-type]
size=3,
subtype="COLOR",
default=(0, 0, 0),
default=shader.OUTPUT_GROUP_EMISSIVE_FACTOR_DEFAULT,
min=0,
max=1,
update=update_emissive_factor,
Expand Down

0 comments on commit 8ab756c

Please sign in to comment.