Skip to content

Commit b262df6

Browse files
author
Lawrence D'Oliveiro
committed
Take grunge out of normal-map image and make it a procedural
parameter instead.
1 parent 1d8b519 commit b262df6

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name" : "Spaceship Generator",
44
"author" : "Michael Davies, Lawrence D'Oliveiro",
5-
"version" : (1, 3, 2),
5+
"version" : (1, 4, 0),
66
"blender" : (2, 82, 0),
77
"location" : "View3D > Add > Mesh",
88
"description" : "Procedurally generate 3D spaceships from a random seed.",
@@ -24,6 +24,7 @@
2424
import bpy.utils.previews
2525
from bpy.props import \
2626
BoolProperty, \
27+
FloatProperty, \
2728
IntProperty, \
2829
StringProperty
2930

@@ -90,7 +91,7 @@ class GenerateSpaceship(bpy.types.Operator) :
9091
allow_vertical_symmetry : BoolProperty \
9192
(
9293
default = df.allow_vertical_symmetry,
93-
name="Allow Vertical Symmetry"
94+
name = "Allow Vertical Symmetry"
9495
)
9596
add_bevel_modifier : BoolProperty \
9697
(
@@ -102,6 +103,13 @@ class GenerateSpaceship(bpy.types.Operator) :
102103
default = df.assign_materials,
103104
name = "Assign Materials"
104105
)
106+
grunge_factor : FloatProperty \
107+
(
108+
default = df.grunge_factor,
109+
min = 0,
110+
max = 1,
111+
name = "Material Grunge"
112+
)
105113
del df
106114

107115
def invoke(self, context, event) :

spaceship_generator.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class MATERIAL(IntEnum) :
224224
GLOW_DISC = 4 # Emissive landing pad disc material
225225
#end MATERIAL
226226

227-
def create_materials(mat_random) :
227+
def create_materials(parms, mat_random) :
228228
# Creates all our materials and returns them as a list.
229229

230230
def define_tex_coords_common() :
@@ -261,22 +261,39 @@ def define_normals_common() :
261261
# defines a node group for the normal-mapping texture to be used
262262
# across different hull materials.
263263
normals_common = bpy.data.node_groups.new("SpaceShip.NormalsCommon", "ShaderNodeTree")
264-
ctx = NodeContext(normals_common, (-300, 0))
264+
ctx = NodeContext(normals_common, (-500, 0))
265+
group_input = ctx.node("NodeGroupInput", ctx.step_across(200))
266+
normals_common.inputs.new("NodeSocketFloat", "Grunge")
267+
normals_common.inputs[0].default_value = parms.grunge_factor
268+
save1_pos = ctx.pos
265269
tex_out = create_texture \
266270
(
267271
ctx,
268272
filename = "hull_normal.png",
269273
use_alpha = True,
270274
is_color = False
271275
)
276+
save2_pos = ctx.pos
277+
ctx.pos = (save1_pos[0], ctx.pos[1])
278+
ctx.step_down(400)
279+
dirty = ctx.node("ShaderNodeTexNoise", ctx.step_across(200))
280+
dirty.inputs["Scale"].default_value = 10
281+
ctx.pos = save2_pos
282+
mix = ctx.node("ShaderNodeMixRGB", ctx.step_across(200))
283+
mix.blend_type = "MIX"
284+
#mix.inputs[0].default_value = 0.5
285+
ctx.link(group_input.outputs[0], mix.inputs[0])
286+
ctx.link(tex_out, mix.inputs[1])
287+
ctx.link(dirty.outputs[1], mix.inputs[2])
272288
normal_map = ctx.node("ShaderNodeNormalMap", ctx.step_across(200))
273-
ctx.link(tex_out, normal_map.inputs["Color"])
289+
ctx.link(mix.outputs[0], normal_map.inputs["Color"])
274290
normal_map.inputs["Strength"].default_value = 1
275291
group_output = ctx.node("NodeGroupOutput", ctx.step_across(200))
276292
normals_common.outputs.new("NodeSocketVector", "Normal")
277293
# work around intermittent crash on following line
278294
ctx.link(normal_map.outputs["Normal"], group_output.inputs[0])
279-
group_output.inputs[0].name = normals_common.outputs[0].name = "Normal"
295+
group_input.outputs[0].name = normals_common.inputs[0].name
296+
group_output.inputs[0].name = normals_common.outputs[0].name
280297
deselect_all(normals_common)
281298
return normals_common
282299
#end define_normals_common
@@ -420,6 +437,7 @@ class parms_defaults :
420437
allow_vertical_symmetry = False
421438
add_bevel_modifier = True
422439
assign_materials = True
440+
grunge_factor = 0.5
423441
#end parms_defaults
424442

425443
def generate_spaceship(parms) :
@@ -1089,7 +1107,7 @@ def add_disc_to_face(bm, face) :
10891107
if parms.mat_ranseed != "" :
10901108
mat_random.seed(parms.mat_ranseed)
10911109
#end if
1092-
materials = create_materials(mat_random)
1110+
materials = create_materials(parms, mat_random)
10931111
for mat in materials :
10941112
if parms.assign_materials :
10951113
me.materials.append(mat)

textures/hull_normal.png

-4.58 MB
Loading

0 commit comments

Comments
 (0)