@@ -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
425443def  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 )
0 commit comments