55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
# tools/blender/build_lut.py
|
|
# FBC: NIGHT SHIFT — stylised lighting ramp (S9 look-dev).
|
|
#
|
|
# Run inside Blender 5.x:
|
|
# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_lut.py").read())
|
|
#
|
|
# Generates the one-dimensional gradient map sampled by assets/shaders/actor.fs.
|
|
# Shadow stops are cool blue-grey, highlights warm pale — Risk of Rain 2's
|
|
# gradient-map shading in the Control palette. Kept as a generated image so the
|
|
# ramp is version-controlled and reproducible from this script.
|
|
|
|
import os
|
|
|
|
import bpy
|
|
import numpy as np
|
|
|
|
REPO = "/home/dandovlatov/Documents/cntrl"
|
|
OUT_DIR = os.path.join(REPO, "assets", "textures", "actor")
|
|
os.makedirs(OUT_DIR, exist_ok=True)
|
|
OUT = os.path.join(OUT_DIR, "actor_ramp.png")
|
|
|
|
WIDTH = 256
|
|
HEIGHT = 4
|
|
|
|
# (position, linear RGB in 0..1 — the shader multiplies by 1.7 to recover the
|
|
# linear highlight range without needing a 16-bit texture).
|
|
STOPS = [
|
|
(0.00, (0.310, 0.330, 0.380)),
|
|
(0.28, (0.420, 0.430, 0.465)),
|
|
(0.55, (0.560, 0.560, 0.565)),
|
|
(0.78, (0.750, 0.730, 0.690)),
|
|
(1.00, (0.960, 0.930, 0.870)),
|
|
]
|
|
|
|
t = np.linspace(0.0, 1.0, WIDTH, dtype=np.float32)
|
|
xs = np.array([s[0] for s in STOPS], dtype=np.float32)
|
|
row = np.stack([np.interp(t, xs, np.array([s[1][k] for s in STOPS],
|
|
dtype=np.float32)) for k in range(3)],
|
|
axis=1)
|
|
row = np.power(row, 1.08) # gentle shoulder separates the lit facets
|
|
|
|
# Blender's pixel buffer is row-major (y outer, x inner).
|
|
rgb = np.tile(row[None, :, :], (HEIGHT, 1, 1))
|
|
rgba = np.dstack([rgb, np.ones((HEIGHT, WIDTH), dtype=np.float32)])
|
|
|
|
img = bpy.data.images.new("actor_ramp", width=WIDTH, height=HEIGHT, alpha=True)
|
|
try:
|
|
img.colorspace_settings.name = "Non-Color"
|
|
except Exception:
|
|
pass
|
|
img.pixels.foreach_set(np.asarray(rgba, dtype=np.float32).ravel())
|
|
img.filepath_raw = OUT
|
|
img.file_format = "PNG"
|
|
img.save()
|
|
print("[lut] wrote %s (%dx%d)" % (OUT, WIDTH, HEIGHT))
|