Skip to content

Commit 5ec3106

Browse files
committed
math node: add Square root option
1 parent df67c7b commit 5ec3106

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

nodes/textures/math.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
1: ["Increment", True],
3737
2: ["", False]
3838
},
39+
"sqrt": {
40+
0: ["Value", True],
41+
1: ["", False],
42+
2: ["", False]
43+
},
3944
}
4045

4146

@@ -70,6 +75,7 @@ def change_mode(self, context):
7075
("greaterthan", "Greater Than", "Value 1 > Value 2 (returns 0 if false, 1 if true)", 9),
7176
("rounding", "Round", "Round the input to the nearest increment", 10),
7277
("modulo", "Modulo", "Return the remainder of the floating point division Value 1 / Value 2", 11),
78+
("sqrt", "Square Root", "Square root", 12),
7379
]
7480
mode: EnumProperty(name="Mode", items=mode_items, default="scale", update=change_mode)
7581

@@ -107,9 +113,16 @@ def draw_buttons(self, context, layout):
107113
layout.label(text="Min should be smaller than max!", icon=icons.WARNING)
108114

109115
def sub_export(self, exporter, depsgraph, props, luxcore_name=None, output_socket=None):
110-
definitions = {
111-
"type": self.mode,
112-
}
116+
if self.mode == 'sqrt':
117+
# Square-root added as explicit option rather than the non-obvious power-0.5 combo.
118+
# Export as an alias to power because there is no dedicated implementation in LuxCore (yet).
119+
definitions = {
120+
"type": "power",
121+
}
122+
else:
123+
definitions = {
124+
"type": self.mode,
125+
}
113126

114127
if self.mode == "abs":
115128
definitions["texture"] = self.inputs[0].export(exporter, depsgraph, props)
@@ -130,6 +143,9 @@ def sub_export(self, exporter, depsgraph, props, luxcore_name=None, output_socke
130143
elif self.mode == "modulo":
131144
definitions["texture"] = self.inputs[0].export(exporter, depsgraph, props)
132145
definitions["modulo"] = self.inputs[1].export(exporter, depsgraph, props)
146+
elif self.mode == "sqrt":
147+
definitions["base"] = self.inputs[0].export(exporter, depsgraph, props)
148+
definitions["exponent"] = 0.5
133149
else:
134150
definitions["texture1"] = self.inputs[0].export(exporter, depsgraph, props)
135151
definitions["texture2"] = self.inputs[1].export(exporter, depsgraph, props)

0 commit comments

Comments
 (0)