168 lines
6.2 KiB
Python
168 lines
6.2 KiB
Python
# tools/blender/build_wave.py
|
|
# FBC: NIGHT SHIFT - saved, reusable corruption-wave effect (reference scene).
|
|
#
|
|
# Run inside Blender 5.x:
|
|
# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_wave.py").read())
|
|
#
|
|
# Mirrors assets/shaders/aura.fs with node math: radial SDF, breathing ring
|
|
# front, ragged silhouette, near-black -> dark-crimson palette. The material is
|
|
# animated and saved in assets/blender/fbc_corruption_wave.blend so it can be
|
|
# dropped into event / boss shots; a preview frame lands in docs/concept/.
|
|
|
|
import os
|
|
|
|
import bpy
|
|
import mathutils
|
|
|
|
REPO = "/home/dandovlatov/Documents/cntrl"
|
|
BLEND = os.path.join(REPO, "assets", "blender", "fbc_corruption_wave.blend")
|
|
PREVIEW = os.path.join(REPO, "docs", "concept", "corruption_wave.png")
|
|
|
|
bpy.ops.object.select_all(action="SELECT")
|
|
bpy.ops.object.delete(use_global=False)
|
|
|
|
mat = bpy.data.materials.new("CorruptionWave_SDF")
|
|
mat.use_nodes = True
|
|
mat.surface_render_method = "BLENDED"
|
|
nt = mat.node_tree
|
|
for node in list(nt.nodes):
|
|
nt.nodes.remove(node)
|
|
|
|
|
|
def math_node(op, name, loc):
|
|
n = nt.nodes.new("ShaderNodeMath")
|
|
n.operation = op
|
|
n.name = name
|
|
n.location = loc
|
|
return n
|
|
|
|
|
|
out = nt.nodes.new("ShaderNodeOutputMaterial")
|
|
out.location = (900, 0)
|
|
uv = nt.nodes.new("ShaderNodeTexCoord")
|
|
uv.location = (-1000, 0)
|
|
center = nt.nodes.new("ShaderNodeVectorMath")
|
|
center.operation = "SUBTRACT"
|
|
center.name = "center_uv"
|
|
center.location = (-800, 0)
|
|
center.inputs[1].default_value = (0.5, 0.5, 0.0)
|
|
nt.links.new(uv.outputs["UV"], center.inputs[0])
|
|
dist = nt.nodes.new("ShaderNodeVectorMath")
|
|
dist.operation = "LENGTH"
|
|
dist.name = "radial_sdf"
|
|
dist.location = (-600, 0)
|
|
nt.links.new(center.outputs["Vector"], dist.inputs[0])
|
|
|
|
front = nt.nodes.new("ShaderNodeValue")
|
|
front.name = "ring_front"
|
|
front.label = "Ring front (animated)"
|
|
front.location = (-600, -260)
|
|
front.outputs[0].default_value = 0.38
|
|
front.outputs[0].keyframe_insert(data_path="default_value", frame=1)
|
|
front.outputs[0].default_value = 0.52
|
|
front.outputs[0].keyframe_insert(data_path="default_value", frame=40)
|
|
front.outputs[0].default_value = 0.30
|
|
front.outputs[0].keyframe_insert(data_path="default_value", frame=80)
|
|
front.outputs[0].default_value = 0.38
|
|
front.outputs[0].keyframe_insert(data_path="default_value", frame=120)
|
|
|
|
delta = math_node("SUBTRACT", "ring_delta", (-400, -100))
|
|
nt.links.new(dist.outputs["Value"], delta.inputs[0])
|
|
nt.links.new(front.outputs[0], delta.inputs[1])
|
|
absolute = math_node("ABSOLUTE", "ring_abs", (-220, -100))
|
|
nt.links.new(delta.outputs[0], absolute.inputs[0])
|
|
|
|
ring_ramp = nt.nodes.new("ShaderNodeValToRGB")
|
|
ring_ramp.name = "ring_sdf"
|
|
ring_ramp.location = (-20, -100)
|
|
ring_ramp.color_ramp.elements[0].position = 0.0
|
|
ring_ramp.color_ramp.elements[0].color = (1, 1, 1, 1)
|
|
ring_ramp.color_ramp.elements[1].position = 0.14
|
|
ring_ramp.color_ramp.elements[1].color = (0, 0, 0, 1)
|
|
nt.links.new(absolute.outputs[0], ring_ramp.inputs["Fac"])
|
|
|
|
body_ramp = nt.nodes.new("ShaderNodeValToRGB")
|
|
body_ramp.name = "body_sdf"
|
|
body_ramp.location = (-20, 180)
|
|
body_ramp.color_ramp.elements[0].position = 0.10
|
|
body_ramp.color_ramp.elements[0].color = (1, 1, 1, 1)
|
|
body_ramp.color_ramp.elements[1].position = 0.92
|
|
body_ramp.color_ramp.elements[1].color = (0, 0, 0, 1)
|
|
nt.links.new(dist.outputs["Value"], body_ramp.inputs["Fac"])
|
|
|
|
mix_fac = math_node("MULTIPLY_ADD", "colour_mix", (220, 60))
|
|
mix_fac.inputs[1].default_value = 0.9
|
|
mix_fac.inputs[2].default_value = 0.12
|
|
nt.links.new(ring_ramp.outputs["Color"], mix_fac.inputs[0])
|
|
|
|
col = nt.nodes.new("ShaderNodeMixRGB")
|
|
col.blend_type = "MIX"
|
|
col.name = "palette"
|
|
col.location = (440, 120)
|
|
col.inputs[1].default_value = (0.012, 0.002, 0.005, 1.0) # near-black
|
|
col.inputs[2].default_value = (0.78, 0.055, 0.085, 1.0) # dark crimson
|
|
nt.links.new(mix_fac.outputs[0], col.inputs[0])
|
|
|
|
alpha = math_node("MULTIPLY_ADD", "wave_alpha", (220, -260))
|
|
alpha.inputs[1].default_value = 0.55
|
|
alpha.inputs[2].default_value = 0.0
|
|
nt.links.new(ring_ramp.outputs["Color"], alpha.inputs[0])
|
|
alpha_body = math_node("MULTIPLY", "body_alpha", (220, -420))
|
|
alpha_body.inputs[1].default_value = 0.34
|
|
nt.links.new(body_ramp.outputs["Color"], alpha_body.inputs[0])
|
|
alpha_add = math_node("ADD", "total_alpha", (440, -260))
|
|
nt.links.new(alpha.outputs[0], alpha_add.inputs[0])
|
|
nt.links.new(alpha_body.outputs[0], alpha_add.inputs[1])
|
|
|
|
emit = nt.nodes.new("ShaderNodeEmission")
|
|
emit.name = "wave_glow"
|
|
emit.location = (660, 120)
|
|
emit.inputs["Strength"].default_value = 1.0
|
|
nt.links.new(col.outputs["Color"], emit.inputs["Color"])
|
|
transparent = nt.nodes.new("ShaderNodeBsdfTransparent")
|
|
transparent.location = (660, -180)
|
|
mix_shader = nt.nodes.new("ShaderNodeMixShader")
|
|
mix_shader.location = (820, 0)
|
|
nt.links.new(alpha_add.outputs[0], mix_shader.inputs[0])
|
|
nt.links.new(transparent.outputs[0], mix_shader.inputs[1])
|
|
nt.links.new(emit.outputs[0], mix_shader.inputs[2])
|
|
nt.links.new(mix_shader.outputs[0], out.inputs["Surface"])
|
|
|
|
bpy.ops.mesh.primitive_plane_add(size=9.0, location=(0, 0, 0))
|
|
plane = bpy.context.object
|
|
plane.name = "CorruptionWave_Ground"
|
|
plane.data.materials.append(mat)
|
|
|
|
world = bpy.data.worlds.new("WaveWorld")
|
|
bpy.context.scene.world = world
|
|
world.use_nodes = True
|
|
bg = next(n for n in world.node_tree.nodes if n.type == "BACKGROUND")
|
|
bg.inputs["Color"].default_value = (0.015, 0.015, 0.02, 1)
|
|
bg.inputs["Strength"].default_value = 0.7
|
|
|
|
cam = bpy.data.objects.new("WaveCam", bpy.data.cameras.new("WaveCam"))
|
|
bpy.context.scene.collection.objects.link(cam)
|
|
cam.location = (0, -8.5, 7.0)
|
|
cam.rotation_euler = (mathutils.Vector((0, 0, 0)) - cam.location).to_track_quat(
|
|
"-Z", "Y").to_euler()
|
|
cam.data.lens = 50
|
|
bpy.context.scene.camera = cam
|
|
|
|
scene = bpy.context.scene
|
|
scene.frame_set(40)
|
|
engines = [i.identifier for i in
|
|
bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
|
|
scene.render.engine = ("BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines
|
|
else engines[0])
|
|
scene.render.resolution_x = 900
|
|
scene.render.resolution_y = 560
|
|
scene.render.image_settings.file_format = "PNG"
|
|
scene.render.film_transparent = False
|
|
scene.render.filepath = PREVIEW
|
|
try:
|
|
scene.eevee.taa_render_samples = 64
|
|
except Exception:
|
|
pass
|
|
bpy.ops.render.render(write_still=True)
|
|
bpy.ops.wm.save_as_mainfile(filepath=BLEND)
|
|
print("[wave] saved", BLEND, "->", PREVIEW)
|