Datasets:
Add code
Browse files- code/post/cond_v9.py +109 -0
- code/post/export_v6.py +93 -0
- code/post/post_v10_pool.py +67 -0
- code/ue_capture/PipelineCaptureV10.cpp +284 -0
- code/ue_capture/PipelineCaptureV10Real.cpp +695 -0
- code/ue_capture/PipelineCaptureV9.cpp +416 -0
- code/ue_capture/run_all_v10.ps1 +54 -0
- code/ue_capture/run_all_v9.ps1 +50 -0
- code/ue_capture/v10_masters4.py +84 -0
code/post/cond_v9.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""v9 condition images. For every frame of a run: cond.png = semantic palette for the scene classes, and the player / boss
|
| 2 |
+
(class 10 / 11, capsules in the v9 labels) shaded by code from the per-frame capsule segments, tinted per role.
|
| 3 |
+
usage: cond_v9.py RUN_DIR [--preview OUT.mp4 SECONDS] [--every N]"""
|
| 4 |
+
import os, sys, glob, json, subprocess, shutil
|
| 5 |
+
import numpy as np
|
| 6 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 7 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
+
PAL = np.array([[18, 20, 26], [122, 156, 92], [196, 186, 160], [182, 98, 72], [128, 120, 132], [52, 128, 60], [214, 168, 52]] + [[0, 0, 0]] * 3 +
|
| 9 |
+
[[80, 150, 255], [255, 80, 70]] + [[255, 0, 255]] * 244, np.uint8)
|
| 10 |
+
TINT = {10: np.array([0.62, 0.80, 1.0]), 11: np.array([1.0, 0.66, 0.60])}
|
| 11 |
+
SIDE = {'l_': 0.80, 'r_': 1.0}
|
| 12 |
+
def cap_hit(ro, rd, a, b, r):
|
| 13 |
+
"""ray / capsule intersection (vectorised over rays); returns t (inf = miss)"""
|
| 14 |
+
ba = b - a; oa = ro - a; baba = ba @ ba; bard = rd @ ba; baoa = oa @ ba; rdoa = np.einsum('ij,ij->i', rd, oa); oaoa = np.einsum('ij,ij->i', oa, oa)
|
| 15 |
+
A = baba - bard * bard; B = baba * rdoa - baoa * bard; C = baba * oaoa - baoa * baoa - r * r * baba
|
| 16 |
+
h = B * B - A * C; t = np.full(len(ro), np.inf)
|
| 17 |
+
ok = (h >= 0) & (np.abs(A) > 1e-9)
|
| 18 |
+
t1 = np.where(ok, (-B - np.sqrt(np.maximum(h, 0))) / np.where(np.abs(A) > 1e-9, A, 1), np.inf); y = baoa + t1 * bard
|
| 19 |
+
body = ok & (y > 0) & (y < baba); t = np.where(body, t1, t)
|
| 20 |
+
for end in (a, b): # sphere caps
|
| 21 |
+
oc = ro - end; bb = np.einsum('ij,ij->i', rd, oc); cc = np.einsum('ij,ij->i', oc, oc) - r * r; hh = bb * bb - cc
|
| 22 |
+
ts = np.where(hh > 0, -bb - np.sqrt(np.maximum(hh, 0)), np.inf); t = np.minimum(t, np.where(ts > 0, ts, np.inf))
|
| 23 |
+
return t
|
| 24 |
+
def char_shading(ids, J):
|
| 25 |
+
"""shade the capsule characters by code from the per-frame capsule segments (same geometry as the labels):
|
| 26 |
+
orthographic view rays from world_to_clip, nearest capsule hit, lambert + ambient from a light fixed in view space,
|
| 27 |
+
left limbs slightly darker so the pose reads. Returns (H, W) shade in 0..1 for class 10 / 11 pixels."""
|
| 28 |
+
H, W = ids.shape; m = (ids == 10) | (ids == 11); shade = np.zeros((H, W)); caps = []
|
| 29 |
+
for ch in ((J.get('v9') or {}).get('characters') or []):
|
| 30 |
+
for c in ch['capsules']:
|
| 31 |
+
k = 0.88 if c['name'] == 'weapon' else SIDE.get(c['name'][:2], 1.0)
|
| 32 |
+
caps.append((np.array(c['a'], float), np.array(c['b'], float), float(c['r']), k))
|
| 33 |
+
if not m.any() or not caps: return shade, m
|
| 34 |
+
M = np.array(J['world_to_clip'], float).reshape(4, 4); Mi = np.linalg.inv(M)
|
| 35 |
+
V = np.array(J['world_to_view'], float).reshape(4, 4)
|
| 36 |
+
vy, vx = np.nonzero(m); nx = ((vx + 0.5) / W - 0.5) * 2; ny = (0.5 - (vy + 0.5) / H) * 2
|
| 37 |
+
def unproj(z):
|
| 38 |
+
p = np.stack([nx, ny, np.full_like(nx, z), np.ones_like(nx)], 1) @ Mi; return p[:, :3] / p[:, 3:4]
|
| 39 |
+
p0, p1 = unproj(0.9), unproj(0.1); rd = p1 - p0; rd /= np.linalg.norm(rd, axis=1, keepdims=True)
|
| 40 |
+
fwd = V[:3, 2] / np.linalg.norm(V[:3, 2]) # world direction of the view forward axis (row-vector convention)
|
| 41 |
+
if (rd @ fwd).mean() < 0: rd = -rd
|
| 42 |
+
ro = p0 - rd * 5000.0
|
| 43 |
+
best = np.full(len(ro), np.inf); kk = np.ones(len(ro)); nn = np.zeros((len(ro), 3))
|
| 44 |
+
for a, b, r, k in caps:
|
| 45 |
+
t = cap_hit(ro, rd, a, b, r); w = t < best
|
| 46 |
+
if w.any():
|
| 47 |
+
best[w] = t[w]; kk[w] = k; P = ro[w] + rd[w] * t[w, None]; ba = b - a
|
| 48 |
+
hseg = np.clip(((P - a) @ ba) / max(ba @ ba, 1e-6), 0, 1); n = P - a - hseg[:, None] * ba; nn[w] = n / np.maximum(np.linalg.norm(n, axis=1, keepdims=True), 1e-6)
|
| 49 |
+
right, up = V[:3, 0] / np.linalg.norm(V[:3, 0]), V[:3, 1] / np.linalg.norm(V[:3, 1])
|
| 50 |
+
L = -0.45 * right + 0.55 * up - 0.70 * fwd; L /= np.linalg.norm(L)
|
| 51 |
+
lam = np.clip(nn @ L, 0, 1); s = np.where(np.isfinite(best), (0.30 + 0.70 * lam) * kk, 0.62)
|
| 52 |
+
shade[vy, vx] = s; return shade, m
|
| 53 |
+
def cond(ids, J):
|
| 54 |
+
out = PAL[ids].astype(np.float32)
|
| 55 |
+
shade, m = char_shading(ids, J)
|
| 56 |
+
for c, t in TINT.items():
|
| 57 |
+
mc = ids == c
|
| 58 |
+
if mc.any(): out[mc] = np.clip(shade[mc, None] * 1.1, 0, 1) * t * 255.0
|
| 59 |
+
return np.clip(out, 0, 255).astype(np.uint8)
|
| 60 |
+
def one(base):
|
| 61 |
+
ids = np.asarray(Image.open(base + '.ids.png')); ids = ids[..., 0] if ids.ndim == 3 else ids
|
| 62 |
+
c = cond(ids, json.load(open(base + '.json')))
|
| 63 |
+
Image.fromarray(c).save(base + '.cond.png', optimize=False, compress_level=3)
|
| 64 |
+
return base
|
| 65 |
+
def clip_index(run, bases):
|
| 66 |
+
"""81-frame training clips on the v9 cut grid: starts at multiples of cut_grid (96); a clip is kept only if all 81 frames
|
| 67 |
+
share look, camera variant and episode and the player never jumps > 4 m between frames (unscheduled teleports)."""
|
| 68 |
+
cr = json.load(open(os.path.join(run, 'capture_result.json'), encoding='utf-8')); v9 = cr.get('v9') or {}
|
| 69 |
+
G = int(v9.get('cut_grid', 96)); n = len(bases)
|
| 70 |
+
def meta(b):
|
| 71 |
+
j = json.load(open(b + '.json')); a = {x['role']: x for x in j.get('actors', [])}
|
| 72 |
+
return ((j.get('v9') or {}).get('look'), j.get('camera_variant'), j.get('episode'), (a.get('player') or {}).get('position_cm'))
|
| 73 |
+
with ThreadPoolExecutor(8) as ex: M = list(ex.map(meta, bases))
|
| 74 |
+
keep, drop = [], []
|
| 75 |
+
for s in range(0, n - 80, G):
|
| 76 |
+
w = M[s:s + 81]; ok = len({(m[0], m[1], m[2]) for m in w}) == 1
|
| 77 |
+
if ok:
|
| 78 |
+
for a, b in zip(w, w[1:]):
|
| 79 |
+
if a[3] and b[3] and np.linalg.norm(np.array(a[3]) - np.array(b[3])) > 400: ok = False; break
|
| 80 |
+
(keep if ok else drop).append({'start': s, 'end': s + 80, 'look': w[0][0], 'camera_variant': w[0][1], 'episode': w[0][2]})
|
| 81 |
+
looks = {l['index']: l['name'] for l in v9.get('look_log', [])}
|
| 82 |
+
for c in keep: c['look_name'] = looks.get(c['look'], '')
|
| 83 |
+
json.dump({'clip_frames': 81, 'cut_grid': G, 'rule': 'clips start at multiples of cut_grid; looks / cameras / episodes only change between frame k*cut_grid+%d and the next' % v9.get('cut_phase', 80),
|
| 84 |
+
'clips': keep, 'dropped': drop}, open(os.path.join(run, 'clips_81_v9.json'), 'w'), indent=1)
|
| 85 |
+
print('clips kept', len(keep), 'dropped', len(drop), flush=True)
|
| 86 |
+
def main():
|
| 87 |
+
run = sys.argv[1]; every = 1
|
| 88 |
+
if '--every' in sys.argv: every = int(sys.argv[sys.argv.index('--every') + 1])
|
| 89 |
+
bases = sorted(p[:-8] for p in glob.glob(os.path.join(run, 'raw', '[0-9]' * 6 + '.ids.png')))[::every]
|
| 90 |
+
with ThreadPoolExecutor(8) as ex: list(ex.map(one, bases))
|
| 91 |
+
print('cond frames', len(bases), flush=True)
|
| 92 |
+
if every == 1: clip_index(run, bases)
|
| 93 |
+
if '--preview' in sys.argv:
|
| 94 |
+
k = sys.argv.index('--preview'); out = sys.argv[k + 1]; sec = float(sys.argv[k + 2])
|
| 95 |
+
tmp = out + '_tmp'; shutil.rmtree(tmp, ignore_errors=True); os.makedirs(tmp)
|
| 96 |
+
try: F = ImageFont.truetype('C:/Windows/Fonts/msyh.ttc', 22)
|
| 97 |
+
except Exception: F = ImageFont.load_default()
|
| 98 |
+
sel = bases[:int(sec * 16)]
|
| 99 |
+
def pv(a):
|
| 100 |
+
i, b = a
|
| 101 |
+
rgb = Image.open(b + '.jpg').convert('RGB').resize((960, 528), Image.LANCZOS); cd = Image.open(b + '.cond.png').convert('RGB').resize((960, 528), Image.NEAREST)
|
| 102 |
+
j = json.load(open(b + '.json')); nm = (j.get('v9') or {}).get('look_name', '')
|
| 103 |
+
fr = Image.new('RGB', (1928, 576), (10, 10, 14)); fr.paste(rgb, (0, 48)); fr.paste(cd, (968, 48)); d = ImageDraw.Draw(fr)
|
| 104 |
+
d.text((14, 10), 'RGB · ' + nm, font=F, fill=(255, 214, 110)); d.text((982, 10), 'cond(场景语义 + 胶囊白膜角色) · ortho %.0f cm' % j.get('ortho_width_cm', 0), font=F, fill=(200, 200, 210))
|
| 105 |
+
fr.save(os.path.join(tmp, '%05d.jpg' % i), quality=90)
|
| 106 |
+
with ThreadPoolExecutor(8) as ex: list(ex.map(pv, enumerate(sel)))
|
| 107 |
+
subprocess.run(['ffmpeg', '-y', '-loglevel', 'error', '-framerate', '16', '-i', os.path.join(tmp, '%05d.jpg'), '-c:v', 'libx264', '-crf', '22', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', out])
|
| 108 |
+
shutil.rmtree(tmp, ignore_errors=True); print('preview', out)
|
| 109 |
+
main()
|
code/post/export_v6.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""GameCrafter v5 capture -> training index (v4 format + layout remix summary). usage: export_v4.py cache RAW OUT BUDGET | index RAW OUT"""
|
| 2 |
+
import sys, os, json, glob
|
| 3 |
+
import numpy as np
|
| 4 |
+
MODE, RAW, OUT = sys.argv[1], os.path.abspath(sys.argv[2]), os.path.abspath(sys.argv[3])
|
| 5 |
+
FPS, BLOCK, CLIP = 16, 4, 81
|
| 6 |
+
CLASSES = {0: 'sky/background', 1: 'terrain', 2: 'paving', 3: 'architecture', 4: 'rock', 5: 'vegetation', 6: 'prop', 10: 'player', 11: 'boss'}
|
| 7 |
+
os.makedirs(OUT, exist_ok=True)
|
| 8 |
+
R = os.path.join(RAW, 'raw')
|
| 9 |
+
N = len(glob.glob(os.path.join(R, '*.json')))
|
| 10 |
+
if MODE == 'cache':
|
| 11 |
+
import time; t0 = time.time(); budget = float(sys.argv[4]) if len(sys.argv) > 4 else 150
|
| 12 |
+
C = os.path.join(OUT, '_cache'); os.makedirs(C, exist_ok=True)
|
| 13 |
+
for k in range((N + 999) // 1000):
|
| 14 |
+
path = os.path.join(C, f'{k:04d}.json')
|
| 15 |
+
if os.path.exists(path): continue
|
| 16 |
+
if time.time() - t0 > budget: break
|
| 17 |
+
chunk = [json.load(open(os.path.join(R, f'{f:06d}.json'))) for f in range(k * 1000, min(N, (k + 1) * 1000))]
|
| 18 |
+
json.dump(chunk, open(path + '.tmp', 'w')); os.replace(path + '.tmp', path)
|
| 19 |
+
left = [k for k in range((N + 999) // 1000) if not os.path.exists(os.path.join(C, f'{k:04d}.json'))]
|
| 20 |
+
print('cache chunks remaining', len(left)); sys.exit(0)
|
| 21 |
+
|
| 22 |
+
acts = np.zeros((N, 5), np.uint8); eps = np.zeros(N, np.int32); cams = np.zeros(N, np.int32); invalid = 0
|
| 23 |
+
modes, states, rows, ev_frames = {}, {}, [], []
|
| 24 |
+
models = {'player': {}, 'boss': {}}; scales = {'player': [], 'boss': []}
|
| 25 |
+
C = os.path.join(OUT, '_cache'); cached = {}
|
| 26 |
+
def get(f):
|
| 27 |
+
k = f // 1000
|
| 28 |
+
if k not in cached:
|
| 29 |
+
cp = os.path.join(C, f'{k:04d}.json'); cached.clear(); cached[k] = json.load(open(cp)) if os.path.exists(cp) else None
|
| 30 |
+
return cached[k][f - k * 1000] if cached[k] is not None else json.load(open(os.path.join(R, f'{f:06d}.json')))
|
| 31 |
+
appearance = None
|
| 32 |
+
with open(os.path.join(OUT, 'frames.jsonl'), 'w') as fj:
|
| 33 |
+
for f in range(N):
|
| 34 |
+
j = get(f); a = j['action']; acts[f] = [a['w'], a['a'], a['s'], a['d'], a['attack']]
|
| 35 |
+
eps[f] = j['episode']; cams[f] = j.get('camera_variant', 0); invalid += j.get('label_invalid_pixels', 0)
|
| 36 |
+
appearance = j.get('appearance', appearance)
|
| 37 |
+
modes[a['bot_mode']] = modes.get(a['bot_mode'], 0) + 1
|
| 38 |
+
pl = next(x for x in j['actors'] if x['role'] == 'player'); bs = next(x for x in j['actors'] if x['role'] == 'boss')
|
| 39 |
+
states[pl['action']] = states.get(pl['action'], 0) + 1
|
| 40 |
+
ch = {c['role']: c for c in j.get('characters', [])}
|
| 41 |
+
if f % 4 == 0:
|
| 42 |
+
for role in ('player', 'boss'):
|
| 43 |
+
if role in ch: models[role][ch[role]['model']] = models[role].get(ch[role]['model'], 0) + 1; scales[role].append(ch[role]['scale'])
|
| 44 |
+
for e in j.get('events', []): ev_frames.append(dict(e, frame=f))
|
| 45 |
+
rows.append(f"{f},{j['time_seconds']:.4f},{a['w']},{a['a']},{a['s']},{a['d']},{a['attack']},{j['episode']},{cams[f]},{a['bot_mode']},{a.get('fight_sub','')},{pl['action']},{pl['health']:.0f},{bs['action']},{bs['health']:.0f},"
|
| 46 |
+
f"{ch.get('player',{}).get('model','')},{ch.get('player',{}).get('scale',1):.3f},{ch.get('boss',{}).get('model','')},{ch.get('boss',{}).get('scale',1):.3f},{len(j.get('events',[]))}")
|
| 47 |
+
keep = ['frame_id', 'time_seconds', 'episode', 'camera_variant', 'mirrored_world', 'personality', 'action', 'camera_world_cm', 'camera_pitch_yaw_roll', 'ortho_width_cm', 'world_to_clip', 'label_invalid_pixels', 'appearance', 'characters', 'events']
|
| 48 |
+
fj.write(json.dumps({k: j[k] for k in keep if k in j} | {'actors': [{k: x[k] for k in ['role', 'action', 'health', 'position_cm', 'velocity_cm_s']} for x in j['actors']]}, separators=(',', ':')) + '\n')
|
| 49 |
+
np.save(os.path.join(OUT, 'actions.npy'), acts); np.save(os.path.join(OUT, 'episodes.npy'), eps)
|
| 50 |
+
nb = N // BLOCK; blocks = np.zeros((nb, 5), np.uint8)
|
| 51 |
+
for b in range(nb):
|
| 52 |
+
seg = acts[b * BLOCK:(b + 1) * BLOCK]; blocks[b, :4] = seg[0, :4]; blocks[b, 4] = seg[:, 4].max()
|
| 53 |
+
np.save(os.path.join(OUT, 'actions_block_0.25s.npy'), blocks)
|
| 54 |
+
within_change = int(sum((acts[b * BLOCK:(b + 1) * BLOCK, :4] != acts[b * BLOCK, :4]).any() for b in range(nb)))
|
| 55 |
+
with open(os.path.join(OUT, 'actions.csv'), 'w') as fc:
|
| 56 |
+
fc.write('frame,time_s,w,a,s,d,attack,episode,camera_variant,bot_mode,fight_sub,player_state,player_hp,boss_state,boss_hp,player_model,player_scale,boss_model,boss_scale,n_events\n' + '\n'.join(rows) + '\n')
|
| 57 |
+
# events: the json of frame f lists the events that first become visible at frame f
|
| 58 |
+
events = [e for e in ev_frames if e.get('type') in ('delete', 'replace', 'spawn')]
|
| 59 |
+
json.dump(ev_frames, open(os.path.join(OUT, 'events.json'), 'w'), indent=0)
|
| 60 |
+
clips = []
|
| 61 |
+
starts = [0] + [f for f in range(1, N) if eps[f] != eps[f - 1] or cams[f] != cams[f - 1]] + [N]
|
| 62 |
+
for s0, s1 in zip(starts[:-1], starts[1:]):
|
| 63 |
+
s = ((s0 + BLOCK - 1) // BLOCK) * BLOCK
|
| 64 |
+
while s + CLIP <= s1:
|
| 65 |
+
inside = [{'offset': e['frame'] - s, 'type': e['type'], 'removed': e.get('removed', {}).get('class'), 'added': e.get('added', {}).get('class')} for e in events if s < e['frame'] < s + CLIP]
|
| 66 |
+
clips.append({'start': s, 'end': s + CLIP, 'episode': int(eps[s]), 'camera_variant': int(cams[s]), 'events': inside}); s += CLIP - 1
|
| 67 |
+
json.dump(clips, open(os.path.join(OUT, 'clips_81.json'), 'w'))
|
| 68 |
+
res = json.load(open(os.path.join(RAW, 'capture_result.json'))) if os.path.exists(os.path.join(RAW, 'capture_result.json')) else {}
|
| 69 |
+
seg_len = np.diff([i for i in range(1, N) if (acts[i, :4] != acts[i - 1, :4]).any()] or [0])
|
| 70 |
+
ev_counts = {}
|
| 71 |
+
for e in events: ev_counts[e['type']] = ev_counts.get(e['type'], 0) + 1
|
| 72 |
+
ev_classes = {}
|
| 73 |
+
for e in events:
|
| 74 |
+
for side in ('removed', 'added'):
|
| 75 |
+
if side in e: k = f"{side}:{e[side]['class']}"; ev_classes[k] = ev_classes.get(k, 0) + 1
|
| 76 |
+
q = lambda v: [round(float(x), 3) for x in np.percentile(v, [0, 10, 50, 90, 100])] if len(v) else []
|
| 77 |
+
meta = {'run': os.path.basename(RAW), 'frames': N, 'fps': FPS, 'duration_min': round(N / FPS / 60, 2), 'resolution': [1280, 704], 'camera': 'isometric orthographic 2.5D',
|
| 78 |
+
'appearance': appearance, 'appearance_detail': res.get('appearance'), 'layout_seed': res.get('layout_seed'), 'mirrored_world': res.get('mirrored_world'),
|
| 79 |
+
'mirrored_y': res.get('mirrored_y'), 'layout_remix': {k: v for k, v in (res.get('layout_remix') or {}).items() if k != 'items'},
|
| 80 |
+
'cross_scene': {k: v for k, v in (res.get('cross_scene') or {}).items() if k not in ('items', 'style_map')},
|
| 81 |
+
'files_per_frame': {'rgb': '%06d.jpg', 'semantic_ids': '%06d.ids.png (uint8 class id, lossless)', 'whitebox': '%06d.whitebox.jpg', 'meta': '%06d.json'},
|
| 82 |
+
'action_layout': ['w', 'a', 's', 'd', 'attack'],
|
| 83 |
+
'semantic_classes': {str(k): v for k, v in CLASSES.items()}, 'episodes': int(eps.max() + 1), 'camera_variants': int(len(set(cams.tolist()))), 'clips_81': len(clips),
|
| 84 |
+
'clips_with_events': sum(1 for c in clips if c['events']), 'events': ev_counts, 'event_classes': ev_classes,
|
| 85 |
+
'label_invalid_pixels_total': int(invalid), 'blocks_with_key_change_inside': within_change,
|
| 86 |
+
'key_segment_frames': {'median': float(np.median(seg_len)) if len(seg_len) else 0, 'p10': float(np.percentile(seg_len, 10)) if len(seg_len) else 0, 'min': int(seg_len.min()) if len(seg_len) else 0},
|
| 87 |
+
'action_frequency': {k: round(float(acts[:, i].mean()), 4) for i, k in enumerate('wasd')} | {'attack_per_block': round(float(blocks[:, 4].mean()), 4), 'no_key': round(float((acts[:, :4].sum(1) == 0).mean()), 4)},
|
| 88 |
+
'bot_modes': {k: round(v / N, 4) for k, v in sorted(modes.items(), key=lambda x: -x[1])}, 'player_states': {k: round(v / N, 4) for k, v in sorted(states.items(), key=lambda x: -x[1])},
|
| 89 |
+
'character_models': {r: {k: round(v / max(1, sum(models[r].values())), 3) for k, v in models[r].items()} for r in models},
|
| 90 |
+
'character_scale_percentiles': {r: q(scales[r]) for r in scales},
|
| 91 |
+
'capture_result': res}
|
| 92 |
+
json.dump(meta, open(os.path.join(OUT, 'meta.json'), 'w'), indent=1, ensure_ascii=False)
|
| 93 |
+
print(json.dumps({k: meta[k] for k in ['run', 'frames', 'appearance', 'episodes', 'clips_81', 'clips_with_events', 'events', 'label_invalid_pixels_total', 'blocks_with_key_change_inside', 'action_frequency', 'bot_modes', 'character_models', 'character_scale_percentiles']}, ensure_ascii=False))
|
code/post/post_v10_pool.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Index every finished run since the capsule-character labels (v9 stylized + v10 real) for upload: v6 exporter (actions, blocks,
|
| 2 |
+
events, frames.jsonl, meta) with the clip list replaced by the capture's cut-grid clips (clips_81_v9.json), meta extended with the
|
| 3 |
+
v9 / v10 fields, plus a thumbnail (RGB | semantic | condition). Parallel; finished runs are skipped.
|
| 4 |
+
usage: post_v10_pool.py DSROOT [WORKERS]"""
|
| 5 |
+
import os, sys, json, glob, re, time, subprocess
|
| 6 |
+
from concurrent.futures import ProcessPoolExecutor, as_completed
|
| 7 |
+
import numpy as np
|
| 8 |
+
from PIL import Image
|
| 9 |
+
EXP = r'G:\GameCrafter\capture_work\v6\post\export_v6.py'
|
| 10 |
+
SUBSETS = {'v9_stylized': ([r'D:\GameCrafter_v9\raw', r'E:\GameCrafter_v9\raw'], re.compile(r'^(\d\d_.+?)_(P9[A-Z]?_[a-z]+_s\d+)$')),
|
| 11 |
+
'v10_real': ([r'F:\GameCrafter_v10\raw', r'E:\GameCrafter_v10\raw', r'H:\GameCrafter_v10\raw', r'G:\GameCrafter_v10\raw'], re.compile(r'^(\d\d_.+?)_(R10_s\d+)$'))}
|
| 12 |
+
PAL = np.array([[18, 20, 26], [122, 156, 92], [196, 186, 160], [182, 98, 72], [128, 120, 132], [52, 128, 60], [214, 168, 52]] + [[0, 0, 0]] * 3 +
|
| 13 |
+
[[80, 150, 255], [255, 80, 70]] + [[255, 0, 255]] * 244, np.uint8)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def one(subset, d, ds):
|
| 17 |
+
name = os.path.basename(d); scene, tag = SUBSETS[subset][1].match(name).groups()
|
| 18 |
+
out = os.path.join(ds, subset, scene, tag); t0 = time.time()
|
| 19 |
+
if os.path.exists(os.path.join(out, 'meta.json')) and os.path.exists(os.path.join(out, 'thumb.jpg')): return name, 'skip', 0
|
| 20 |
+
r = subprocess.run([sys.executable, EXP, 'index', d, out], capture_output=True, text=True)
|
| 21 |
+
if r.returncode: return name, 'INDEX FAILED ' + r.stderr[-600:], time.time() - t0
|
| 22 |
+
m = json.load(open(os.path.join(out, 'meta.json'), encoding='utf-8')); cr = m.get('capture_result', {}); v9 = cr.get('v9', {})
|
| 23 |
+
cv = json.load(open(os.path.join(d, 'clips_81_v9.json'), encoding='utf-8'))
|
| 24 |
+
ev = json.load(open(os.path.join(out, 'events.json'), encoding='utf-8')); ev = [e for e in ev if e.get('type') in ('delete', 'replace', 'spawn')]
|
| 25 |
+
clips = []
|
| 26 |
+
for c in cv['clips']:
|
| 27 |
+
s, e = c['start'], c['end'] + 1
|
| 28 |
+
clips.append({'start': s, 'end': e, 'episode': c.get('episode'), 'camera_variant': c.get('camera_variant'), 'look': c.get('look'), 'look_name': c.get('look_name'),
|
| 29 |
+
'centered': c.get('centered', True), 'max_frame_offset_cm': c.get('max_frame_offset_cm', 0.0),
|
| 30 |
+
'events': [{'offset': x['frame'] - s, 'type': x['type'], 'removed': (x.get('removed') or {}).get('class'), 'added': (x.get('added') or {}).get('class')} for x in ev if s <= x['frame'] < e]})
|
| 31 |
+
json.dump(clips, open(os.path.join(out, 'clips_81.json'), 'w'))
|
| 32 |
+
real = subset == 'v10_real'; vr = v9.get('v10_real') or {}
|
| 33 |
+
m.update({'subset': subset, 'clips_81': len(clips), 'clips_81_dropped': len(cv.get('dropped') or []), 'clips_with_events': sum(1 for c in clips if c['events']),
|
| 34 |
+
'clips_centered': sum(1 for c in clips if c['centered']), 'cut_grid': cv.get('cut_grid'), 'clip_rule': cv.get('rule'), 'looks': v9.get('looks'),
|
| 35 |
+
'look_names': sorted({c['look_name'] for c in clips if c.get('look_name')}), 'capsule_labels': bool(v9.get('capsule_labels')),
|
| 36 |
+
'camera': ('perspective telephoto (FOV 22-40 deg) with the 2.5D framing, player kept centred' if real else
|
| 37 |
+
'isometric orthographic 2.5D (v9 framing: ortho width 900-1600 cm, 12% wide 2000-3000 cm, pitch -68..-32 deg)'),
|
| 38 |
+
'files_per_frame': {'rgb': '%06d.jpg', 'semantic_ids': '%06d.ids.png (uint8 class id, lossless; player / boss drawn as capsules)',
|
| 39 |
+
'whitebox': '%06d.whitebox.jpg', 'condition': '%06d.cond.png (semantic palette + code-shaded capsule characters)', 'meta': '%06d.json'}})
|
| 40 |
+
if real: m['v10_real'] = {'biome_variants_used': vr.get('variants_used'), 'counts': vr.get('counts')}
|
| 41 |
+
json.dump(m, open(os.path.join(out, 'meta.json'), 'w', encoding='utf-8'), indent=1, ensure_ascii=False)
|
| 42 |
+
n = m['frames']; rows = []
|
| 43 |
+
for f in (n // 3, 2 * n // 3):
|
| 44 |
+
b = os.path.join(d, 'raw', f'{f:06d}')
|
| 45 |
+
rgb = np.asarray(Image.open(b + '.jpg').convert('RGB').resize((427, 235)))
|
| 46 |
+
ids = PAL[np.asarray(Image.open(b + '.ids.png').resize((427, 235), Image.NEAREST))]
|
| 47 |
+
cond = np.asarray(Image.open(b + '.cond.png').convert('RGB').resize((427, 235)))
|
| 48 |
+
rows.append(np.concatenate([rgb, ids, cond], 1))
|
| 49 |
+
Image.fromarray(np.concatenate(rows, 0)).save(os.path.join(out, 'thumb.jpg'), quality=85)
|
| 50 |
+
return name, 'done', time.time() - t0
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
if __name__ == '__main__':
|
| 54 |
+
ds = sys.argv[1]; workers = int(sys.argv[2]) if len(sys.argv) > 2 else 4
|
| 55 |
+
jobs = []
|
| 56 |
+
for subset, (roots, rx) in SUBSETS.items():
|
| 57 |
+
for root in roots:
|
| 58 |
+
for d in sorted(glob.glob(os.path.join(root, '*'))):
|
| 59 |
+
if not rx.match(os.path.basename(d)): continue
|
| 60 |
+
try: ok = json.load(open(os.path.join(d, 'capture_result.json'))).get('ok')
|
| 61 |
+
except Exception: ok = False
|
| 62 |
+
if ok and os.path.exists(os.path.join(d, 'clips_81_v9.json')): jobs.append((subset, d))
|
| 63 |
+
print(time.strftime('%H:%M:%S'), len(jobs), 'runs', {s: sum(1 for j in jobs if j[0] == s) for s in SUBSETS}, flush=True)
|
| 64 |
+
with ProcessPoolExecutor(workers) as ex:
|
| 65 |
+
futs = [ex.submit(one, s, d, ds) for s, d in jobs]
|
| 66 |
+
for k, f in enumerate(as_completed(futs)):
|
| 67 |
+
name, st, sec = f.result(); print(time.strftime('%H:%M:%S'), f'{k + 1}/{len(jobs)}', name, st, f'{sec:.0f}s', flush=True)
|
code/ue_capture/PipelineCaptureV10.cpp
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// v10 photoreal pass (on top of v9; -DatasetV10Photo): every camera-variant look is "photoreal": the scene's opaque materials
|
| 2 |
+
// are replaced per (material, semantic class) by M_V10PBR with CC0 photo-scanned PBR sets (Poly Haven / ambientCG; top layer
|
| 3 |
+
// for horizontal faces, side layer for walls / cliffs, a noise-masked cover layer of moss / dust / snow on upward faces),
|
| 4 |
+
// a cinematic light preset (golden hour, morning mist, overcast, harsh noon, backlit, dusk: sun angle / colour / intensity,
|
| 5 |
+
// sky light, height fog + volumetric fog) and a film grade (split toning, grain, vignette, bloom). RGB only: labels, depth
|
| 6 |
+
// and whitebox are unchanged; the v9 cut grid, centred camera and capsule labels apply as before.
|
| 7 |
+
#include "PipelineCapture.h"
|
| 8 |
+
#include "GameDemo.h"
|
| 9 |
+
#include "Components/SceneCaptureComponent2D.h"
|
| 10 |
+
#include "Components/DirectionalLightComponent.h"
|
| 11 |
+
#include "Components/SkyLightComponent.h"
|
| 12 |
+
#include "Components/ExponentialHeightFogComponent.h"
|
| 13 |
+
#include "Components/MeshComponent.h"
|
| 14 |
+
#include "GameFramework/SpringArmComponent.h"
|
| 15 |
+
#include "Engine/Texture.h"
|
| 16 |
+
#include "Materials/MaterialInterface.h"
|
| 17 |
+
#include "Materials/MaterialInstanceDynamic.h"
|
| 18 |
+
#include "EngineUtils.h"
|
| 19 |
+
#include "Misc/FileHelper.h"
|
| 20 |
+
#include "HAL/IConsoleManager.h"
|
| 21 |
+
#include "Misc/Paths.h"
|
| 22 |
+
#include "Dom/JsonObject.h"
|
| 23 |
+
#include "Serialization/JsonReader.h"
|
| 24 |
+
#include "Serialization/JsonSerializer.h"
|
| 25 |
+
|
| 26 |
+
namespace
|
| 27 |
+
{
|
| 28 |
+
struct FV10Set{FString Key,Role,Words,C,N,R;};
|
| 29 |
+
TArray<FV10Set> GV10Sets;
|
| 30 |
+
const TCHAR* V10LightNames[8]={TEXT("golden"),TEXT("mist"),TEXT("overcast"),TEXT("noon"),TEXT("backlit"),TEXT("dusk"),TEXT("night"),TEXT("storm")};
|
| 31 |
+
const TCHAR* V10Biomes[7]={TEXT("forest"),TEXT("arid"),TEXT("snow"),TEXT("temperate"),TEXT("wet"),TEXT("meadow"),TEXT("coast")};
|
| 32 |
+
const TCHAR* V10BiomeWords[7]={TEXT("forest moss leaves mud bark soil grass fern root"),TEXT("sand desert dry gravel dirt sandstone red cracked"),
|
| 33 |
+
TEXT("snow ice frozen frost"),TEXT(""),TEXT("mud wet puddle moss rain"),TEXT("grass meadow soil mud dirt aerial leaves"),TEXT("sand beach gravel pebble shore coast")};
|
| 34 |
+
int32 V10PickKey(const TCHAR* List,FRandomStream& R)
|
| 35 |
+
{
|
| 36 |
+
TArray<FString> W;FString(List).ParseIntoArray(W,TEXT(" "));TArray<int32> Hit;
|
| 37 |
+
for(int32 I=0;I<GV10Sets.Num();I++)for(const FString& X:W)if(GV10Sets[I].Key==X){Hit.Add(I);break;}
|
| 38 |
+
return Hit.Num()?Hit[R.RandRange(0,Hit.Num()-1)]:-1;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
bool APipelineCapture::V10LoadSets()
|
| 43 |
+
{
|
| 44 |
+
if(V10Loaded)return GV10Sets.Num()>0;V10Loaded=true;
|
| 45 |
+
V10Mat=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V10/Materials/M_V10PBR.M_V10PBR"));
|
| 46 |
+
FString S;if(!FFileHelper::LoadFileToString(S,*(FPaths::ProjectContentDir()/TEXT("Xfer/V10/v10_pbr.json"))))return false;
|
| 47 |
+
TSharedPtr<FJsonObject> O;const TSharedRef<TJsonReader<>> Rd=TJsonReaderFactory<>::Create(S);
|
| 48 |
+
if(!FJsonSerializer::Deserialize(Rd,O)||!O.IsValid())return false;
|
| 49 |
+
const TArray<TSharedPtr<FJsonValue>>* A;
|
| 50 |
+
if(O->TryGetArrayField(TEXT("sets"),A))for(const auto& V:*A)
|
| 51 |
+
{
|
| 52 |
+
const TSharedPtr<FJsonObject> T=V->AsObject();if(!T)continue;
|
| 53 |
+
FV10Set X;X.Key=T->GetStringField(TEXT("key"));X.Role=T->GetStringField(TEXT("role"));X.C=T->GetStringField(TEXT("color"));X.N=T->GetStringField(TEXT("normal"));X.R=T->GetStringField(TEXT("rough"));
|
| 54 |
+
FString W=X.Key;const TArray<TSharedPtr<FJsonValue>>* L;
|
| 55 |
+
for(const TCHAR* F:{TEXT("categories"),TEXT("tags")})if(T->TryGetArrayField(F,L))for(const auto& Q:*L)W+=TEXT(" ")+Q->AsString();
|
| 56 |
+
X.Words=W.ToLower();GV10Sets.Add(X);
|
| 57 |
+
}
|
| 58 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 photoreal: material=%d pbr sets=%d"),V10Mat!=nullptr,GV10Sets.Num());
|
| 59 |
+
return GV10Sets.Num()>0;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
int32 APipelineCapture::V10Pick(const TCHAR* WantRole,const TCHAR* Fallback)
|
| 63 |
+
{
|
| 64 |
+
const FString Bw=V10BiomeWords[FMath::Clamp(V10Biome,0,6)];TArray<FString> Words;Bw.ParseIntoArray(Words,TEXT(" "));
|
| 65 |
+
TArray<int32> All,Match;
|
| 66 |
+
for(int32 Pass=0;Pass<2&&All.Num()==0;Pass++)
|
| 67 |
+
for(int32 I=0;I<GV10Sets.Num();I++)if(GV10Sets[I].Role==(Pass==0?WantRole:Fallback))
|
| 68 |
+
{
|
| 69 |
+
All.Add(I);for(const FString& W:Words)if(GV10Sets[I].Words.Contains(W)){Match.Add(I);break;}
|
| 70 |
+
}
|
| 71 |
+
if(All.Num()==0)return GV10Sets.Num()?V9Rng.RandRange(0,GV10Sets.Num()-1):-1;
|
| 72 |
+
const TArray<int32>& From=(Match.Num()&&V9Rng.FRand()<.75f)?Match:All;
|
| 73 |
+
return From[V9Rng.RandRange(0,From.Num()-1)];
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
UTexture* APipelineCapture::V10Tex(const FString& Path)
|
| 77 |
+
{
|
| 78 |
+
if(UTexture** T=V10TexCache.Find(Path))return *T;
|
| 79 |
+
UTexture* T=LoadObject<UTexture>(nullptr,*Path);V10TexCache.Add(Path,T);if(T)V10Keep.Add(T);return T;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
void APipelineCapture::V10ApplyPBR()
|
| 83 |
+
{
|
| 84 |
+
if(!V10LoadSets()||!V10Mat){UE_LOG(LogTemp,Warning,TEXT("DATASET_V10 PBR sets / material missing, keeping originals"));return;}
|
| 85 |
+
auto R=[&](float A,float B){return V9Rng.FRandRange(A,B);};
|
| 86 |
+
int32 G=V10Pick(TEXT("ground"),TEXT("rock")),P=V10Pick(TEXT("paving"),TEXT("ground")),Rf=V10Pick(TEXT("roof"),TEXT("wall")),K=V10Pick(TEXT("rock"),TEXT("ground"));
|
| 87 |
+
int32 Cv=V10Pick(V10Biome==2?TEXT("top"):(V9Rng.FRand()<.6f?TEXT("top"):TEXT("ground")),TEXT("ground")),Mt=V10Pick(TEXT("metal"),TEXT("wood"));
|
| 88 |
+
const int32 W[3]={V10Pick(TEXT("wall"),TEXT("wood")),V10Pick(TEXT("wood"),TEXT("wall")),V10Pick(TEXT("wall"),TEXT("rock"))};
|
| 89 |
+
float CovBase=V10Biome==2?R(.45f,.8f):R(.1f,.5f);
|
| 90 |
+
if(V10Real) // v10 real v2: the ground / slope / cover sets of the look's biome variant
|
| 91 |
+
{
|
| 92 |
+
const int32 G2=V10PickKey(*V10VarGround,V9Rng),K2=V10PickKey(*V10VarSide,V9Rng),C2=V10PickKey(*V10VarCover,V9Rng);
|
| 93 |
+
if(G2>=0)G=G2;if(K2>=0)K=K2;if(C2>=0)Cv=C2;CovBase=R(V10VarGCov0,V10VarGCov1);
|
| 94 |
+
}
|
| 95 |
+
V10Theme=FString::Printf(TEXT("ground=%s paving=%s roof=%s rock=%s cover=%s walls=%s,%s,%s"),G>=0?*GV10Sets[G].Key:TEXT("-"),P>=0?*GV10Sets[P].Key:TEXT("-"),
|
| 96 |
+
Rf>=0?*GV10Sets[Rf].Key:TEXT("-"),K>=0?*GV10Sets[K].Key:TEXT("-"),Cv>=0?*GV10Sets[Cv].Key:TEXT("-"),W[0]>=0?*GV10Sets[W[0]].Key:TEXT("-"),W[1]>=0?*GV10Sets[W[1]].Key:TEXT("-"),W[2]>=0?*GV10Sets[W[2]].Key:TEXT("-"));
|
| 97 |
+
auto Make=[&](int32 Top,int32 Side,float CovAmt,float TopTile,float SideTile)->UMaterialInterface*
|
| 98 |
+
{
|
| 99 |
+
if(Top<0||Side<0)return nullptr;
|
| 100 |
+
UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(V10Mat,this);
|
| 101 |
+
const FV10Set& T=GV10Sets[Top];const FV10Set& S=GV10Sets[Side];const FV10Set& C=GV10Sets[Cv>=0?Cv:Top];
|
| 102 |
+
D->SetTextureParameterValue(TEXT("TC"),V10Tex(T.C));D->SetTextureParameterValue(TEXT("TN"),V10Tex(T.N));D->SetTextureParameterValue(TEXT("TR"),V10Tex(T.R));
|
| 103 |
+
D->SetTextureParameterValue(TEXT("SC"),V10Tex(S.C));D->SetTextureParameterValue(TEXT("SN"),V10Tex(S.N));D->SetTextureParameterValue(TEXT("SR"),V10Tex(S.R));
|
| 104 |
+
D->SetTextureParameterValue(TEXT("CC"),V10Tex(C.C));D->SetTextureParameterValue(TEXT("CN"),V10Tex(C.N));D->SetTextureParameterValue(TEXT("CR"),V10Tex(C.R));
|
| 105 |
+
D->SetScalarParameterValue(TEXT("TopTile"),TopTile);D->SetScalarParameterValue(TEXT("SideTile"),SideTile);D->SetScalarParameterValue(TEXT("CovTile"),R(300.f,520.f));
|
| 106 |
+
D->SetScalarParameterValue(TEXT("CovAmt"),FMath::Clamp(CovAmt,0.f,.95f));D->SetScalarParameterValue(TEXT("RMul"),R(.85f,1.15f)*(V10Real?FMath::Lerp(1.f,.62f,V10VarWet):1.f));D->SetScalarParameterValue(TEXT("NStr"),1.f);
|
| 107 |
+
const FLinearColor Warm(1.f,.9f,.78f),Cool(.85f,.92f,1.f);
|
| 108 |
+
D->SetVectorParameterValue(TEXT("Tint"),FLinearColor::LerpUsingHSV(FLinearColor::White,V9Rng.FRand()<(V10Real?.8f:.5f)?Warm:Cool,R(0.f,V10Real?.25f:.35f))*R(.85f,1.08f)*(V10Real?1.f-.25f*V10VarWet:1.f));
|
| 109 |
+
V9MIDs.Add(D);return D;
|
| 110 |
+
};
|
| 111 |
+
TMap<TPair<UMaterialInterface*,int32>,UMaterialInterface*> Map;int32 Comps=0;
|
| 112 |
+
for(TActorIterator<AActor> I(GetWorld());I;++I)
|
| 113 |
+
{
|
| 114 |
+
if(I->ActorHasTag(TEXT("whitebox"))||Cast<AGameDemoFighter>(*I)||*I==this)continue;
|
| 115 |
+
TArray<UMeshComponent*> Cs;I->GetComponents(Cs);
|
| 116 |
+
for(UMeshComponent* C:Cs)
|
| 117 |
+
{
|
| 118 |
+
const int32 Id=C->CustomDepthStencilValue;
|
| 119 |
+
if(!C->bRenderCustomDepth||Id<1||Id>4||Id==3||C->ComponentHasTag(TEXT("v8fx"))||C->ComponentHasTag(TEXT("v10_scatter")))continue; // v10 real: scanned assets keep their own materials // v10b: only terrain / paving / rocks get PBR; buildings, props and (masked) vegetation keep their authored materials
|
| 120 |
+
TArray<UMaterialInterface*> Old;bool Any=false;
|
| 121 |
+
for(int32 S=0;S<C->GetNumMaterials();S++)
|
| 122 |
+
{
|
| 123 |
+
UMaterialInterface* M=C->GetMaterial(S);Old.Add(M);
|
| 124 |
+
if(!M||M->GetBlendMode()!=BLEND_Opaque)continue;
|
| 125 |
+
const TPair<UMaterialInterface*,int32> Key(M,Id);UMaterialInterface** Got=Map.Find(Key);
|
| 126 |
+
if(!Got)
|
| 127 |
+
{
|
| 128 |
+
UMaterialInterface* N=nullptr;
|
| 129 |
+
if(V9Rng.FRand()>=V9Cur.Keep)switch(Id)
|
| 130 |
+
{
|
| 131 |
+
case 1: N=Make(G,K,CovBase+R(-.1f,.15f),V10Real?R(220.f,380.f):R(250.f,450.f),R(300.f,520.f));break;
|
| 132 |
+
case 2: N=Make(V9Rng.FRand()<.7f?P:G,V9Rng.FRand()<.5f?K:W[0],CovBase*R(0.f,.6f),R(150.f,320.f),R(200.f,320.f));break;
|
| 133 |
+
case 3: N=Make(Rf,W[V9Rng.RandRange(0,2)],CovBase*R(0.f,.5f),R(180.f,300.f),R(180.f,320.f));break;
|
| 134 |
+
case 4: N=Make(K,K,CovBase+R(0.f,.25f),R(250.f,500.f),R(250.f,500.f));break;
|
| 135 |
+
default: N=Make(W[1],V9Rng.FRand()<.5f?Mt:W[1],CovBase*R(0.f,.3f),R(120.f,220.f),R(120.f,220.f));break;
|
| 136 |
+
}
|
| 137 |
+
Got=&Map.Add(Key,N?N:M);
|
| 138 |
+
}
|
| 139 |
+
if(*Got!=M){if(!Any){V9Orig.Add(TPair<TWeakObjectPtr<UMeshComponent>,TArray<UMaterialInterface*>>(C,TArray<UMaterialInterface*>()));Any=true;}C->SetMaterial(S,*Got);}
|
| 140 |
+
}
|
| 141 |
+
if(Any){V9Orig.Last().Value=Old;Comps++;}
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
V9MatSwaps+=Comps;
|
| 145 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 pbr (%s): %d material/class pairs -> %d components | %s"),V10Biomes[FMath::Clamp(V10Biome,0,6)],Map.Num(),Comps,*V10Theme);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
void APipelineCapture::V10PhotoLook(FV9Look& L)
|
| 149 |
+
{
|
| 150 |
+
auto R=[&](float A,float B){return V9Rng.FRandRange(A,B);};
|
| 151 |
+
L.Mode=0;L.Tier=0;L.Mip=0;L.Outline=V9Rng.FRand()<.5f;L.Mat=V9Rng.FRand()<.5f?5:0;L.Keep=V9Rng.FRand()<.3f?R(.05f,.2f):0.f;
|
| 152 |
+
V10Biome=V9Rng.RandRange(0,4);
|
| 153 |
+
if(V10Real){L.Mat=5;L.Keep=0;L.Outline=false;V10Biome=0;V10RealNewVariant(L);} // v10 real v2: a new biome variant (and re-scatter) per look
|
| 154 |
+
else L.Biome=V10Biomes[V10Biome];
|
| 155 |
+
if(!V10LightInit)
|
| 156 |
+
{
|
| 157 |
+
V10LightInit=true;
|
| 158 |
+
for(TActorIterator<AActor> I(GetWorld());I;++I)
|
| 159 |
+
{
|
| 160 |
+
TArray<UActorComponent*> Comps;I->GetComponents(Comps);
|
| 161 |
+
for(UActorComponent* C:Comps)
|
| 162 |
+
{
|
| 163 |
+
if(auto* D=Cast<UDirectionalLightComponent>(C)){if(!V10Sun.IsValid()||D->Intensity>V10Sun->Intensity)V10Sun=D;}
|
| 164 |
+
else if(auto* S=Cast<USkyLightComponent>(C))V10Sky=S;
|
| 165 |
+
else if(auto* F=Cast<UExponentialHeightFogComponent>(C))V10Fog=F;
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
if(V10Sun.IsValid()){V10SunI0=V10Sun->Intensity;V10SunR0=V10Sun->GetComponentRotation();V10Sun->SetMobility(EComponentMobility::Movable);}
|
| 169 |
+
if(V10Sky.IsValid())V10SkyI0=V10Sky->Intensity;
|
| 170 |
+
// v10 real: the host scenes' stylised lights range from 0.12 to 5.2 lux sun and 0.85x to 8x ambient (all the same engine
|
| 171 |
+
// daylight cubemap); photo looks use one absolute rig (scene 07's levels, on which the presets were calibrated)
|
| 172 |
+
if(V10Fog.IsValid())V10FogD0=FMath::Max(V10Fog->FogDensity,.004f);
|
| 173 |
+
if(V10Real){V10SunI0=1.f;V10SkyI0=3.4f;V10FogD0=.004f;if(V10Fog.IsValid())V10Fog->SetFogHeightFalloff(.2f);} // fog too: 08 / 10 had .018 / .025 with a high falloff (a milky column under the camera)
|
| 174 |
+
}
|
| 175 |
+
const float W=V9Rng.FRand();int32 P=W<.24f?0:W<.40f?1:W<.58f?2:W<.72f?3:W<.86f?4:5;
|
| 176 |
+
if(V10Real&&!V10LightForced.IsEmpty()){for(int32 I=0;I<8;I++)if(V10LightForced==V10LightNames[I])P=I;} // tests
|
| 177 |
+
else if(V10Real&&!V10VarLights.IsEmpty()) // the light presets that suit the biome variant (incl. night / storm)
|
| 178 |
+
{
|
| 179 |
+
TArray<FString> Ls;V10VarLights.ParseIntoArray(Ls,TEXT(" "));const FString Pk=Ls[V9Rng.RandRange(0,Ls.Num()-1)];
|
| 180 |
+
for(int32 I=0;I<8;I++)if(Pk==V10LightNames[I])P=I;
|
| 181 |
+
}
|
| 182 |
+
L.Light=P;L.LightName=V10LightNames[P];
|
| 183 |
+
float Pitch=-30,Yaw=R(-180.f,180.f),SunMul=1,SkyMul=1,FogMul=1,VolExt=.6f,Scatter=1;FLinearColor SunC(1,1,1),FogC(.6f,.65f,.72f);
|
| 184 |
+
// v10b: sun-and-shadow driven presets (fog only as light aerial haze: in the top-down orthographic view heavy fog just greys the
|
| 185 |
+
// picture), exposure lifted to at least the baseline brightness
|
| 186 |
+
switch(P)
|
| 187 |
+
{
|
| 188 |
+
case 0: Pitch=-R(12.f,22.f);SunMul=R(1.3f,1.8f);SunC=FLinearColor(1.f,R(.68f,.78f),R(.45f,.56f));SkyMul=R(.8f,1.f);FogMul=R(1.f,1.3f);FogC=FLinearColor(.9f,.7f,.5f);VolExt=.4f;Scatter=1.5f;
|
| 189 |
+
L.Temp=R(6800.f,7500.f);L.Sat=R(1.02f,1.12f);L.Ev=R(.3f,.7f);break;
|
| 190 |
+
case 1: Pitch=-R(18.f,30.f);SunMul=R(1.f,1.3f);SunC=FLinearColor(1.f,.9f,.78f);SkyMul=R(.95f,1.15f);FogMul=R(1.6f,2.4f);FogC=FLinearColor(.7f,.74f,.8f);VolExt=.6f;Scatter=2.f;
|
| 191 |
+
L.Temp=6400.f;L.Sat=R(.9f,1.f);L.Ev=R(.4f,.7f);break;
|
| 192 |
+
case 2: Pitch=-R(45.f,70.f);SunMul=R(.3f,.45f);SunC=FLinearColor(.94f,.96f,1.f);SkyMul=R(1.4f,1.8f);FogMul=R(1.f,1.3f);FogC=FLinearColor(.62f,.66f,.72f);VolExt=.4f;
|
| 193 |
+
L.Temp=6500.f;L.Sat=R(.88f,.98f);L.Ev=R(.5f,.8f);break;
|
| 194 |
+
case 3: Pitch=-R(50.f,70.f);SunMul=R(1.3f,1.6f);SunC=FLinearColor(1.f,.97f,.93f);SkyMul=R(.85f,1.f);FogMul=R(.7f,1.f);
|
| 195 |
+
L.Temp=6000.f;L.Sat=R(.98f,1.08f);L.Ev=R(0.f,.3f);break;
|
| 196 |
+
case 4: Pitch=-R(20.f,32.f);Yaw=(Player?Player->CameraBoom->GetComponentRotation().Yaw:0.f)+180.f+R(-35.f,35.f);SunMul=R(1.4f,1.8f);SunC=FLinearColor(1.f,.84f,.66f);
|
| 197 |
+
SkyMul=R(.75f,.95f);FogMul=R(1.2f,1.6f);FogC=FLinearColor(.88f,.74f,.58f);VolExt=.5f;Scatter=2.5f;L.Temp=7000.f;L.Sat=R(1.f,1.08f);L.Ev=R(.4f,.7f);break;
|
| 198 |
+
case 5: Pitch=-R(6.f,12.f);SunMul=R(.5f,.7f);SunC=FLinearColor(.95f,.68f,.62f);SkyMul=R(.6f,.75f);FogMul=R(1.1f,1.5f);FogC=FLinearColor(.45f,.48f,.62f);VolExt=.5f;
|
| 199 |
+
L.Temp=5600.f;L.Sat=.95f;L.Ev=R(.8f,1.2f);break;
|
| 200 |
+
case 6: // v10 real v2: moonlit night (cold, low sun = moon, dark sky; exposure kept low so it stays a night picture)
|
| 201 |
+
Pitch=-R(35.f,65.f);SunMul=R(.08f,.14f);SunC=FLinearColor(.55f,.66f,1.f);SkyMul=R(.25f,.4f);FogMul=R(.8f,1.2f);FogC=FLinearColor(.06f,.08f,.14f);VolExt=.5f;
|
| 202 |
+
L.Temp=R(4300.f,5000.f);L.Sat=R(.6f,.75f);L.Ev=R(.2f,.9f);break;
|
| 203 |
+
default: // v10 real v2: storm (dim flat light, heavy haze, desaturated)
|
| 204 |
+
Pitch=-R(40.f,70.f);SunMul=R(.08f,.16f);SunC=FLinearColor(.85f,.9f,1.f);SkyMul=R(1.f,1.3f);FogMul=R(2.2f,3.2f);FogC=FLinearColor(.42f,.45f,.5f);VolExt=.6f;
|
| 205 |
+
L.Temp=6200.f;L.Sat=R(.7f,.85f);L.Ev=R(.1f,.4f);break;
|
| 206 |
+
}
|
| 207 |
+
FLinearColor SkyC(1.f,1.f,1.f);
|
| 208 |
+
if(V10Real)
|
| 209 |
+
{ // v10 real: the host scenes are lit for a stylised look (1 lux bluish sun, 3.4x bluish ambient cubemap): flat, cyan-grey ground.
|
| 210 |
+
// A photo needs the sun to dominate in sunny looks and a neutral ambient: sun up, sky down, sky tint neutralised
|
| 211 |
+
const float SunBoost=P==0?3.f:P==3?3.5f:P==4?3.f:P==5?2.f:P==1?2.f:P==2?1.5f:1.f;
|
| 212 |
+
const float SkyCut=P==6?1.f:P==7?.8f:P==2?.75f:.45f;
|
| 213 |
+
SunMul*=SunBoost;SkyMul*=SkyCut;
|
| 214 |
+
SkyC=P==0?FLinearColor(.93f,.96f,1.f):P==1?FLinearColor(1.f,.96f,.9f):P==2?FLinearColor(1.f,.95f,.88f):P==3?FLinearColor(1.f,.96f,.9f):
|
| 215 |
+
P==4?FLinearColor(.95f,.97f,1.f):P==5?FLinearColor(1.f,.9f,.88f):P==6?FLinearColor(.75f,.85f,1.f):FLinearColor(.96f,.97f,1.f); // golden / backlit: cool shadows vs the warm sun
|
| 216 |
+
}
|
| 217 |
+
if(UDirectionalLightComponent* S=V10Sun.Get())
|
| 218 |
+
{
|
| 219 |
+
S->SetWorldRotation(FRotator(Pitch,Yaw,0));S->SetIntensity(V10SunI0*SunMul);S->SetLightColor(SunC);S->SetVolumetricScatteringIntensity(Scatter);
|
| 220 |
+
S->bCastVolumetricShadow=true;if(V10Real)S->SetLightSourceAngle(P==2?R(2.5f,4.f):R(.6f,1.6f));S->MarkRenderStateDirty();
|
| 221 |
+
}
|
| 222 |
+
if(USkyLightComponent* K=V10Sky.Get()){K->SetIntensity(V10SkyI0*SkyMul);if(V10Real)K->SetLightColor(SkyC);K->RecaptureSky();}
|
| 223 |
+
if(UExponentialHeightFogComponent* F=V10Fog.Get())
|
| 224 |
+
{
|
| 225 |
+
F->SetFogDensity(V10FogD0*FogMul);F->SetFogInscatteringColor(FogC);F->SetVolumetricFog(true);
|
| 226 |
+
F->SetVolumetricFogExtinctionScale(VolExt);F->SetVolumetricFogScatteringDistribution(.75f);F->SetVolumetricFogDistance(15000.f);
|
| 227 |
+
}
|
| 228 |
+
L.Con=R(1.04f,1.14f);L.Gam=1.f;L.Gain=FLinearColor::White;
|
| 229 |
+
L.Grain=V10Real?R(.02f,.08f):R(.08f,.22f);L.Vig=R(.2f,.38f);L.Bloom=R(.4f,.75f); // v10 real: lighter grain (it smeared the fine ground cover)
|
| 230 |
+
if(V10Real&&P<6)
|
| 231 |
+
{ // v10 real: without the distance-field / Lumen halos under the ground cover the frames came out over-exposed, cool and milky
|
| 232 |
+
// (a warm leaf-litter ground rendered pale cyan-grey): less exposure, warmer white balance, a little more saturation, less bloom
|
| 233 |
+
// (calibrated on scene 07 after the sun / sky rebalance above; all scenes now use the same absolute lights / exposure)
|
| 234 |
+
L.Ev-=P==3?1.35f:P==2?1.35f:P==5?0.f:P==1?.2f:P==0?.3f:.55f;
|
| 235 |
+
if(P!=0&&P!=4)L.Temp=FMath::Max(L.Temp,6500.f)+R(100.f,450.f);
|
| 236 |
+
L.Sat=FMath::Min(L.Sat*R(1.04f,1.12f),1.15f);L.Con=R(1.08f,1.18f);L.Bloom=R(.2f,.4f);
|
| 237 |
+
}
|
| 238 |
+
const float Sp=R(0.f,.05f);L.ShTint=FLinearColor(1.f-Sp*.6f,1.f-Sp*.1f,1.f+Sp);L.HiTint=FLinearColor(1.f+Sp,1.f+Sp*.3f,1.f-Sp*.8f);
|
| 239 |
+
L.SunPitch=Pitch;L.SunYaw=Yaw;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
void APipelineCapture::V10BeforeRGB(USceneCaptureComponent2D* C)
|
| 243 |
+
{
|
| 244 |
+
const FV9Look& L=V9Cur;auto& PP=C->PostProcessSettings;
|
| 245 |
+
if(!V10EvInit){V10EvInit=true;V10Ev0=PP.bOverride_AutoExposureBias?PP.AutoExposureBias:0.f;if(V10Real)V10Ev0=1.6f;} // v10 real: absolute (scene 07: volume 1.0 + art pass .6)
|
| 246 |
+
PP.bOverride_AutoExposureBias=true;PP.AutoExposureBias=V10Ev0+L.Ev;
|
| 247 |
+
PP.bOverride_FilmGrainIntensity=true;PP.FilmGrainIntensity=L.Grain;
|
| 248 |
+
PP.bOverride_VignetteIntensity=true;PP.VignetteIntensity=L.Vig;
|
| 249 |
+
PP.bOverride_BloomIntensity=true;PP.BloomIntensity=L.Bloom;
|
| 250 |
+
PP.bOverride_SceneFringeIntensity=true;PP.SceneFringeIntensity=.15f;
|
| 251 |
+
PP.bOverride_ColorGainShadows=true;PP.ColorGainShadows=FVector4(L.ShTint.R,L.ShTint.G,L.ShTint.B,1.f);
|
| 252 |
+
PP.bOverride_ColorGainHighlights=true;PP.ColorGainHighlights=FVector4(L.HiTint.R,L.HiTint.G,L.HiTint.B,1.f);
|
| 253 |
+
// v10b render quality: higher Lumen gather / scene / reflection quality, stronger AO, contact shadows, a little more sharpening
|
| 254 |
+
PP.bOverride_LumenFinalGatherQuality=true;PP.LumenFinalGatherQuality=4.f;PP.bOverride_LumenSceneLightingQuality=true;PP.LumenSceneLightingQuality=4.f;
|
| 255 |
+
PP.bOverride_LumenSceneDetail=true;PP.LumenSceneDetail=4.f;PP.bOverride_LumenReflectionQuality=true;PP.LumenReflectionQuality=4.f;
|
| 256 |
+
PP.bOverride_AmbientOcclusionIntensity=true;PP.AmbientOcclusionIntensity=.65f;PP.bOverride_AmbientOcclusionRadius=true;PP.AmbientOcclusionRadius=180.f;
|
| 257 |
+
if(V10Real) // the art pass (v7) flattened local contrast for the stylised scenes; a photo keeps it
|
| 258 |
+
{
|
| 259 |
+
PP.bOverride_LocalExposureHighlightContrastScale=true;PP.LocalExposureHighlightContrastScale=1.f;
|
| 260 |
+
PP.bOverride_LocalExposureShadowContrastScale=true;PP.LocalExposureShadowContrastScale=.92f;
|
| 261 |
+
}
|
| 262 |
+
if(V10Real&&V10AOFix) // v10 real: dense scanned grass / shrubs went black under the 1.8 m SSAO + Lumen short-range AO; keep a little contact AO only
|
| 263 |
+
{
|
| 264 |
+
PP.AmbientOcclusionIntensity=.25f;PP.AmbientOcclusionRadius=50.f;
|
| 265 |
+
PP.bOverride_LumenAmbientOcclusionIntensity=true;PP.LumenAmbientOcclusionIntensity=.35f;
|
| 266 |
+
}
|
| 267 |
+
if(!V10QualityInit)
|
| 268 |
+
{
|
| 269 |
+
V10QualityInit=true;
|
| 270 |
+
for(const TPair<const TCHAR*,float>& Q:{TPair<const TCHAR*,float>(TEXT("r.Tonemapper.Sharpen"),.7f),TPair<const TCHAR*,float>(TEXT("r.ContactShadows"),1.f),
|
| 271 |
+
TPair<const TCHAR*,float>(TEXT("r.Lumen.ScreenProbeGather.ScreenSpaceBentNormal"),V10Real&&V10AOFix?0.f:1.f),TPair<const TCHAR*,float>(TEXT("r.Shadow.Virtual.ResolutionLodBiasDirectional"),-1.5f)})
|
| 272 |
+
if(IConsoleVariable* V=IConsoleManager::Get().FindConsoleVariable(Q.Key))V->Set(Q.Value,ECVF_SetByCode);
|
| 273 |
+
if(UDirectionalLightComponent* S=V10Sun.Get()){S->ContactShadowLength=.06f;S->MarkRenderStateDirty();}
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
void APipelineCapture::V10LookJson(TSharedPtr<FJsonObject> J)
|
| 278 |
+
{
|
| 279 |
+
const FV9Look& L=V9Cur;
|
| 280 |
+
V10RealLookJson(J);
|
| 281 |
+
J->SetStringField(TEXT("light"),L.LightName);J->SetStringField(TEXT("biome"),L.Biome);J->SetStringField(TEXT("pbr_theme"),L.Mat==5?V10Theme:FString());
|
| 282 |
+
J->SetArrayField(TEXT("sun_pitch_yaw"),{MakeShared<FJsonValueNumber>(L.SunPitch),MakeShared<FJsonValueNumber>(L.SunYaw)});
|
| 283 |
+
J->SetArrayField(TEXT("grain_vignette_bloom_ev"),{MakeShared<FJsonValueNumber>(L.Grain),MakeShared<FJsonValueNumber>(L.Vig),MakeShared<FJsonValueNumber>(L.Bloom),MakeShared<FJsonValueNumber>(L.Ev)});
|
| 284 |
+
}
|
code/ue_capture/PipelineCaptureV10Real.cpp
ADDED
|
@@ -0,0 +1,695 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// v10 real (-DatasetV10Real, needs -DatasetV9): photoreal outdoor biomes built at run time on the scene's walkable ground,
|
| 2 |
+
// recorded in exactly the v9 data format (RGB / ids / depth / whitebox / capsule characters, cut grid, centred camera).
|
| 3 |
+
// * the authored set dressing (classes 3-6) is hidden and loses its collision; the authored ground / paving keep their
|
| 4 |
+
// collision (the gameplay walks on it) but are not rendered
|
| 5 |
+
// * a new ground surface: a height field traced from the authored ground (80 cm grid over the area the bot visits), with a
|
| 6 |
+
// little natural relief away from the route; it gets the photo-scanned PBR sets of the current biome variant (M_V10PBR)
|
| 7 |
+
// * v10 real v2 (diversity): every look (= camera variant, only on the v9 cut grid) rolls a new biome variant out of 12
|
| 8 |
+
// (conifer forest, autumn wood, spring meadow, dry savanna, semi desert, rocky coast, snow alpine, rain wetland, rock
|
| 9 |
+
// badlands, mossy old wood, red canyon, sand beach): asset mix, ground / slope / cover PBR sets, foliage season tint,
|
| 10 |
+
// snow / moss / dust / sand cover on the models, wetness, density multipliers and the light presets that suit it
|
| 11 |
+
// (incl. night and storm). The CC0 photo-scanned assets (Poly Haven) are re-scattered as Nanite instances with
|
| 12 |
+
// noise-driven patches; objects that would block the route keep a clearance from the route and the spawns; ground
|
| 13 |
+
// cover (grass, debris) is labelled ground, rocks 4, plants / trees / logs 5, props 6
|
| 14 |
+
// * perspective telephoto camera (FOV 22-40 deg) replacing the orthographic one: same framing (the v9 frame width at the
|
| 15 |
+
// player), camera pulled back along the view axis
|
| 16 |
+
// -DatasetV10Real [-DatasetV10Biome=<variant>|forest|meadow|arid|coast] [-DatasetV10Density=1] [-DatasetV10FovMin=22 -DatasetV10FovMax=40]
|
| 17 |
+
#include "PipelineCapture.h"
|
| 18 |
+
#include "PipelineWhitebox.h"
|
| 19 |
+
#include "GameDemo.h"
|
| 20 |
+
#include "Camera/CameraTypes.h"
|
| 21 |
+
#include "Components/StaticMeshComponent.h"
|
| 22 |
+
#include "Components/InstancedStaticMeshComponent.h"
|
| 23 |
+
#include "Components/SceneCaptureComponent2D.h"
|
| 24 |
+
#include "Engine/StaticMesh.h"
|
| 25 |
+
#include "Engine/Texture.h"
|
| 26 |
+
#include "GameFramework/SpringArmComponent.h"
|
| 27 |
+
#include "Materials/MaterialInterface.h"
|
| 28 |
+
#include "Materials/Material.h"
|
| 29 |
+
#include "Components/ExponentialHeightFogComponent.h"
|
| 30 |
+
#include "Components/LocalLightComponent.h"
|
| 31 |
+
#include "Components/DecalComponent.h"
|
| 32 |
+
#include "Materials/MaterialInstanceDynamic.h"
|
| 33 |
+
#include "MeshDescription.h"
|
| 34 |
+
#include "StaticMeshAttributes.h"
|
| 35 |
+
#include "EngineUtils.h"
|
| 36 |
+
#include "Misc/CommandLine.h"
|
| 37 |
+
#include "HAL/IConsoleManager.h"
|
| 38 |
+
#include "Misc/FileHelper.h"
|
| 39 |
+
#include "Misc/Paths.h"
|
| 40 |
+
#include "Dom/JsonObject.h"
|
| 41 |
+
#include "Serialization/JsonReader.h"
|
| 42 |
+
#include "Serialization/JsonSerializer.h"
|
| 43 |
+
|
| 44 |
+
namespace
|
| 45 |
+
{
|
| 46 |
+
// kinds: base instances per m2 of the visited zone per base biome (forest / meadow / arid / coast) and patch threshold of the kind's noise
|
| 47 |
+
struct FV10KindCfg{const TCHAR* Kind;float Dens[4];float Cut[4];int32 Sem;bool Big;};
|
| 48 |
+
const FV10KindCfg V10Kinds[]={
|
| 49 |
+
{TEXT("grass"), {2.f,4.5f,.45f,.3f}, {-.05f,-.3f,.25f,.3f}, 1,false},
|
| 50 |
+
{TEXT("plant"), {.35f,.6f,.25f,.15f}, {0.f,-.15f,.05f,.2f}, 5,false},
|
| 51 |
+
{TEXT("debris"),{.12f,.03f,.06f,.02f}, {-.1f,.3f,.1f,.3f}, 1,false},
|
| 52 |
+
{TEXT("rock"), {.06f,.03f,.14f,.14f}, {-.1f,.2f,-.3f,-.4f}, 4,false}, // small rocks (< 70 cm); bigger ones use the "rockbig" entry
|
| 53 |
+
{TEXT("rockbig"),{.010f,.005f,.016f,.02f},{-1.f,-1.f,-1.f,-1.f},4,true},
|
| 54 |
+
{TEXT("shrub"), {.08f,.045f,.06f,.02f},{-.2f,-.1f,-.3f,0.f}, 5,true},
|
| 55 |
+
{TEXT("log"), {.006f,.0025f,.003f,.002f},{-1.f,-1.f,-1.f,-1.f},5,true},
|
| 56 |
+
{TEXT("tree"), {.05f,.01f,.008f,.004f},{-.4f,-.2f,-1.f,-1.f},5,true},
|
| 57 |
+
{TEXT("prop"), {.0012f,.0012f,.0012f,.0018f},{-1.f,-1.f,-1.f,-1.f},6,true}};
|
| 58 |
+
// biome variants (one per look)
|
| 59 |
+
struct FV10Variant
|
| 60 |
+
{
|
| 61 |
+
const TCHAR* Name;const TCHAR* Assets;int32 Base;float Mul[9];
|
| 62 |
+
const TCHAR* Ground;const TCHAR* Side;const TCHAR* Cover;float GCov0,GCov1;
|
| 63 |
+
FLinearColor Fol0,Fol1;FLinearColor Cov;float Cov0,Cov1,CovRough;float Wet;const TCHAR* Lights;
|
| 64 |
+
};
|
| 65 |
+
const TCHAR* GForestG=TEXT("ph_forest_ground_04 ph_forest_leaves_02 ph_forest_leaves_04 ph_forrest_ground_01 ph_brown_mud_leaves_01");
|
| 66 |
+
const TCHAR* GMossySide=TEXT("ph_mossy_rock ph_rock_pitted_mossy ph_lichen_rock ph_rock_ground ph_cliff_side");
|
| 67 |
+
const TCHAR* GRockSide=TEXT("ph_rock_ground ph_lichen_rock ph_cliff_side ph_gray_rocks");
|
| 68 |
+
const TCHAR* GDrySide=TEXT("ph_rock_boulder_dry ph_rock_face_03 ph_cliff_side ph_rock_ground_02");
|
| 69 |
+
const TCHAR* GAllDay=TEXT("golden mist overcast noon backlit dusk");
|
| 70 |
+
const FV10Variant V10Vars[]={
|
| 71 |
+
{TEXT("conifer_forest"),TEXT("forest"),0,{1,1,1,1,1,1,1,1.2f,1},GForestG,GMossySide,TEXT("ph_forest_leaves_02 ph_forest_leaves_04 ph_brown_mud_leaves_01 ph_moss_wood"),.1f,.4f,
|
| 72 |
+
FLinearColor(.95f,1.02f,.9f),FLinearColor(1.f,1.f,1.f),FLinearColor(.26f,.34f,.13f),0.f,.25f,.9f,0.f,GAllDay},
|
| 73 |
+
{TEXT("autumn_wood"),TEXT("forest meadow"),0,{.7f,.6f,1.6f,1,1,1.2f,1.5f,1,1},TEXT("ph_forest_leaves_02 ph_forest_leaves_04 ph_brown_mud_leaves_01 ph_forrest_ground_01"),GMossySide,
|
| 74 |
+
TEXT("ph_forest_leaves_02 ph_forest_leaves_04 ph_brown_mud_leaves_01"),.3f,.6f,FLinearColor(1.5f,.85f,.32f),FLinearColor(1.3f,.55f,.24f),FLinearColor(.5f,.27f,.1f),0.f,.2f,.85f,0.f,
|
| 75 |
+
TEXT("golden mist overcast backlit dusk")},
|
| 76 |
+
{TEXT("spring_meadow"),TEXT("meadow"),1,{1.2f,1.5f,1,1,1,1,1,1,1},TEXT("ph_leafy_grass ph_grass_path_2 ph_brown_mud_leaves_01 ph_forest_ground_04"),GRockSide,
|
| 77 |
+
TEXT("ph_leafy_grass ph_grass_path_2 ph_brown_mud_leaves_01"),.12f,.4f,FLinearColor(.92f,1.14f,.82f),FLinearColor(1.f,1.06f,.9f),FLinearColor(.3f,.4f,.15f),0.f,.15f,.9f,0.f,GAllDay},
|
| 78 |
+
{TEXT("dry_savanna"),TEXT("meadow arid"),1,{.8f,.5f,.5f,1,1,.8f,.5f,.6f,1},TEXT("ph_brown_mud_dry ph_dry_ground_rocks ph_gravelly_sand ph_red_laterite_soil_stones"),GDrySide,
|
| 79 |
+
TEXT("ph_sand_01 ph_gravelly_sand ph_brown_mud_dry"),.1f,.35f,FLinearColor(1.32f,1.05f,.52f),FLinearColor(1.2f,.95f,.6f),FLinearColor(.62f,.52f,.4f),0.f,.2f,.9f,0.f,
|
| 80 |
+
TEXT("golden noon backlit dusk overcast")},
|
| 81 |
+
{TEXT("semi_desert"),TEXT("arid"),2,{1,1,1,1,1,1,1,1,1},TEXT("ph_dry_ground_rocks ph_brown_mud_dry ph_red_laterite_soil_stones ph_red_mud_stones ph_gravelly_sand ph_rocky_terrain ph_aerial_rocks_02"),
|
| 82 |
+
GDrySide,TEXT("ph_sand_01 ph_gravelly_sand ph_brown_mud_dry"),.12f,.4f,FLinearColor(1.f,1.f,1.f),FLinearColor(1.08f,1.f,.85f),FLinearColor(.66f,.55f,.42f),0.f,.15f,.9f,0.f,
|
| 83 |
+
TEXT("golden noon backlit dusk overcast night")},
|
| 84 |
+
{TEXT("rocky_coast"),TEXT("coast"),3,{1,1,1,1.2f,1.2f,1,1,1,1},TEXT("ph_coast_sand_01 ph_coast_sand_05 ph_coast_sand_rocks_02 ph_coast_land_rocks_01 ph_aerial_beach_01 ph_clean_pebbles ph_gravelly_sand"),
|
| 85 |
+
TEXT("ph_coast_land_rocks_01 ph_cliff_side ph_gray_rocks ph_rock_ground"),TEXT("ph_coast_sand_01 ph_clean_pebbles ph_gravelly_sand"),.12f,.4f,FLinearColor(1.f,1.f,1.f),FLinearColor(.95f,1.02f,.95f),
|
| 86 |
+
FLinearColor(.78f,.72f,.6f),0.f,.2f,.85f,0.f,TEXT("golden mist overcast noon backlit dusk storm")},
|
| 87 |
+
{TEXT("snow_alpine"),TEXT("forest coast"),0,{.12f,.1f,.3f,1.2f,1.3f,.6f,.8f,1.2f,.6f},TEXT("ph_snow_01 ph_snow_02 ph_snow_field_aerial"),TEXT("ph_rock_ground ph_gray_rocks ph_cliff_side"),
|
| 88 |
+
TEXT("ph_snow_01 ph_snow_02"),.35f,.7f,FLinearColor(.8f,.88f,.92f),FLinearColor(.95f,.98f,1.f),FLinearColor(.92f,.94f,.98f),.45f,.85f,.6f,0.f,TEXT("overcast noon golden mist storm night")},
|
| 89 |
+
{TEXT("rain_wetland"),TEXT("meadow forest"),1,{1.1f,1.2f,.8f,.8f,.8f,1.2f,1,.8f,1},TEXT("ph_brown_mud ph_brown_mud_02 ph_brown_mud_03 ph_brown_mud_leaves_01"),GMossySide,
|
| 90 |
+
TEXT("ph_brown_mud_leaves_01 ph_moss_wood"),.15f,.45f,FLinearColor(.82f,1.f,.78f),FLinearColor(.9f,1.05f,.85f),FLinearColor(.14f,.19f,.08f),.08f,.3f,.85f,1.f,TEXT("overcast mist storm")},
|
| 91 |
+
{TEXT("rock_badlands"),TEXT("arid coast"),2,{.2f,.3f,.6f,1.6f,1.5f,.5f,.3f,.3f,.6f},
|
| 92 |
+
TEXT("ph_rock_ground ph_rock_ground_02 ph_rocks_ground_01 ph_rocks_ground_02 ph_rocks_ground_04 ph_rocks_ground_05 ph_rocks_ground_06 ph_aerial_rocks_01 ph_aerial_rocks_02 ph_aerial_rocks_04 ph_gray_rocks"),
|
| 93 |
+
GRockSide,TEXT("ph_gravelly_sand ph_clean_pebbles"),.05f,.25f,FLinearColor(1.15f,1.f,.7f),FLinearColor(1.05f,.95f,.75f),FLinearColor(.5f,.48f,.45f),0.f,.3f,.9f,0.f,
|
| 94 |
+
TEXT("golden mist overcast noon backlit dusk night storm")},
|
| 95 |
+
{TEXT("mossy_oldwood"),TEXT("forest"),0,{.6f,1.2f,1.6f,1.3f,1.2f,1.3f,2.f,1.3f,1},TEXT("ph_forest_ground_04 ph_forrest_ground_01 ph_forest_leaves_04 ph_brown_mud_leaves_01"),GMossySide,
|
| 96 |
+
TEXT("ph_moss_wood ph_mossy_rock ph_forest_leaves_04"),.3f,.6f,FLinearColor(.78f,1.f,.72f),FLinearColor(.9f,1.05f,.85f),FLinearColor(.13f,.19f,.07f),.2f,.45f,.85f,.5f,
|
| 97 |
+
TEXT("mist overcast backlit golden")},
|
| 98 |
+
{TEXT("red_canyon"),TEXT("arid"),2,{.4f,.6f,.6f,1.3f,1.4f,.8f,.5f,.5f,1},TEXT("ph_red_laterite_soil_stones ph_red_mud_stones"),GDrySide,
|
| 99 |
+
TEXT("ph_red_laterite_soil_stones ph_red_mud_stones"),.1f,.35f,FLinearColor(1.2f,1.f,.65f),FLinearColor(1.1f,.95f,.7f),FLinearColor(.62f,.36f,.24f),.15f,.4f,.9f,0.f,TEXT("golden noon backlit dusk")},
|
| 100 |
+
{TEXT("sand_beach"),TEXT("coast"),3,{.5f,.6f,.5f,.6f,.6f,.5f,.5f,0.f,1.5f},TEXT("ph_coast_sand_01 ph_coast_sand_05 ph_aerial_beach_01 ph_gravelly_sand"),
|
| 101 |
+
TEXT("ph_coast_land_rocks_01 ph_gray_rocks"),TEXT("ph_coast_sand_01 ph_coast_sand_05"),.15f,.45f,FLinearColor(1.05f,1.02f,.85f),FLinearColor(1.f,1.f,1.f),FLinearColor(.8f,.72f,.58f),0.f,.3f,.9f,0.f,
|
| 102 |
+
TEXT("golden noon overcast backlit dusk")}};
|
| 103 |
+
const int32 V10NumVars=UE_ARRAY_COUNT(V10Vars);
|
| 104 |
+
struct FV10Season{const TCHAR* Var;FLinearColor Col;float A0,A1;bool FolCov;};
|
| 105 |
+
const FV10Season V10Seasons[]={{TEXT("autumn_wood"),FLinearColor(1.f,.42f,.1f),.55f,.95f,false},{TEXT("dry_savanna"),FLinearColor(.88f,.72f,.32f),.45f,.75f,true},
|
| 106 |
+
{TEXT("snow_alpine"),FLinearColor(.62f,.7f,.66f),.2f,.4f,true},{TEXT("spring_meadow"),FLinearColor(.5f,.95f,.25f),.1f,.3f,false},{TEXT("semi_desert"),FLinearColor(.75f,.78f,.45f),0.f,.3f,true},
|
| 107 |
+
{TEXT("red_canyon"),FLinearColor(.8f,.7f,.35f),.2f,.5f,true},{TEXT("sand_beach"),FLinearColor(.75f,.8f,.5f),0.f,.25f,true},{TEXT("rock_badlands"),FLinearColor(.8f,.7f,.4f),.2f,.5f,true},
|
| 108 |
+
{TEXT("rocky_coast"),FLinearColor(.6f,.8f,.4f),0.f,.2f,true}};
|
| 109 |
+
const FV10Season* V10SeasonOf(const TCHAR* Var){for(const FV10Season& S:V10Seasons)if(FCString::Strcmp(S.Var,Var)==0)return &S;return nullptr;}
|
| 110 |
+
struct FV10Mesh{UStaticMesh* Mesh=nullptr;FString Id,Kind;FVector Size=FVector::ZeroVector;float MinZ=0;bool Foliage=false;TArray<UMaterialInterface*> Mats;TArray<FString> Biomes;};
|
| 111 |
+
TArray<FV10Mesh> GV10All; // the whole catalog (loaded once, kept by V10RealKeep)
|
| 112 |
+
int32 V10SemOf(const AActor* A){int32 Id=-1;if(A)for(const FName& T:A->Tags){FString S=T.ToString();if(S.RemoveFromStart(TEXT("semantic:")))Id=FCString::Atoi(*S);}return Id;}
|
| 113 |
+
// FRandomStream is a plain LCG: neighbouring seeds give correlated first draws (the same first biome in every run), so
|
| 114 |
+
// per-look seeds go through a splitmix64 finaliser first
|
| 115 |
+
int32 V10Mix(int64 A,int64 B){uint64 Z=uint64(A)*0x9E3779B97F4A7C15ull+uint64(B)*0xBF58476D1CE4E5B9ull+0x94D049BB133111EBull;Z=(Z^(Z>>30))*0xBF58476D1CE4E5B9ull;Z=(Z^(Z>>27))*0x94D049BB133111EBull;Z^=Z>>31;return int32(Z&0x7fffffff);}
|
| 116 |
+
float V10Fbm(float X,float Y,float S,float O){return FMath::PerlinNoise2D(FVector2D(X/S+O,Y/S-O*.7f))*.65f+FMath::PerlinNoise2D(FVector2D(X/(S*.37f)-O,Y/(S*.37f)+O*1.3f))*.35f;}
|
| 117 |
+
bool V10IsFoliageMat(const UMaterialInterface* M){const UMaterial* B=M?M->GetMaterial():nullptr;return B&&B->GetName().Contains(TEXT("Foliage"));}
|
| 118 |
+
|
| 119 |
+
UStaticMesh* V10BuildGrid(UObject* Outer,const TArray<FVector3f>& P,const TArray<FVector3f>& N,const TArray<int32>& Tri,UMaterialInterface* Mat)
|
| 120 |
+
{
|
| 121 |
+
if(Tri.Num()<3)return nullptr;
|
| 122 |
+
FMeshDescription MD;FStaticMeshAttributes Attr(MD);Attr.Register();
|
| 123 |
+
TVertexAttributesRef<FVector3f> Pos=Attr.GetVertexPositions();
|
| 124 |
+
TVertexInstanceAttributesRef<FVector3f> Nrm=Attr.GetVertexInstanceNormals(),Tan=Attr.GetVertexInstanceTangents();
|
| 125 |
+
TVertexInstanceAttributesRef<float> Sgn=Attr.GetVertexInstanceBinormalSigns();
|
| 126 |
+
TVertexInstanceAttributesRef<FVector2f> UVs=Attr.GetVertexInstanceUVs();if(UVs.GetNumChannels()<1)UVs.SetNumChannels(1);
|
| 127 |
+
MD.ReserveNewVertices(P.Num());MD.ReserveNewVertexInstances(P.Num());MD.ReserveNewTriangles(Tri.Num()/3);MD.ReserveNewEdges(Tri.Num());
|
| 128 |
+
const FPolygonGroupID G=MD.CreatePolygonGroup();Attr.GetPolygonGroupMaterialSlotNames()[G]=FName(TEXT("M0"));
|
| 129 |
+
TArray<FVertexInstanceID> VI;VI.SetNum(P.Num());
|
| 130 |
+
for(int32 I=0;I<P.Num();I++)
|
| 131 |
+
{
|
| 132 |
+
const FVertexID V=MD.CreateVertex();Pos[V]=P[I];
|
| 133 |
+
const FVertexInstanceID X=MD.CreateVertexInstance(V);VI[I]=X;
|
| 134 |
+
FVector3f T=FVector3f(1,0,0)-N[I]*N[I].X;T.Normalize();
|
| 135 |
+
Nrm[X]=N[I];Tan[X]=T;Sgn[X]=1.f;UVs.Set(X,0,FVector2f(P[I].X/100.f,P[I].Y/100.f));
|
| 136 |
+
}
|
| 137 |
+
for(int32 I=0;I+2<Tri.Num();I+=3){FVertexInstanceID T3[3]={VI[Tri[I]],VI[Tri[I+1]],VI[Tri[I+2]]};MD.CreateTriangle(G,MakeArrayView(T3,3));}
|
| 138 |
+
UStaticMesh* SM=NewObject<UStaticMesh>(Outer);
|
| 139 |
+
SM->GetStaticMaterials().Add(FStaticMaterial(Mat,FName(TEXT("M0"))));
|
| 140 |
+
UStaticMesh::FBuildMeshDescriptionsParams BP;BP.bFastBuild=true;BP.bMarkPackageDirty=false;BP.bCommitMeshDescription=false;BP.bBuildSimpleCollision=false;
|
| 141 |
+
TArray<const FMeshDescription*> L;L.Add(&MD);
|
| 142 |
+
return SM->BuildFromMeshDescriptions(L,BP)?SM:nullptr;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
void APipelineCapture::ParseV10Real(const TCHAR* Cmd)
|
| 147 |
+
{
|
| 148 |
+
V10Real=FParse::Param(Cmd,TEXT("DatasetV10Real"));
|
| 149 |
+
if(!V10Real)return;
|
| 150 |
+
V10Photo=true;DynamicEvents=false; // the v4 dynamic events spawn authored props during the run
|
| 151 |
+
FString B;
|
| 152 |
+
if(FParse::Value(Cmd,TEXT("DatasetV10Biome="),B))
|
| 153 |
+
{
|
| 154 |
+
static const TCHAR* Old[4][2]={{TEXT("forest"),TEXT("conifer_forest")},{TEXT("meadow"),TEXT("spring_meadow")},{TEXT("arid"),TEXT("semi_desert")},{TEXT("coast"),TEXT("rocky_coast")}};
|
| 155 |
+
for(int32 I=0;I<4;I++)if(B.Equals(Old[I][0],ESearchCase::IgnoreCase))B=Old[I][1];
|
| 156 |
+
for(int32 I=0;I<V10NumVars;I++)if(B.Equals(V10Vars[I].Name,ESearchCase::IgnoreCase))V10VarForced=I;
|
| 157 |
+
}
|
| 158 |
+
{float E=0;if(FParse::Value(Cmd,TEXT("DatasetV10NaniteEdge="),E)&&E>0)if(IConsoleVariable* Cv=IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite.MaxPixelsPerEdge")))Cv->Set(E,ECVF_SetByCode);} // tests
|
| 159 |
+
FParse::Value(Cmd,TEXT("DatasetV10AOFix="),V10AOFix);FParse::Value(Cmd,TEXT("DatasetV10GrassShadow="),V10GrassShadow);FParse::Value(Cmd,TEXT("DatasetV10Light="),V10LightForced);
|
| 160 |
+
FParse::Value(Cmd,TEXT("DatasetV10Density="),V10Density);FParse::Value(Cmd,TEXT("DatasetV10FovMin="),V10FovMin);FParse::Value(Cmd,TEXT("DatasetV10FovMax="),V10FovMax);
|
| 161 |
+
int32 Seed=0;FParse::Value(Cmd,TEXT("DatasetSeed="),Seed);V10RealSeed=Seed*7307+101;
|
| 162 |
+
V10Fov=.5f*(V10FovMin+V10FovMax);
|
| 163 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 real v2: %d biome variants, forced '%s' density %.2f fov %.0f-%.0f"),V10NumVars,V10VarForced>=0?V10Vars[V10VarForced].Name:TEXT("-"),V10Density,V10FovMin,V10FovMax);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
bool APipelineCapture::V10HfAt(float X,float Y,float& Z,int32& Cls) const
|
| 167 |
+
{
|
| 168 |
+
if(V10HfNX<2||V10HfNY<2)return false;
|
| 169 |
+
const float FX=(X-V10HfOrigin.X)/V10HfStep,FY=(Y-V10HfOrigin.Y)/V10HfStep;
|
| 170 |
+
const int32 IX=FMath::FloorToInt(FX),IY=FMath::FloorToInt(FY);
|
| 171 |
+
if(IX<0||IY<0||IX>=V10HfNX-1||IY>=V10HfNY-1)return false;
|
| 172 |
+
const float AX=FX-IX,AY=FY-IY;
|
| 173 |
+
const int32 I00=IY*V10HfNX+IX,I10=I00+1,I01=I00+V10HfNX,I11=I01+1;
|
| 174 |
+
if(!V10HfCls[I00]||!V10HfCls[I10]||!V10HfCls[I01]||!V10HfCls[I11])return false;
|
| 175 |
+
Z=FMath::Lerp(FMath::Lerp(V10HfZ[I00],V10HfZ[I10],AX),FMath::Lerp(V10HfZ[I01],V10HfZ[I11],AX),AY);
|
| 176 |
+
Cls=V10HfCls[(AY<.5f?(AX<.5f?I00:I10):(AX<.5f?I01:I11))];
|
| 177 |
+
return true;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
void APipelineCapture::V10RealBuild()
|
| 181 |
+
{
|
| 182 |
+
if(!V10Real||!Player)return;
|
| 183 |
+
UWorld* World=GetWorld();const double T0=FPlatformTime::Seconds();
|
| 184 |
+
V10LoadSets();
|
| 185 |
+
FRandomStream R(V10Mix(V10RealSeed,17));
|
| 186 |
+
// ---- 1. hide the authored scene ------------------------------------------------------------------------------
|
| 187 |
+
int32 HidA=0,HidG=0;
|
| 188 |
+
for(TActorIterator<AActor> I(World);I;++I)
|
| 189 |
+
{
|
| 190 |
+
AActor* A=*I;
|
| 191 |
+
if(A==this||Cast<AGameDemoFighter>(A)||A->ActorHasTag(TEXT("whitebox"))||A->ActorHasTag(TEXT("v10_real")))continue;
|
| 192 |
+
const int32 S=V10SemOf(A);if(S<1||S>6)continue;
|
| 193 |
+
if(S>=3){A->SetActorHiddenInGame(true);A->SetActorEnableCollision(false);HidA++;continue;}
|
| 194 |
+
TArray<UPrimitiveComponent*> Cs;A->GetComponents(Cs);
|
| 195 |
+
for(UPrimitiveComponent* C:Cs){C->SetVisibility(false,true);V10RealHiddenGround.Add(C);HidG++;}
|
| 196 |
+
}
|
| 197 |
+
// the host scenes' own lamps / neon / glow (local lights lit the volumetric fog into white halos), decals, water planes,
|
| 198 |
+
// particle systems and other unlabelled meshes do not belong in a natural biome either
|
| 199 |
+
int32 HidL=0,HidD=0,HidU=0;TMap<FString,int32> UCls;
|
| 200 |
+
for(TActorIterator<AActor> I(World);I;++I)
|
| 201 |
+
{
|
| 202 |
+
AActor* A=*I;if(A==this||A->ActorHasTag(TEXT("whitebox"))||A->ActorHasTag(TEXT("v10_real"))||A->ActorHasTag(TEXT("v4_event")))continue;
|
| 203 |
+
bool Fighter=false;for(AActor* P=A;P&&!Fighter;P=P->GetAttachParentActor())Fighter|=Cast<AGameDemoFighter>(P)!=nullptr||Cast<AGameDemoFighter>(P->GetOwner())!=nullptr;
|
| 204 |
+
if(Fighter)continue;
|
| 205 |
+
TArray<UActorComponent*> Cs;A->GetComponents(Cs);const int32 S=V10SemOf(A);const bool Unlab=S<1||S>6;
|
| 206 |
+
for(UActorComponent* C:Cs)
|
| 207 |
+
{
|
| 208 |
+
if(auto* Lc=Cast<ULocalLightComponent>(C)){if(Lc->IsVisible()){Lc->SetVisibility(false);HidL++;}continue;}
|
| 209 |
+
if(auto* Dc=Cast<UDecalComponent>(C)){if(Dc->IsVisible()){Dc->SetVisibility(false);HidD++;}continue;}
|
| 210 |
+
auto* Pc=Cast<UPrimitiveComponent>(C);
|
| 211 |
+
if(!Unlab||!Pc||!Pc->IsVisible()||Pc->bHiddenInGame||Pc->ComponentHasTag(TEXT("v8fx")))continue;
|
| 212 |
+
Pc->SetVisibility(false);HidU++;UCls.FindOrAdd(Pc->GetClass()->GetName())++;
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
{FString L;for(const auto& P:UCls)L+=FString::Printf(TEXT("%s:%d "),*P.Key,P.Value);
|
| 216 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 real: lights off %d, decals off %d, unlabelled primitives off %d (%s)"),HidL,HidD,HidU,*L);}
|
| 217 |
+
// ---- 2. height field ground ------------------------------------------------------------------------------------
|
| 218 |
+
V10S0=Player->GetAuthoredSpawnPosition();const float RefZ=Player->GetActorLocation().Z;
|
| 219 |
+
V10Anchors.Reset();V10Anchors.Add(V10S0);
|
| 220 |
+
V10SB=V10S0;if(AGameDemoFighter* B=Player->Opponent.Get()){V10SB=B->GetAuthoredSpawnPosition();V10Anchors.Add(V10SB);}
|
| 221 |
+
for(const FVector& P:Player->ExplorationWaypoints)if(FVector::Dist2D(P,V10S0)<7000.f)V10Anchors.Add(P);
|
| 222 |
+
for(const FVector& P:Player->ExplorationPlaces)if(FVector::Dist2D(P,V10S0)<7000.f)V10Anchors.Add(P);
|
| 223 |
+
FBox2D Box(ForceInit);for(const FVector& P:V10Anchors)Box+=FVector2D(P.X,P.Y);
|
| 224 |
+
Box=Box.ExpandBy(4800.f);
|
| 225 |
+
const FVector2D Ctr=Box.GetCenter();FVector2D Ext=Box.GetExtent();Ext.X=FMath::Min(Ext.X,13000.f);Ext.Y=FMath::Min(Ext.Y,13000.f);
|
| 226 |
+
V10HfNX=FMath::CeilToInt(2*Ext.X/V10HfStep)+1;V10HfNY=FMath::CeilToInt(2*Ext.Y/V10HfStep)+1;
|
| 227 |
+
V10HfOrigin=FVector(Ctr.X-Ext.X,Ctr.Y-Ext.Y,RefZ);
|
| 228 |
+
V10HfZ.SetNumZeroed(V10HfNX*V10HfNY);V10HfCls.SetNumZeroed(V10HfNX*V10HfNY);
|
| 229 |
+
FCollisionQueryParams Q(SCENE_QUERY_STAT(V10Ground),true);
|
| 230 |
+
for(TActorIterator<AGameDemoFighter> F(World);F;++F)Q.AddIgnoredActor(*F);
|
| 231 |
+
int32 Valid=0;
|
| 232 |
+
// distance to the places the gameplay uses: no relief there (the characters stand on the authored collision)
|
| 233 |
+
const FVector S0=V10S0,SB=V10SB;
|
| 234 |
+
auto Busy=[&](const FVector2D& P){float D=RouteDist2D(P);D=FMath::Min(D,FVector2D::Distance(P,FVector2D(S0)));D=FMath::Min(D,FVector2D::Distance(P,FVector2D(SB))-600.f);return D;};
|
| 235 |
+
const float Amp=R.FRandRange(8.f,26.f);
|
| 236 |
+
for(int32 Y=0;Y<V10HfNY;Y++)for(int32 X=0;X<V10HfNX;X++)
|
| 237 |
+
{
|
| 238 |
+
const float WX=V10HfOrigin.X+X*V10HfStep,WY=V10HfOrigin.Y+Y*V10HfStep;
|
| 239 |
+
FCollisionQueryParams Q2=Q;
|
| 240 |
+
for(int32 Pass=0;Pass<4;Pass++)
|
| 241 |
+
{
|
| 242 |
+
FHitResult H;
|
| 243 |
+
if(!World->LineTraceSingleByChannel(H,FVector(WX,WY,RefZ+6000),FVector(WX,WY,RefZ-6000),ECC_Visibility,Q2))break;
|
| 244 |
+
const int32 S=V10SemOf(H.GetActor());
|
| 245 |
+
if(S!=1&&S!=2){if(H.GetActor())Q2.AddIgnoredActor(H.GetActor());continue;}
|
| 246 |
+
const int32 K=Y*V10HfNX+X;
|
| 247 |
+
float Z=H.ImpactPoint.Z;
|
| 248 |
+
if(S==1)Z+=Amp*FMath::SmoothStep(350.f,1100.f,Busy(FVector2D(WX,WY)))*V10Fbm(WX,WY,900.f,3.1f);
|
| 249 |
+
V10HfZ[K]=Z;V10HfCls[K]=(uint8)S;Valid++;break; // class 2 = former paving: rendered / labelled as ground, scattered sparser
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
// holes (water, building footprints, gaps between ground pieces) take the nearest valid height; then the steps between
|
| 253 |
+
// ground pieces of different levels (platform edges: vertical walls with stretched texture) relax into slopes of at most
|
| 254 |
+
// ~30 deg. Cells near the route / spawns keep their traced height (the characters walk on the authored collision there).
|
| 255 |
+
int32 Filled=0;
|
| 256 |
+
{
|
| 257 |
+
TArray<int32> Fq;Fq.Reserve(V10HfNX*V10HfNY);for(int32 K=0;K<V10HfNX*V10HfNY;K++)if(V10HfCls[K])Fq.Add(K);
|
| 258 |
+
for(int32 H=0;H<Fq.Num();H++)
|
| 259 |
+
{
|
| 260 |
+
const int32 K=Fq[H],X=K%V10HfNX,Y=K/V10HfNX;
|
| 261 |
+
const int32 Nb[4][2]={{X-1,Y},{X+1,Y},{X,Y-1},{X,Y+1}};
|
| 262 |
+
for(const auto& B:Nb)if(B[0]>=0&&B[1]>=0&&B[0]<V10HfNX&&B[1]<V10HfNY)
|
| 263 |
+
{const int32 J=B[1]*V10HfNX+B[0];if(!V10HfCls[J]){V10HfCls[J]=1;V10HfZ[J]=V10HfZ[K];Fq.Add(J);Filled++;}}
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
{
|
| 267 |
+
TArray<float> Wt;Wt.SetNumUninitialized(V10HfNX*V10HfNY);
|
| 268 |
+
for(int32 K=0;K<V10HfNX*V10HfNY;K++)Wt[K]=FMath::SmoothStep(150.f,600.f,Busy(FVector2D(V10HfOrigin.X+(K%V10HfNX)*V10HfStep,V10HfOrigin.Y+(K/V10HfNX)*V10HfStep)));
|
| 269 |
+
const float MaxStep=.55f*V10HfStep;TArray<float> Z2=V10HfZ;
|
| 270 |
+
for(int32 It=0;It<120;It++)
|
| 271 |
+
{
|
| 272 |
+
for(int32 Y=0;Y<V10HfNY;Y++)for(int32 X=0;X<V10HfNX;X++)
|
| 273 |
+
{
|
| 274 |
+
const int32 K=Y*V10HfNX+X;if(Wt[K]<=0.f)continue;
|
| 275 |
+
float Lo=-1e9f,Hi=1e9f;
|
| 276 |
+
for(int32 DY=-1;DY<=1;DY++)for(int32 DX=-1;DX<=1;DX++)
|
| 277 |
+
{
|
| 278 |
+
if(!DX&&!DY)continue;const int32 XX=X+DX,YY=Y+DY;if(XX<0||YY<0||XX>=V10HfNX||YY>=V10HfNY)continue;
|
| 279 |
+
const float Zn=V10HfZ[YY*V10HfNX+XX],M=MaxStep*((DX&&DY)?1.414f:1.f);Lo=FMath::Max(Lo,Zn-M);Hi=FMath::Min(Hi,Zn+M);
|
| 280 |
+
}
|
| 281 |
+
const float T=Lo<=Hi?FMath::Clamp(V10HfZ[K],Lo,Hi):.5f*(Lo+Hi);
|
| 282 |
+
Z2[K]=FMath::Lerp(V10HfZ[K],T,Wt[K]);
|
| 283 |
+
}
|
| 284 |
+
V10HfZ=Z2;
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
{ // one ground surface (the authored paving becomes a natural clearing, class 1); vertices relative to the holder at the grid origin
|
| 288 |
+
TArray<int32> Map;Map.Init(-1,V10HfNX*V10HfNY);TArray<FVector3f> P,N;TArray<int32> Tri;
|
| 289 |
+
auto Vtx=[&](int32 X,int32 Y)->int32
|
| 290 |
+
{
|
| 291 |
+
const int32 K=Y*V10HfNX+X;if(Map[K]>=0)return Map[K];
|
| 292 |
+
auto Hz=[&](int32 XX,int32 YY){XX=FMath::Clamp(XX,0,V10HfNX-1);YY=FMath::Clamp(YY,0,V10HfNY-1);const int32 Q3=YY*V10HfNX+XX;return V10HfCls[Q3]?V10HfZ[Q3]:V10HfZ[K];};
|
| 293 |
+
const float DX=(Hz(X+1,Y)-Hz(X-1,Y))/(2*V10HfStep),DY=(Hz(X,Y+1)-Hz(X,Y-1))/(2*V10HfStep);
|
| 294 |
+
FVector3f Nn(-DX,-DY,1.f);Nn.Normalize();
|
| 295 |
+
Map[K]=P.Add(FVector3f(X*V10HfStep,Y*V10HfStep,V10HfZ[K]-RefZ));N.Add(Nn);return Map[K];
|
| 296 |
+
};
|
| 297 |
+
for(int32 Y=0;Y+1<V10HfNY;Y++)for(int32 X=0;X+1<V10HfNX;X++)
|
| 298 |
+
{
|
| 299 |
+
const int32 K=Y*V10HfNX+X;const uint8 C[4]={V10HfCls[K],V10HfCls[K+1],V10HfCls[K+V10HfNX],V10HfCls[K+V10HfNX+1]};
|
| 300 |
+
if(!C[0]||!C[1]||!C[2]||!C[3])continue;
|
| 301 |
+
const int32 A0=Vtx(X,Y),A1=Vtx(X+1,Y),A2=Vtx(X,Y+1),A3=Vtx(X+1,Y+1);
|
| 302 |
+
// front faces: UE triangle normal is (C-A)x(B-A) -> (v00, v01, v10) and (v10, v01, v11) face +Z
|
| 303 |
+
Tri.Append({A0,A2,A1,A1,A2,A3});
|
| 304 |
+
}
|
| 305 |
+
AActor* H=World->SpawnActor<AActor>(AActor::StaticClass(),FTransform(V10HfOrigin));
|
| 306 |
+
if(H)
|
| 307 |
+
{
|
| 308 |
+
USceneComponent* HR=NewObject<USceneComponent>(H);H->SetRootComponent(HR);HR->RegisterComponent();HR->SetWorldLocation(V10HfOrigin);
|
| 309 |
+
H->Tags.Add(FName(TEXT("semantic:1")));H->Tags.Add(TEXT("v4_event"));H->Tags.Add(TEXT("v10_real"));
|
| 310 |
+
if(UStaticMesh* M=V10BuildGrid(H,P,N,Tri,V10Mat?V10Mat.Get():nullptr))
|
| 311 |
+
{
|
| 312 |
+
V10RealKeep.Add(M);
|
| 313 |
+
auto* C=NewObject<UStaticMeshComponent>(H);C->SetupAttachment(HR);C->SetMobility(EComponentMobility::Movable);C->SetStaticMesh(M);
|
| 314 |
+
C->SetCollisionEnabled(ECollisionEnabled::NoCollision);C->SetCastShadow(true);C->ComponentTags.Add(TEXT("v10_ground"));C->SetTextureForceResidentFlag(true);
|
| 315 |
+
C->RegisterComponent();C->SetRelativeTransform(FTransform::Identity);H->AddInstanceComponent(C);V10RealGround.Add(C);
|
| 316 |
+
V10RealCounts.Add(TEXT("ground_tris"),Tri.Num()/3);
|
| 317 |
+
}
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
// ---- 3. the whole asset catalog, textures forced resident (every look re-scatters another biome) -----------------
|
| 321 |
+
GV10All.Reset();int32 NTex=0;TSet<UTexture*> SeenTex;
|
| 322 |
+
{
|
| 323 |
+
FString S;
|
| 324 |
+
if(FFileHelper::LoadFileToString(S,*(FPaths::ProjectContentDir()/TEXT("Xfer/V10/v10_models.json"))))
|
| 325 |
+
{
|
| 326 |
+
TSharedPtr<FJsonObject> O;const TSharedRef<TJsonReader<>> Rd=TJsonReaderFactory<>::Create(S);
|
| 327 |
+
const TArray<TSharedPtr<FJsonValue>>* A;
|
| 328 |
+
if(FJsonSerializer::Deserialize(Rd,O)&&O.IsValid()&&O->TryGetArrayField(TEXT("meshes"),A))for(const auto& V:*A)
|
| 329 |
+
{
|
| 330 |
+
const TSharedPtr<FJsonObject> T=V->AsObject();if(!T)continue;
|
| 331 |
+
FV10Mesh M;M.Id=T->GetStringField(TEXT("id"));M.Kind=T->GetStringField(TEXT("kind"));M.Foliage=T->GetBoolField(TEXT("foliage"));
|
| 332 |
+
{bool Skip=false;for(const TCHAR* X:{TEXT("mountainside"),TEXT("rock_face_"),TEXT("coastal_cliff_"),TEXT("coast_line_"),TEXT("coast_land_rocks_"),TEXT("namaqualand_cliff_"),TEXT("grass_medium_01"),TEXT("celandine_01")})Skip|=M.Id.StartsWith(X);
|
| 333 |
+
static TArray<FString> Excl;static bool ExclInit=false;if(!ExclInit){ExclInit=true;FString E;if(FParse::Value(FCommandLine::Get(),TEXT("DatasetV10Exclude="),E))E.ParseIntoArray(Excl,TEXT("+"));}
|
| 334 |
+
for(const FString& X:Excl)Skip|=M.Id.StartsWith(X);if(Skip)continue;}
|
| 335 |
+
// scanned cliff faces are open shells; grass_medium_01 / celandine_01 ship dirty opacity maps (grey padding blocks around the blades render as dark patches)
|
| 336 |
+
const TArray<TSharedPtr<FJsonValue>>* Bs;if(T->TryGetArrayField(TEXT("biomes"),Bs))for(const auto& B:*Bs)M.Biomes.Add(B->AsString());
|
| 337 |
+
const TArray<TSharedPtr<FJsonValue>>* Sz;if(T->TryGetArrayField(TEXT("size"),Sz)&&Sz->Num()==3)M.Size=FVector((*Sz)[0]->AsNumber(),(*Sz)[1]->AsNumber(),(*Sz)[2]->AsNumber());
|
| 338 |
+
M.MinZ=T->GetNumberField(TEXT("min_z"));
|
| 339 |
+
if(M.Kind==TEXT("debris")&&FMath::Max(M.Size.X,M.Size.Y)>120.f)M.Kind=TEXT("log");
|
| 340 |
+
if(M.Kind==TEXT("rock")&&FMath::Max(M.Size.X,M.Size.Y)>=70.f)M.Kind=TEXT("rockbig");
|
| 341 |
+
if(M.Kind==TEXT("rockbig")&&FMath::Max(M.Size.X,M.Size.Y)>1400.f)continue; // cliffs / shore shelves: larger than the play spaces
|
| 342 |
+
if(M.Kind==TEXT("shrub")&&FMath::Max3(M.Size.X,M.Size.Y,M.Size.Z)<70.f)M.Kind=TEXT("plant");
|
| 343 |
+
M.Mesh=LoadObject<UStaticMesh>(nullptr,*T->GetStringField(TEXT("mesh")));if(!M.Mesh)continue;
|
| 344 |
+
const TArray<TSharedPtr<FJsonValue>>* Ms;
|
| 345 |
+
if(T->TryGetArrayField(TEXT("materials"),Ms))for(const auto& X:*Ms)
|
| 346 |
+
{
|
| 347 |
+
UMaterialInterface* Mi=X->AsString().IsEmpty()?nullptr:LoadObject<UMaterialInterface>(nullptr,*X->AsString());M.Mats.Add(Mi);
|
| 348 |
+
if(!Mi)continue;
|
| 349 |
+
V10RealKeep.Add(Mi);
|
| 350 |
+
for(const TCHAR* Pn:{TEXT("BC"),TEXT("NM"),TEXT("RT"),TEXT("OP")})
|
| 351 |
+
{
|
| 352 |
+
UTexture* Tx=nullptr;
|
| 353 |
+
if(Mi->GetTextureParameterValue(FHashedMaterialParameterInfo(FName(Pn)),Tx)&&Tx&&!SeenTex.Contains(Tx)){SeenTex.Add(Tx);V10RealKeep.Add(Tx);Tx->SetForceMipLevelsToBeResident(1e6f);NTex++;}
|
| 354 |
+
}
|
| 355 |
+
}
|
| 356 |
+
V10RealKeep.Add(M.Mesh);GV10All.Add(M);
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
// zone of the visible play space (within ~26 m of the route / anchors) and its area
|
| 361 |
+
const FVector2D Lo(V10HfOrigin.X,V10HfOrigin.Y),Hi(V10HfOrigin.X+(V10HfNX-1)*V10HfStep,V10HfOrigin.Y+(V10HfNY-1)*V10HfStep);
|
| 362 |
+
int32 ZoneHit=0,ZoneTry=0;
|
| 363 |
+
for(int32 I=0;I<4000;I++)
|
| 364 |
+
{
|
| 365 |
+
ZoneTry++;const FVector2D P(R.FRandRange(Lo.X,Hi.X),R.FRandRange(Lo.Y,Hi.Y));
|
| 366 |
+
bool In=RouteDist2D(P)<2600.f;for(const FVector& A:V10Anchors)In|=FVector2D::Distance(P,FVector2D(A.X,A.Y))<3000.f;ZoneHit+=In;
|
| 367 |
+
}
|
| 368 |
+
V10AreaM2=(Hi.X-Lo.X)*(Hi.Y-Lo.Y)/1e4f*ZoneHit/FMath::Max(1,ZoneTry);
|
| 369 |
+
V10RealCounts.Add(TEXT("hidden_actors"),HidA);V10RealCounts.Add(TEXT("hidden_ground_components"),HidG);V10RealCounts.Add(TEXT("catalog_meshes"),GV10All.Num());
|
| 370 |
+
V10RealCounts.Add(TEXT("resident_textures"),NTex);V10RealCounts.Add(TEXT("zone_m2"),FMath::RoundToInt(V10AreaM2));V10RealCounts.Add(TEXT("relief_cm"),FMath::RoundToInt(Amp));V10RealCounts.Add(TEXT("holes_filled"),Filled);V10RealCounts.Add(TEXT("lights_off"),HidL);V10RealCounts.Add(TEXT("unlabelled_off"),HidU);
|
| 371 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 real: hidden %d actors / %d ground comps, height field %dx%d (%d valid, relief %.0f cm), catalog %d meshes, %d textures resident, zone %.0f m2, %.1fs"),
|
| 372 |
+
HidA,HidG,V10HfNX,V10HfNY,Valid,Amp,GV10All.Num(),NTex,V10AreaM2,FPlatformTime::Seconds()-T0);
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
// a new biome variant for a new look: material parameters + re-scatter (called from V10PhotoLook, i.e. only on the cut grid)
|
| 376 |
+
void APipelineCapture::V10RealNewVariant(FV9Look& L)
|
| 377 |
+
{
|
| 378 |
+
if(!V10Real)return;
|
| 379 |
+
FRandomStream R(V10Mix(V10RealSeed,++V10LookN));
|
| 380 |
+
int32 Var=V10VarForced;
|
| 381 |
+
if(Var<0){Var=R.RandRange(0,V10NumVars-1);if(Var==V10Var&&V10NumVars>1)Var=(Var+1+R.RandRange(0,V10NumVars-2))%V10NumVars;}
|
| 382 |
+
V10Var=Var;const FV10Variant& V=V10Vars[Var];
|
| 383 |
+
V10VarName=V.Name;V10VarLights=V.Lights;V10VarGround=V.Ground;V10VarSide=V.Side;V10VarCover=V.Cover;V10VarGCov0=V.GCov0;V10VarGCov1=V.GCov1;V10VarWet=V.Wet;
|
| 384 |
+
L.Biome=V.Name;V10VarLog.AddUnique(V.Name);
|
| 385 |
+
V10RealScatterNow(Var,R.RandRange(1,1<<30));
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
void APipelineCapture::V10RealScatterNow(int32 Var,int32 Seed)
|
| 389 |
+
{
|
| 390 |
+
UWorld* World=GetWorld();const double T0=FPlatformTime::Seconds();
|
| 391 |
+
const FV10Variant& V=V10Vars[FMath::Clamp(Var,0,V10NumVars-1)];const int32 Bi=V.Base;
|
| 392 |
+
FRandomStream R(Seed);
|
| 393 |
+
// ---- remove the previous look's instances and whitebox twins ----------------------------------------------------
|
| 394 |
+
for(const TWeakObjectPtr<UPrimitiveComponent>& W:V10RealTwins)if(UPrimitiveComponent* C=W.Get()){WhiteboxComponents.Remove(C);if(Whitebox)Whitebox->RemoveShowOnlyComponent(C);C->DestroyComponent();}
|
| 395 |
+
V10RealTwins.Reset();
|
| 396 |
+
for(const TWeakObjectPtr<UInstancedStaticMeshComponent>& W:V10RealScatter)if(UInstancedStaticMeshComponent* C=W.Get())C->DestroyComponent();
|
| 397 |
+
V10RealScatter.Reset();V10RealMIDs.Reset();V10LookCounts.Reset();
|
| 398 |
+
// ---- per-look material variants (season tint, cover, wetness) ----------------------------------------------------
|
| 399 |
+
const FLinearColor Fol=FLinearColor::LerpUsingHSV(V.Fol0,V.Fol1,R.FRand());const float CovAmt=R.FRandRange(V.Cov0,V.Cov1);const FV10Season* Sea=V10SeasonOf(V.Name);
|
| 400 |
+
TMap<UMaterialInterface*,UMaterialInterface*> MidOf;
|
| 401 |
+
auto Mat=[&](UMaterialInterface* Mi)->UMaterialInterface*
|
| 402 |
+
{
|
| 403 |
+
if(!Mi)return nullptr;if(UMaterialInterface** F=MidOf.Find(Mi))return *F;
|
| 404 |
+
UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(Mi,this);
|
| 405 |
+
const bool Fo=V10IsFoliageMat(Mi);
|
| 406 |
+
// per material a little hue / value jitter around the season tint (not every plant turns at once)
|
| 407 |
+
const FLinearColor J(R.FRandRange(.94f,1.06f),R.FRandRange(.94f,1.06f),R.FRandRange(.92f,1.08f));
|
| 408 |
+
if(Fo)D->SetVectorParameterValue(TEXT("Tint"),FLinearColor::LerpUsingHSV(FLinearColor::White,Fol,R.FRandRange(.6f,1.f))*J*(1.f-.22f*V.Wet));
|
| 409 |
+
else if(V.Wet>0)D->SetVectorParameterValue(TEXT("Tint"),FLinearColor(1,1,1)*(1.f-.25f*V.Wet));
|
| 410 |
+
if(Fo){D->SetScalarParameterValue(TEXT("Bright"),R.FRandRange(.96f,1.08f));D->SetScalarParameterValue(TEXT("AOScale"),.3f);D->SetScalarParameterValue(TEXT("SSSAmt"),.3f);}
|
| 411 |
+
if(Fo&&Sea) // a quarter of the plants lag behind (greener)
|
| 412 |
+
{
|
| 413 |
+
D->SetVectorParameterValue(TEXT("SeasonCol"),Sea->Col*FLinearColor(R.FRandRange(.9f,1.1f),R.FRandRange(.85f,1.15f),R.FRandRange(.8f,1.2f)));
|
| 414 |
+
D->SetScalarParameterValue(TEXT("SeasonAmt"),R.FRandRange(Sea->A0,Sea->A1)*(R.FRand()<.25f?.4f:1.f));
|
| 415 |
+
}
|
| 416 |
+
D->SetVectorParameterValue(TEXT("CovColor"),V.Cov*R.FRandRange(.9f,1.1f));D->SetScalarParameterValue(TEXT("CovAmt"),CovAmt*(Fo?(Sea&&Sea->FolCov?.6f:0.f):1.f));D->SetScalarParameterValue(TEXT("CovRough"),V.CovRough);D->SetScalarParameterValue(TEXT("CovDetail"),V.Cov.GetLuminance()>.5f?.35f:.85f);
|
| 417 |
+
if(V.Wet>0)D->SetScalarParameterValue(TEXT("RMul"),FMath::Lerp(1.f,.6f,V.Wet)); // wet, not mirror: a top-down sun glint flooded whole frames
|
| 418 |
+
V10RealMIDs.Add(D);MidOf.Add(Mi,D);return D;
|
| 419 |
+
};
|
| 420 |
+
// ---- scatter ---------------------------------------------------------------------------------------------------
|
| 421 |
+
TArray<FString> AssetTags;FString(V.Assets).ParseIntoArray(AssetTags,TEXT(" "));
|
| 422 |
+
TArray<const FV10Mesh*> Pool;for(const FV10Mesh& M:GV10All){bool In=false;for(const FString& T:AssetTags)In|=M.Biomes.Contains(T);if(In)Pool.Add(&M);}
|
| 423 |
+
TMap<UStaticMesh*,TArray<FTransform>> Inst;TMap<UStaticMesh*,int32> MeshSem;TMap<UStaticMesh*,bool> MeshBig;TMap<UStaticMesh*,const FV10Mesh*> MeshInfo;
|
| 424 |
+
TMap<FIntPoint,TArray<FVector4f>> BigGrid; // x, y, radius for big object spacing (5 m cells)
|
| 425 |
+
auto BigFree=[&](const FVector2D& P,float Rad)
|
| 426 |
+
{
|
| 427 |
+
const FIntPoint C0(FMath::FloorToInt(P.X/500.f),FMath::FloorToInt(P.Y/500.f));const int32 Rr=FMath::CeilToInt((Rad+700.f)/500.f);
|
| 428 |
+
for(int32 Y=-Rr;Y<=Rr;Y++)for(int32 X=-Rr;X<=Rr;X++)if(const TArray<FVector4f>* L=BigGrid.Find(C0+FIntPoint(X,Y)))
|
| 429 |
+
for(const FVector4f& B:*L)if(FVector2D::Distance(P,FVector2D(B.X,B.Y))<(Rad+B.Z)*.85f)return false;
|
| 430 |
+
return true;
|
| 431 |
+
};
|
| 432 |
+
const FVector2D Lo(V10HfOrigin.X,V10HfOrigin.Y),Hi(V10HfOrigin.X+(V10HfNX-1)*V10HfStep,V10HfOrigin.Y+(V10HfNY-1)*V10HfStep);
|
| 433 |
+
auto Zone=[&](const FVector2D& P){if(RouteDist2D(P)<2600.f)return true;for(const FVector& A:V10Anchors)if(FVector2D::Distance(P,FVector2D(A.X,A.Y))<3000.f)return true;return false;};
|
| 434 |
+
const FVector S0=V10S0,SB=V10SB;
|
| 435 |
+
const float Global=V10Density*R.FRandRange(.6f,1.4f); // per look: sparser / denser
|
| 436 |
+
const bool OpenClearing=R.FRand()<.25f; // the former paving: an open clearing or overgrown
|
| 437 |
+
const float NoiseShift=R.FRandRange(0.f,100.f);
|
| 438 |
+
int32 Rej[4]={0,0,0,0};
|
| 439 |
+
for(int32 KI=0;KI<UE_ARRAY_COUNT(V10Kinds);KI++)
|
| 440 |
+
{
|
| 441 |
+
const FV10KindCfg& K=V10Kinds[KI];
|
| 442 |
+
TArray<const FV10Mesh*> Ms;for(const FV10Mesh* M:Pool)if(M->Kind==K.Kind)Ms.Add(M);
|
| 443 |
+
if(!Ms.Num()){V10LookCounts.Add(K.Kind,0);continue;}
|
| 444 |
+
const int32 Want=FMath::Min(FMath::RoundToInt(K.Dens[Bi]*V.Mul[KI]*Global*V10AreaM2),K.Big?4000:160000);
|
| 445 |
+
int32 Placed=0;const float NoiseOff=KI*13.7f+NoiseShift;
|
| 446 |
+
// small kinds come in clusters (a few clumps of one or two species around a centre, gaussian spread) with bare ground in
|
| 447 |
+
// between, the way ground cover grows; big objects are placed one by one with clearances
|
| 448 |
+
const float MeanN=K.Big?1.f:KI==0?18.f:KI==1?6.f:KI==2?4.f:5.f;
|
| 449 |
+
const float CR0=KI==0?60.f:KI==1?40.f:KI==2?50.f:40.f,CR1=KI==0?220.f:KI==1?150.f:KI==2?200.f:150.f;
|
| 450 |
+
auto PlaceAt=[&](const FVector2D& P,const FV10Mesh& M,float Sc)->bool
|
| 451 |
+
{
|
| 452 |
+
float Z;int32 Cls;if(!V10HfAt(P.X,P.Y,Z,Cls)){Rej[2]++;return false;}
|
| 453 |
+
if(Cls==2&&OpenClearing&&R.FRand()>(K.Big?.35f:.5f))return false;
|
| 454 |
+
const bool Rock=K.Sem==4,Tree=M.Kind==TEXT("tree"),Grass=M.Kind==TEXT("grass")||M.Kind==TEXT("debris");
|
| 455 |
+
const float Rad=.5f*FMath::Max(M.Size.X,M.Size.Y)*Sc;
|
| 456 |
+
if(K.Big)
|
| 457 |
+
{
|
| 458 |
+
// trees: the trunk keeps clear of the route, the canopy may reach over its edge (depth / shade in the frame)
|
| 459 |
+
const float RR=Tree?.35f*Rad:Rad,Clear=Tree?160.f:M.Kind==TEXT("prop")?140.f:170.f;
|
| 460 |
+
if(RouteDist2D(P)<RR+Clear||FVector2D::Distance(P,FVector2D(S0))<RR+550.f||FVector2D::Distance(P,FVector2D(SB))<RR+850.f){Rej[3]++;return false;}
|
| 461 |
+
const float SpR=Tree?.6f*Rad:Rad;
|
| 462 |
+
if(!BigFree(P,SpR)){Rej[3]++;return false;}
|
| 463 |
+
BigGrid.FindOrAdd(FIntPoint(FMath::FloorToInt(P.X/500.f),FMath::FloorToInt(P.Y/500.f))).Add(FVector4f(P.X,P.Y,SpR,0));
|
| 464 |
+
}
|
| 465 |
+
else if(Rock&&RouteDist2D(P)<60.f+Rad){Rej[3]++;return false;}
|
| 466 |
+
const float Tilt=Rock?12.f:Tree?3.f:M.Kind==TEXT("log")||Grass?4.f:6.f;
|
| 467 |
+
const FRotator Rot(R.FRandRange(-Tilt,Tilt),R.FRandRange(0.f,360.f),R.FRandRange(-Tilt,Tilt));
|
| 468 |
+
const float Sink=M.Size.Z*Sc*(Rock?R.FRandRange(.1f,.3f):Tree?.04f:M.Kind==TEXT("log")?.12f:.03f)+M.MinZ*Sc;
|
| 469 |
+
const FVector S3=FVector(Sc)*FVector(R.FRandRange(.92f,1.08f),R.FRandRange(.92f,1.08f),R.FRandRange(.9f,1.1f));
|
| 470 |
+
Inst.FindOrAdd(M.Mesh).Add(FTransform(Rot,FVector(P.X,P.Y,Z-Sink),S3));MeshSem.Add(M.Mesh,K.Sem);MeshBig.Add(M.Mesh,K.Big||Rock);MeshInfo.Add(M.Mesh,&M);
|
| 471 |
+
return true;
|
| 472 |
+
};
|
| 473 |
+
auto PickMesh=[&]()->const FV10Mesh*
|
| 474 |
+
{
|
| 475 |
+
const FV10Mesh* Pk=Ms[R.RandRange(0,Ms.Num()-1)];
|
| 476 |
+
if(KI==0)for(int32 Tr=0;Tr<3&&FMath::Max(Pk->Size.X,Pk->Size.Y)<20.f;Tr++)Pk=Ms[R.RandRange(0,Ms.Num()-1)];
|
| 477 |
+
return Pk;
|
| 478 |
+
};
|
| 479 |
+
for(int32 Try=0;Try<Want*6&&Placed<Want;Try++)
|
| 480 |
+
{
|
| 481 |
+
const FVector2D P0(R.FRandRange(Lo.X,Hi.X),R.FRandRange(Lo.Y,Hi.Y));
|
| 482 |
+
if(!Zone(P0)){Rej[0]++;continue;}
|
| 483 |
+
if(K.Cut[Bi]>-1.f&&V10Fbm(P0.X,P0.Y,K.Big?2500.f:1300.f,NoiseOff)<K.Cut[Bi]){Rej[1]++;continue;}
|
| 484 |
+
const FV10Mesh* MA=PickMesh();const FV10Mesh* MB=R.FRand()<.4f?PickMesh():MA;
|
| 485 |
+
const bool Rock=K.Sem==4,Tree=MA->Kind==TEXT("tree");
|
| 486 |
+
auto Scale=[&](const FV10Mesh& M){return Rock?R.FRandRange(K.Big?.7f:.6f,K.Big?1.35f:1.6f):Tree?R.FRandRange(.8f,1.2f):M.Kind==TEXT("prop")?R.FRandRange(.95f,1.05f):KI==0?R.FRandRange(1.f,1.6f):R.FRandRange(.8f,1.3f);};
|
| 487 |
+
if(K.Big){if(PlaceAt(P0,*MA,Scale(*MA)))Placed++;continue;}
|
| 488 |
+
const int32 N=FMath::Max(1,FMath::RoundToInt(MeanN*R.FRandRange(.3f,1.7f)));const float Rc=R.FRandRange(CR0,CR1);
|
| 489 |
+
for(int32 J=0;J<N&&Placed<Want;J++)
|
| 490 |
+
{
|
| 491 |
+
const float U=FMath::Max(1e-4f,R.FRand()),Rr=FMath::Min(Rc*.5f*FMath::Sqrt(-2.f*FMath::Loge(U)),Rc*1.6f),An=R.FRandRange(0.f,2*UE_PI);
|
| 492 |
+
const FV10Mesh& M=*(J%3==2?MB:MA);
|
| 493 |
+
if(PlaceAt(P0+FVector2D(FMath::Cos(An),FMath::Sin(An))*Rr,M,Scale(M)))Placed++;
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
V10LookCounts.Add(K.Kind,Placed);
|
| 497 |
+
}
|
| 498 |
+
// ---- components (stencil set here: the label set-up pass ran before the first look) -------------------------------
|
| 499 |
+
int32 NComp=0,NInst=0;
|
| 500 |
+
for(auto& E:Inst)
|
| 501 |
+
{
|
| 502 |
+
const int32 S=FMath::Clamp(MeshSem.FindRef(E.Key),0,6);
|
| 503 |
+
AActor* H=V10Holder[S].Get();
|
| 504 |
+
if(!H)
|
| 505 |
+
{
|
| 506 |
+
H=World->SpawnActor<AActor>(AActor::StaticClass(),FTransform(V10HfOrigin));if(!H)continue;
|
| 507 |
+
USceneComponent* HR=NewObject<USceneComponent>(H);H->SetRootComponent(HR);HR->RegisterComponent();
|
| 508 |
+
H->Tags.Add(FName(*FString::Printf(TEXT("semantic:%d"),S)));H->Tags.Add(TEXT("v4_event"));H->Tags.Add(TEXT("v10_real"));V10Holder[S]=H;
|
| 509 |
+
}
|
| 510 |
+
auto* C=NewObject<UInstancedStaticMeshComponent>(H);C->SetupAttachment(H->GetRootComponent());C->SetMobility(EComponentMobility::Movable);
|
| 511 |
+
C->SetStaticMesh(E.Key);C->SetCollisionEnabled(ECollisionEnabled::NoCollision);C->SetCastShadow(true);C->ComponentTags.Add(TEXT("v10_scatter"));
|
| 512 |
+
if(const FV10Mesh* Info=MeshInfo.FindRef(E.Key))if(Info->Kind==TEXT("grass")||Info->Kind==TEXT("plant")||Info->Kind==TEXT("debris"))
|
| 513 |
+
{ // ground cover shadows: 1 full, 2 no contact shadows (the screen-space ones blacken dense tufts), 0 none
|
| 514 |
+
if(V10GrassShadow==0)C->SetCastShadow(false);else if(V10GrassShadow==2)C->bCastContactShadow=false;
|
| 515 |
+
// masked cards become solid blobs in the mesh distance fields / Lumen scene: every clump then occludes the sky light
|
| 516 |
+
// and leaves a dark halo on the ground. Ground cover stays out of the indirect / distance field lighting.
|
| 517 |
+
C->bAffectDistanceFieldLighting=false;C->bAffectDynamicIndirectLighting=false;
|
| 518 |
+
}
|
| 519 |
+
if(MeshBig.FindRef(E.Key))C->ComponentTags.Add(TEXT("v10_big"));
|
| 520 |
+
if(const FV10Mesh* Info=MeshInfo.FindRef(E.Key))for(int32 Sl=0;Sl<Info->Mats.Num();Sl++)if(UMaterialInterface* Mi=Mat(Info->Mats[Sl]))C->SetMaterial(Sl,Mi);
|
| 521 |
+
C->SetRenderCustomDepth(true);C->SetCustomDepthStencilValue(S);C->SetTextureForceResidentFlag(true);
|
| 522 |
+
C->RegisterComponent();H->AddInstanceComponent(C);C->AddInstances(E.Value,false,true);
|
| 523 |
+
V10RealScatter.Add(C);NComp++;NInst+=E.Value.Num();
|
| 524 |
+
}
|
| 525 |
+
// ---- whitebox twins of the structural objects (rocks, shrubs, trees, logs, props) ----------------------------------
|
| 526 |
+
if(Whitebox&&V10WhiteHolder.IsValid())
|
| 527 |
+
{
|
| 528 |
+
UMaterialInterface* White=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V10/Materials/M_V10White.M_V10White"));if(!White)White=WhiteMaterialRef;
|
| 529 |
+
AActor* H=V10WhiteHolder.Get();
|
| 530 |
+
for(const TWeakObjectPtr<UInstancedStaticMeshComponent>& Sw:V10RealScatter)if(UInstancedStaticMeshComponent* C=Sw.Get())
|
| 531 |
+
{
|
| 532 |
+
if(!C->ComponentHasTag(TEXT("v10_big")))continue;
|
| 533 |
+
auto* W=NewObject<UInstancedStaticMeshComponent>(H);W->SetupAttachment(H->GetRootComponent());W->SetMobility(EComponentMobility::Movable);W->SetStaticMesh(C->GetStaticMesh());
|
| 534 |
+
for(int32 K=0;K<C->GetNumMaterials();K++)W->SetMaterial(K,White);
|
| 535 |
+
W->SetCollisionEnabled(ECollisionEnabled::NoCollision);W->SetCastShadow(false);W->RegisterComponent();H->AddInstanceComponent(W);
|
| 536 |
+
TArray<FTransform> T;T.Reserve(C->GetInstanceCount());
|
| 537 |
+
for(int32 K=0;K<C->GetInstanceCount();K++){FTransform X;C->GetInstanceTransform(K,X,true);T.Add(X);}
|
| 538 |
+
W->AddInstances(T,false,true);
|
| 539 |
+
WhiteboxComponents.Add(W);Whitebox->ShowOnlyComponent(W);V10RealTwins.Add(W);
|
| 540 |
+
}
|
| 541 |
+
}
|
| 542 |
+
V10LookCounts.Add(TEXT("instances"),NInst);V10LookCounts.Add(TEXT("components"),NComp);V10LookCounts.Add(TEXT("pool_meshes"),Pool.Num());
|
| 543 |
+
V10LookCounts.Add(TEXT("density_x100"),FMath::RoundToInt(Global*100));V10LookCounts.Add(TEXT("open_clearing"),OpenClearing);V10LookCounts.Add(TEXT("whitebox_twins"),V10RealTwins.Num());
|
| 544 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 real look %d: %s pool %d, %d instances in %d components (density %.2f, cover %.2f, wet %.1f, rejects %d/%d/%d/%d) %.1fs"),
|
| 545 |
+
V10LookN,V.Name,Pool.Num(),NInst,NComp,Global,CovAmt,V.Wet,Rej[0],Rej[1],Rej[2],Rej[3],FPlatformTime::Seconds()-T0);
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
void APipelineCapture::V10RealWhitebox()
|
| 549 |
+
{
|
| 550 |
+
if(!V10Real||!Whitebox)return;
|
| 551 |
+
UMaterialInterface* White=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V10/Materials/M_V10White.M_V10White"));
|
| 552 |
+
if(!White)White=WhiteMaterialRef;
|
| 553 |
+
// the authored structural whitebox describes the hidden scene: out of the whitebox pass
|
| 554 |
+
int32 Removed=0;
|
| 555 |
+
for(TActorIterator<AActor> I(GetWorld());I;++I)if(I->ActorHasTag(TEXT("whitebox"))&&!Cast<APipelineWhitebox>(*I))
|
| 556 |
+
{
|
| 557 |
+
TArray<UPrimitiveComponent*> Cs;I->GetComponents(Cs);
|
| 558 |
+
for(UPrimitiveComponent* C:Cs){Whitebox->RemoveShowOnlyComponent(C);WhiteboxComponents.Remove(C);C->SetVisibility(false);Removed++;}
|
| 559 |
+
}
|
| 560 |
+
AActor* H=GetWorld()->SpawnActor<AActor>(AActor::StaticClass(),FTransform(V10HfOrigin));if(!H)return;
|
| 561 |
+
USceneComponent* HR=NewObject<USceneComponent>(H);H->SetRootComponent(HR);HR->RegisterComponent();H->Tags.Add(TEXT("whitebox_v10"));V10WhiteHolder=H;
|
| 562 |
+
for(const TWeakObjectPtr<UStaticMeshComponent>& G:V10RealGround)if(UStaticMeshComponent* C=G.Get())
|
| 563 |
+
{
|
| 564 |
+
auto* W=NewObject<UStaticMeshComponent>(H);W->SetupAttachment(HR);W->SetMobility(EComponentMobility::Movable);W->SetStaticMesh(C->GetStaticMesh());W->SetMaterial(0,White);
|
| 565 |
+
W->SetCollisionEnabled(ECollisionEnabled::NoCollision);W->SetCastShadow(false);W->RegisterComponent();W->SetWorldTransform(C->GetComponentTransform());H->AddInstanceComponent(W);
|
| 566 |
+
WhiteboxComponents.Add(W);Whitebox->ShowOnlyComponent(W);
|
| 567 |
+
}
|
| 568 |
+
V10RealCounts.Add(TEXT("whitebox_removed"),Removed);
|
| 569 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V10 real whitebox: %d authored components out, ground twin in (object twins follow every look)"),Removed);
|
| 570 |
+
}
|
| 571 |
+
|
| 572 |
+
void APipelineCapture::V10RealCamera(FMinimalViewInfo& View)
|
| 573 |
+
{
|
| 574 |
+
if(!V10Real||!Player)return;
|
| 575 |
+
// same framing as the orthographic view (frame width W at the pivot = the player), seen through a telephoto lens
|
| 576 |
+
const float W=FMath::Max(View.OrthoWidth,300.f);const FVector Fwd=View.Rotation.Vector();
|
| 577 |
+
const FVector Pivot=View.Location+Fwd*Player->CameraBoom->TargetArmLength;
|
| 578 |
+
const float Fov=FMath::Clamp(V10Fov,10.f,90.f);
|
| 579 |
+
V10CamDist=.5f*W/FMath::Tan(FMath::DegreesToRadians(.5f*Fov));
|
| 580 |
+
View.ProjectionMode=ECameraProjectionMode::Perspective;View.FOV=Fov;View.Location=Pivot-Fwd*V10CamDist;
|
| 581 |
+
// the telephoto camera sits 30-80 m above the ground: height fog over that whole path laid a milky veil over the frame.
|
| 582 |
+
// Fog starts near the ground (aerial haze stays for mist / storm looks)
|
| 583 |
+
if(UExponentialHeightFogComponent* F=V10Fog.Get())
|
| 584 |
+
{
|
| 585 |
+
const float St=V10CamDist*(V9Cur.Light==1||V9Cur.Light==7?.6f:.9f);
|
| 586 |
+
if(FMath::Abs(F->StartDistance-St)>100.f){F->SetStartDistance(St);F->SetVolumetricFogStartDistance(St);}
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
void APipelineCapture::V10RealLookJson(TSharedPtr<FJsonObject> J)
|
| 591 |
+
{
|
| 592 |
+
if(!V10Real)return;
|
| 593 |
+
J->SetStringField(TEXT("v10_variant"),V10VarName);
|
| 594 |
+
TSharedPtr<FJsonObject> C=MakeShared<FJsonObject>();for(const auto& P:V10LookCounts)C->SetNumberField(P.Key,P.Value);J->SetObjectField(TEXT("v10_scatter"),C);
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
void APipelineCapture::WriteV10Real(TSharedPtr<FJsonObject> O)
|
| 598 |
+
{
|
| 599 |
+
if(!V10Real)return;
|
| 600 |
+
TSharedPtr<FJsonObject> J=MakeShared<FJsonObject>();
|
| 601 |
+
TArray<TSharedPtr<FJsonValue>> Vs;for(const FString& S:V10VarLog)Vs.Add(MakeShared<FJsonValueString>(S));J->SetArrayField(TEXT("variants_used"),Vs);
|
| 602 |
+
J->SetStringField(TEXT("forced_variant"),V10VarForced>=0?V10Vars[V10VarForced].Name:TEXT(""));J->SetNumberField(TEXT("variant_count"),V10NumVars);J->SetNumberField(TEXT("density"),V10Density);
|
| 603 |
+
J->SetArrayField(TEXT("fov_range_deg"),{MakeShared<FJsonValueNumber>(V10FovMin),MakeShared<FJsonValueNumber>(V10FovMax)});
|
| 604 |
+
J->SetNumberField(TEXT("height_field_step_cm"),V10HfStep);J->SetNumberField(TEXT("height_field_nx"),V10HfNX);J->SetNumberField(TEXT("height_field_ny"),V10HfNY);
|
| 605 |
+
TSharedPtr<FJsonObject> C=MakeShared<FJsonObject>();for(const auto& P:V10RealCounts)C->SetNumberField(P.Key,P.Value);J->SetObjectField(TEXT("counts"),C);
|
| 606 |
+
J->SetStringField(TEXT("assets"),TEXT("Poly Haven CC0 1.0 photo-scanned models and PBR sets (see Content/Xfer/V10/v10_models.json, v10_pbr.json)"));
|
| 607 |
+
O->SetObjectField(TEXT("v10_real"),J);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
// ---- promo cinematic cameras (-DatasetCine=orbit|hero|crane|drone|fight|dolly) ------------------------------------------
|
| 611 |
+
// Free camera for showcase footage; every pass (RGB, whitebox, labels, depth) uses the same view, so the structural
|
| 612 |
+
// whitebox stays aligned with the render. Off unless -DatasetCine is given.
|
| 613 |
+
void V10CineCamera(AGameDemoFighter* Player,FMinimalViewInfo& View,float Time,int32 Frame,USceneCaptureComponent2D* RGBC)
|
| 614 |
+
{
|
| 615 |
+
static float Fps=30.f;
|
| 616 |
+
static int32 Mode=-1;static float Seed=30.f,Speed=1.f,FStop=2.2f,T0=-1.f,LastT=0.f,A0=0.f,DistSm=0.f;
|
| 617 |
+
static FVector TSm,CamSm,DirSm,Ctr;static float Rad=0.f;
|
| 618 |
+
const TCHAR* Cmd=FCommandLine::Get();
|
| 619 |
+
if(Mode<0)
|
| 620 |
+
{
|
| 621 |
+
FString M;FParse::Value(Cmd,TEXT("DatasetCine="),M);
|
| 622 |
+
Mode=M==TEXT("orbit")?1:M==TEXT("hero")?2:M==TEXT("crane")?3:M==TEXT("drone")?4:M==TEXT("fight")?5:M==TEXT("dolly")?6:0;
|
| 623 |
+
FParse::Value(Cmd,TEXT("DatasetCineSeed="),Seed);FParse::Value(Cmd,TEXT("DatasetCineSpeed="),Speed);FParse::Value(Cmd,TEXT("DatasetCineFStop="),FStop);{int32 Hz=60,St=2;FParse::Value(Cmd,TEXT("DatasetSimHz="),Hz);FParse::Value(Cmd,TEXT("DatasetStride="),St);Fps=float(Hz)/FMath::Max(1,St);}
|
| 624 |
+
if(Mode)UE_LOG(LogTemp,Display,TEXT("DATASET_CINE mode %s seed %.0f speed %.2f fstop %.1f"),*M,Seed,Speed,FStop);
|
| 625 |
+
}
|
| 626 |
+
if(Mode==0||!Player)return;
|
| 627 |
+
UWorld* World=Player->GetWorld();if(!World)return;
|
| 628 |
+
AGameDemoFighter* Boss=Player->Opponent.Get();
|
| 629 |
+
const FVector P=Player->GetActorLocation();
|
| 630 |
+
FVector T=P+FVector(0,0,25);float Sep=0.f;
|
| 631 |
+
float FightW=0.f;
|
| 632 |
+
if(Mode==5&&Boss){const FVector B=Boss->GetActorLocation();Sep=FVector::Dist2D(P,B);FightW=FMath::Clamp((1000.f-Sep)/450.f,0.f,1.f);T=FMath::Lerp(P,B,.42f*FightW)+FVector(0,0,25.f+20.f*FightW);}
|
| 633 |
+
if(T0<0.f)
|
| 634 |
+
{
|
| 635 |
+
T0=Time;LastT=Time;TSm=T;A0=Player->GetActorRotation().Yaw+180.f+Seed;DirSm=Player->GetActorForwardVector();
|
| 636 |
+
FBox B(ForceInit);B+=P;if(Boss)B+=Boss->GetActorLocation();for(const FVector& W:Player->ExplorationWaypoints)B+=W;for(const FVector& W:Player->ExplorationPlaces)B+=W;
|
| 637 |
+
Ctr=B.GetCenter();Ctr.Z=P.Z-90.f;Rad=FMath::Max(1500.f,.5f*FVector::Dist2D(B.Min,B.Max));
|
| 638 |
+
DistSm=0.f;CamSm=FVector::ZeroVector;
|
| 639 |
+
}
|
| 640 |
+
static FVector PrevP=P;
|
| 641 |
+
const float t=Frame/Fps,Dt=FMath::Clamp(Time-LastT,0.f,.1f);LastT=Time; // shot time runs from the first written frame (warm-up holds the start pose)
|
| 642 |
+
auto Ease=[](float U){U=FMath::Clamp(U,0.f,1.f);return U*U*(3.f-2.f*U);};
|
| 643 |
+
auto Smooth=[&](float Tau){return Dt<=0.f?0.f:1.f-FMath::Exp(-Dt/Tau);};
|
| 644 |
+
TSm=FMath::Lerp(TSm,T,Smooth(Mode==4?2.f:.35f));
|
| 645 |
+
float Dist=430.f,Hgt=70.f,Ang=A0,Fov=40.f;FVector Look=TSm;bool Trace=true;
|
| 646 |
+
switch(Mode)
|
| 647 |
+
{
|
| 648 |
+
case 1: Ang=A0+14.f*Speed*t;Dist=520.f;Hgt=125.f;break;
|
| 649 |
+
case 2: // chase: low camera behind and beside the player, following the smoothed travel direction
|
| 650 |
+
{
|
| 651 |
+
const FVector V=Dt>0.f?(P-PrevP)/Dt:FVector::ZeroVector;
|
| 652 |
+
if(V.Size2D()>60.f)DirSm=FMath::Lerp(DirSm,V.GetSafeNormal2D(),Smooth(1.1f)).GetSafeNormal2D();
|
| 653 |
+
const FVector R=FVector::CrossProduct(FVector::UpVector,DirSm);
|
| 654 |
+
const FVector Cam=TSm-DirSm*430.f+R*(85.f*(Seed>=0?1:-1))+FVector(0,0,65);
|
| 655 |
+
CamSm=CamSm.IsZero()?Cam:FMath::Lerp(CamSm,Cam,Smooth(.45f));
|
| 656 |
+
Dist=-1.f;Fov=40.f;Look=TSm+DirSm*160.f+FVector(0,0,10);break;
|
| 657 |
+
}
|
| 658 |
+
case 3:{const float U=Ease(t/(12.f/Speed));Dist=FMath::Lerp(280.f,1150.f,U);Hgt=FMath::Lerp(-10.f,980.f,U);Ang=A0+6.f*Speed*t;Fov=45.f;break;}
|
| 659 |
+
case 4:{Dist=Rad*1.05f+700.f;Hgt=Rad*.62f+550.f;Ang=A0+4.5f*Speed*t;Fov=50.f;Look=Ctr;Trace=false;break;}
|
| 660 |
+
case 5:{Dist=FMath::Lerp(500.f,FMath::Clamp(1.1f*Sep+380.f,480.f,950.f),FightW);Hgt=130.f;Ang=A0+10.f*Speed*t;Fov=42.f;break;}
|
| 661 |
+
case 6:{const float U=Ease(t/(10.f/Speed));Dist=FMath::Lerp(950.f,330.f,U);Hgt=FMath::Lerp(260.f,55.f,U);Ang=A0+3.f*Speed*t;Fov=36.f;break;}
|
| 662 |
+
}
|
| 663 |
+
FVector Cam;
|
| 664 |
+
if(Dist>0.f)
|
| 665 |
+
{
|
| 666 |
+
DistSm=DistSm<=0.f?Dist:FMath::Lerp(DistSm,Dist,Smooth(.6f));
|
| 667 |
+
const float Rd=FMath::DegreesToRadians(Ang);
|
| 668 |
+
Cam=Look+FVector(FMath::Cos(Rd)*DistSm,FMath::Sin(Rd)*DistSm,Hgt);
|
| 669 |
+
}
|
| 670 |
+
else Cam=CamSm;
|
| 671 |
+
if(Trace)
|
| 672 |
+
{
|
| 673 |
+
FCollisionQueryParams Q(SCENE_QUERY_STAT(V10Cine),false);Q.AddIgnoredActor(Player);if(Boss)Q.AddIgnoredActor(Boss);
|
| 674 |
+
FHitResult H;
|
| 675 |
+
// pull in only for real occluders (walls, buildings); shrubs, grass and small props are ignored and passed through
|
| 676 |
+
for(int32 It=0;It<8;It++)
|
| 677 |
+
{
|
| 678 |
+
if(!World->LineTraceSingleByChannel(H,Look,Cam,ECC_Camera,Q))break;
|
| 679 |
+
const UPrimitiveComponent* Hc=H.GetComponent();const FVector Ext=Hc?Hc->Bounds.BoxExtent:FVector(1e4);
|
| 680 |
+
if(Hc&&Ext.Z<140.f&&FMath::Max(Ext.X,Ext.Y)<400.f){Q.AddIgnoredComponent(Hc);continue;}
|
| 681 |
+
Cam=H.Location+(Look-Cam).GetSafeNormal()*30.f;break;
|
| 682 |
+
}
|
| 683 |
+
if(World->LineTraceSingleByChannel(H,Cam+FVector(0,0,200),Cam-FVector(0,0,400),ECC_Visibility,Q)&&Cam.Z<H.Location.Z+35.f)Cam.Z=H.Location.Z+35.f;
|
| 684 |
+
}
|
| 685 |
+
if(Mode!=4){const FVector D=Cam-(P+FVector(0,0,40));if(D.Size()<240.f)Cam=P+FVector(0,0,40)+D.GetSafeNormal()*240.f;}
|
| 686 |
+
if(Dt>0.f)PrevP=P;
|
| 687 |
+
View.ProjectionMode=ECameraProjectionMode::Perspective;View.FOV=Fov;View.Location=Cam;View.Rotation=(Look-Cam).Rotation();
|
| 688 |
+
if(RGBC)
|
| 689 |
+
{
|
| 690 |
+
auto& PP=RGBC->PostProcessSettings;RGBC->ShowFlags.SetDepthOfField(Mode!=4);
|
| 691 |
+
PP.bOverride_DepthOfFieldFocalDistance=true;PP.DepthOfFieldFocalDistance=FVector::Dist(Cam,Look);
|
| 692 |
+
PP.bOverride_DepthOfFieldFstop=true;PP.DepthOfFieldFstop=Mode==4?16.f:FStop;
|
| 693 |
+
PP.bOverride_DepthOfFieldSensorWidth=true;PP.DepthOfFieldSensorWidth=36.f;
|
| 694 |
+
}
|
| 695 |
+
}
|
code/ue_capture/PipelineCaptureV9.cpp
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// v9 dataset: diversity first.
|
| 2 |
+
// * Capsule characters in the labels: the player / boss (and their weapons) appear in the semantic map (ids, class 10 / 11)
|
| 3 |
+
// as the articulated capsule whitebox (the same proxies as the whitebox pass), not as their mesh silhouettes. Every frame
|
| 4 |
+
// also stores the capsule segments (world cm), so the character condition can be redrawn by code without UE.
|
| 5 |
+
// * Closer camera: absolute ortho width range (default 900-1600 cm, 12% wide 2000-3000 cm), wider pitch range, and a
|
| 6 |
+
// smoothed framing offset towards the player / boss midpoint during fights.
|
| 7 |
+
// * Per camera variant "look" (RGB only, labels / whitebox unchanged): post-process style (toon, kuwahara paint, pixel art,
|
| 8 |
+
// comic, duotone, retro dither, sketch, soft low-fi, hue rotation), material randomisation of the scene (material
|
| 9 |
+
// shuffle, flat colours, triplanar CC0 / generated textures), render tier (full, no GI, no shadows, unlit), texture mip
|
| 10 |
+
// bias, colour grade and outline on / off.
|
| 11 |
+
// -DatasetV9 enable (needs -DatasetV8)
|
| 12 |
+
// -DatasetV9MeshLabels keep the mesh silhouettes in the labels
|
| 13 |
+
// -DatasetV9WMin= / WMax= / WideP= / WideMin= / WideMax= / PitchMin= / PitchMax=
|
| 14 |
+
// -DatasetV9NoFraming
|
| 15 |
+
// -DatasetV9StyleP=0.65 -DatasetV9MatP=0.5 -DatasetV9UnlitP=0.12
|
| 16 |
+
// -DatasetV9LookSeconds=N (tests) also switch the look every N seconds of output
|
| 17 |
+
// -DatasetV9Look=mode:mat:tier (tests) force a look (mode 0-9, mat 0-4, tier 0-3; -1 = random)
|
| 18 |
+
#include "PipelineCapture.h"
|
| 19 |
+
#include "PipelineWhitebox.h"
|
| 20 |
+
#include "GameDemo.h"
|
| 21 |
+
#include "Camera/CameraTypes.h"
|
| 22 |
+
#include "Components/SceneCaptureComponent2D.h"
|
| 23 |
+
#include "Components/StaticMeshComponent.h"
|
| 24 |
+
#include "Components/SkeletalMeshComponent.h"
|
| 25 |
+
#include "Engine/StaticMesh.h"
|
| 26 |
+
#include "Engine/Texture2D.h"
|
| 27 |
+
#include "Materials/MaterialInterface.h"
|
| 28 |
+
#include "Materials/MaterialInstanceDynamic.h"
|
| 29 |
+
#include "EngineUtils.h"
|
| 30 |
+
#include "HAL/IConsoleManager.h"
|
| 31 |
+
#include "Misc/CommandLine.h"
|
| 32 |
+
#include "Misc/FileHelper.h"
|
| 33 |
+
#include "Misc/Paths.h"
|
| 34 |
+
#include "Dom/JsonObject.h"
|
| 35 |
+
#include "Serialization/JsonReader.h"
|
| 36 |
+
#include "Serialization/JsonSerializer.h"
|
| 37 |
+
|
| 38 |
+
namespace
|
| 39 |
+
{
|
| 40 |
+
const TCHAR* V9ModeNames[10]={TEXT("none"),TEXT("toon"),TEXT("paint"),TEXT("pixel"),TEXT("comic"),TEXT("duotone"),TEXT("dither"),TEXT("sketch"),TEXT("soft"),TEXT("hue")};
|
| 41 |
+
const TCHAR* V9MatNames[6]={TEXT("orig"),TEXT("shuffle"),TEXT("flat"),TEXT("tex"),TEXT("mixed"),TEXT("pbr")};
|
| 42 |
+
const TCHAR* V9TierNames[4]={TEXT("full"),TEXT("nogi"),TEXT("noshadow"),TEXT("unlit")};
|
| 43 |
+
TSharedPtr<FJsonValue> V9Num(double V){return MakeShared<FJsonValueNumber>(V);}
|
| 44 |
+
FLinearColor V9Hsv(float H,float S,float V){return FLinearColor(FMath::Frac(H)*360.f,FMath::Clamp(S,0.f,1.f),FMath::Clamp(V,0.f,1.f)).HSVToLinearRGB();}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
void APipelineCapture::ParseV9Args()
|
| 48 |
+
{
|
| 49 |
+
const TCHAR* Cmd=FCommandLine::Get();
|
| 50 |
+
V9=V8Chars&&FParse::Param(Cmd,TEXT("DatasetV9"));
|
| 51 |
+
if(!V9)return;
|
| 52 |
+
V9CapLabels=!FParse::Param(Cmd,TEXT("DatasetV9MeshLabels"));
|
| 53 |
+
V9Frame=!FParse::Param(Cmd,TEXT("DatasetV9NoFraming"));
|
| 54 |
+
V10Photo=FParse::Param(Cmd,TEXT("DatasetV10Photo")); // v10: every look photoreal (PBR materials, cinematic light / grade)
|
| 55 |
+
ParseV10Real(Cmd); // v10 real: photoreal outdoor biome + telephoto camera (PipelineCaptureV10Real.cpp)
|
| 56 |
+
FParse::Value(Cmd,TEXT("DatasetV9WMin="),V9WMin);FParse::Value(Cmd,TEXT("DatasetV9WMax="),V9WMax);FParse::Value(Cmd,TEXT("DatasetV9WideP="),V9WideP);
|
| 57 |
+
FParse::Value(Cmd,TEXT("DatasetV9WideMin="),V9WideMin);FParse::Value(Cmd,TEXT("DatasetV9WideMax="),V9WideMax);
|
| 58 |
+
FParse::Value(Cmd,TEXT("DatasetV9PitchMin="),V9PitchMin);FParse::Value(Cmd,TEXT("DatasetV9PitchMax="),V9PitchMax);
|
| 59 |
+
FParse::Value(Cmd,TEXT("DatasetV9StyleP="),V9StyleP);FParse::Value(Cmd,TEXT("DatasetV9MatP="),V9MatP);FParse::Value(Cmd,TEXT("DatasetV9UnlitP="),V9UnlitP);
|
| 60 |
+
FParse::Value(Cmd,TEXT("DatasetV9Look="),V9Force);
|
| 61 |
+
FParse::Value(Cmd,TEXT("DatasetV9CutGrid="),V9CutGrid);FParse::Value(Cmd,TEXT("DatasetV9CutPhase="),V9CutPhase);
|
| 62 |
+
if(V9CutGrid>0){V9CutPhase=FMath::Clamp(V9CutPhase/4*4,0,V9CutGrid-4);if(V9CutGrid<V9CutPhase+4||V9CutPhase<80)UE_LOG(LogTemp,Warning,TEXT("DATASET_V9 cut grid %d/%d cannot hold 81-frame clips"),V9CutGrid,V9CutPhase);}
|
| 63 |
+
float Sec=0;if(FParse::Value(Cmd,TEXT("DatasetV9LookSeconds="),Sec)&&Sec>0)V9LookFrames=FMath::Max(16,FMath::RoundToInt(Sec*16.f));
|
| 64 |
+
int32 Seed=0;FParse::Value(Cmd,TEXT("DatasetSeed="),Seed);int32 S2=0;if(FParse::Value(Cmd,TEXT("DatasetV9Seed="),S2))Seed=S2;
|
| 65 |
+
V9Rng.Initialize(Seed*7919+911);V9CamRng.Initialize(Seed*104729+57); // camera draws on their own stream: paired runs with other looks keep the same views
|
| 66 |
+
V9Neutral=FParse::Param(Cmd,TEXT("DatasetV9NeutralGrade"));
|
| 67 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V9 on capsule_labels=%d framing=%d width %.0f-%.0f wide %.2f (%.0f-%.0f) pitch %.0f..%.0f styleP %.2f matP %.2f force '%s' lookframes %d"),
|
| 68 |
+
V9CapLabels,V9Frame,V9WMin,V9WMax,V9WideP,V9WideMin,V9WideMax,V9PitchMin,V9PitchMax,V9StyleP,V9MatP,*V9Force,V9LookFrames);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// ---------------------------------------------------------------------------------------------------------------------
|
| 72 |
+
// camera
|
| 73 |
+
// ---------------------------------------------------------------------------------------------------------------------
|
| 74 |
+
void APipelineCapture::V9Camera(FRotator& R,float& W,bool bDefault)
|
| 75 |
+
{
|
| 76 |
+
V9Offset=FVector::ZeroVector;
|
| 77 |
+
const bool Wide=V9CamRng.FRand()<V9WideP;
|
| 78 |
+
W=Wide?V9CamRng.FRandRange(V9WideMin,V9WideMax):V9CamRng.FRandRange(V9WMin,V9WMax);
|
| 79 |
+
if(!bDefault)R.Pitch=V9CamRng.FRandRange(V9PitchMin,V9PitchMax);
|
| 80 |
+
if(V10Real)V10Fov=V9CamRng.FRandRange(V10FovMin,V10FovMax);
|
| 81 |
+
V9PendingLook=true; // a new look with every camera variant (clips never cross a camera change)
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
void APipelineCapture::V9Framing(FMinimalViewInfo& View)
|
| 85 |
+
{
|
| 86 |
+
if(!V9Frame||!Player)return;
|
| 87 |
+
const float Now=GetWorld()->GetTimeSeconds();const float Dt=FMath::Clamp(Now-V9LastFrameT,0.f,.25f);V9LastFrameT=Now;
|
| 88 |
+
FVector Want=FVector::ZeroVector;const float W=View.OrthoWidth;
|
| 89 |
+
if(AGameDemoFighter* B=Player->Opponent.Get())if(B->Health>0)
|
| 90 |
+
{
|
| 91 |
+
FVector D=B->GetActorLocation()-Player->GetActorLocation();D.Z=0;const float L=D.Size();
|
| 92 |
+
const float K=1.f-FMath::SmoothStep(.45f*W,.85f*W,L);
|
| 93 |
+
Want=D*.5f*K;if(Want.Size()>.3f*W)Want=Want.GetSafeNormal()*.3f*W;
|
| 94 |
+
}
|
| 95 |
+
V9Offset=FMath::Lerp(V9Offset,Want,1.f-FMath::Exp(-Dt*2.5f));
|
| 96 |
+
View.Location+=V9Offset;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// ---------------------------------------------------------------------------------------------------------------------
|
| 100 |
+
// looks
|
| 101 |
+
// ---------------------------------------------------------------------------------------------------------------------
|
| 102 |
+
void APipelineCapture::V9LoadPools()
|
| 103 |
+
{
|
| 104 |
+
if(V9PoolsLoaded)return;V9PoolsLoaded=true;
|
| 105 |
+
V9FlatMat=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V9/Materials/M_V9Flat.M_V9Flat"));
|
| 106 |
+
V9TriMat=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V9/Materials/M_V9Tri.M_V9Tri"));
|
| 107 |
+
if(UMaterialInterface* L=LoadObject<UMaterialInterface>(nullptr,TEXT("/Game/Xfer/V9/Materials/M_V9Look.M_V9Look")))V9LookMID=UMaterialInstanceDynamic::Create(L,this);
|
| 108 |
+
// textures: a random subset of the catalog per run (photo CC0 and generated stylised)
|
| 109 |
+
FString S;const FString Cat=FPaths::ProjectContentDir()/TEXT("Xfer/V9/v9_tex.json");
|
| 110 |
+
TArray<FString> Photo,Sty;
|
| 111 |
+
if(FFileHelper::LoadFileToString(S,*Cat))
|
| 112 |
+
{
|
| 113 |
+
TSharedPtr<FJsonObject> O;const TSharedRef<TJsonReader<>> R=TJsonReaderFactory<>::Create(S);
|
| 114 |
+
if(FJsonSerializer::Deserialize(R,O)&&O.IsValid())
|
| 115 |
+
{
|
| 116 |
+
const TArray<TSharedPtr<FJsonValue>>* A;
|
| 117 |
+
if(O->TryGetArrayField(TEXT("textures"),A))for(const auto& V:*A)
|
| 118 |
+
{
|
| 119 |
+
const TSharedPtr<FJsonObject> T=V->AsObject();if(!T)continue;
|
| 120 |
+
(T->GetStringField(TEXT("kind"))==TEXT("stylized")?Sty:Photo).Add(T->GetStringField(TEXT("path")));
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
auto Pick=[&](TArray<FString>& From,int32 N)
|
| 125 |
+
{
|
| 126 |
+
for(int32 I=0;I<N&&From.Num();I++)
|
| 127 |
+
{
|
| 128 |
+
const int32 K=V9Rng.RandRange(0,From.Num()-1);
|
| 129 |
+
if(UTexture* T=LoadObject<UTexture>(nullptr,*From[K]))V9TexPool.Add(T);
|
| 130 |
+
From.RemoveAtSwap(K);
|
| 131 |
+
}
|
| 132 |
+
};
|
| 133 |
+
const int32 NPhoto=V9TexPool.Num();Pick(Photo,36);V9NumPhoto=V9TexPool.Num()-NPhoto;Pick(Sty,16);
|
| 134 |
+
// material shuffle pool: every opaque material currently on a labelled scene mesh
|
| 135 |
+
TSet<UMaterialInterface*> Seen;
|
| 136 |
+
for(TActorIterator<AActor> I(GetWorld());I;++I)
|
| 137 |
+
{
|
| 138 |
+
if(I->ActorHasTag(TEXT("whitebox"))||Cast<AGameDemoFighter>(*I)||*I==this)continue;
|
| 139 |
+
TArray<UMeshComponent*> Cs;I->GetComponents(Cs);
|
| 140 |
+
for(UMeshComponent* C:Cs)
|
| 141 |
+
{
|
| 142 |
+
if(!C->bRenderCustomDepth||C->CustomDepthStencilValue<1||C->CustomDepthStencilValue>6||C->ComponentHasTag(TEXT("v8fx")))continue;
|
| 143 |
+
for(int32 K=0;K<C->GetNumMaterials();K++)if(UMaterialInterface* M=C->GetMaterial(K))
|
| 144 |
+
if(M->GetBlendMode()==BLEND_Opaque&&!Seen.Contains(M)){Seen.Add(M);V9MatPool.Add(M);}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V9 pools: flat=%d tri=%d look=%d textures=%d (photo %d) shuffle materials=%d"),V9FlatMat!=nullptr,V9TriMat!=nullptr,V9LookMID!=nullptr,V9TexPool.Num(),V9NumPhoto,V9MatPool.Num());
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
void APipelineCapture::V9RestoreMaterials()
|
| 151 |
+
{
|
| 152 |
+
for(auto& P:V9Orig)if(UMeshComponent* C=P.Key.Get())for(int32 K=0;K<P.Value.Num();K++)C->SetMaterial(K,P.Value[K]);
|
| 153 |
+
V9Orig.Reset();V9MIDs.Reset();
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
void APipelineCapture::V9ApplyMaterials()
|
| 157 |
+
{
|
| 158 |
+
V9RestoreMaterials();
|
| 159 |
+
if(V9Cur.Mat==0)return;
|
| 160 |
+
if(V9Cur.Mat==5){V10ApplyPBR();return;}
|
| 161 |
+
// one replacement per distinct original material (keeps the scene coherent); a fraction of originals stays
|
| 162 |
+
TMap<UMaterialInterface*,UMaterialInterface*> Map;
|
| 163 |
+
const float Keep=V9Cur.Keep;
|
| 164 |
+
TArray<FLinearColor> Pal;const float H0=V9Rng.FRand();const int32 Scheme=V9Rng.RandRange(0,3);
|
| 165 |
+
for(int32 I=0;I<6;I++)
|
| 166 |
+
{
|
| 167 |
+
const float H=Scheme==0?H0+I*.04f:Scheme==1?H0+(I%2)*.5f:Scheme==2?H0+(I%3)/3.f:V9Rng.FRand();
|
| 168 |
+
Pal.Add(V9Hsv(H,V9Rng.FRandRange(.15f,.8f),V9Rng.FRandRange(.25f,.9f)));
|
| 169 |
+
}
|
| 170 |
+
const float StyShare=V9Rng.FRand()<.35f?.7f:.15f;
|
| 171 |
+
auto MakeFor=[&](UMaterialInterface* Orig)->UMaterialInterface*
|
| 172 |
+
{
|
| 173 |
+
int32 Mode=V9Cur.Mat==4?V9Rng.RandRange(1,3):V9Cur.Mat;
|
| 174 |
+
if(Mode==1&&V9MatPool.Num()>1){int32 K=V9Rng.RandRange(0,V9MatPool.Num()-1);if(V9MatPool[K].Get()==Orig)K=(K+1)%V9MatPool.Num();return V9MatPool[K].Get();}
|
| 175 |
+
if(Mode==3&&V9TriMat&&V9TexPool.Num())
|
| 176 |
+
{
|
| 177 |
+
UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(V9TriMat,this);
|
| 178 |
+
const bool Sty=V9TexPool.Num()>V9NumPhoto&&V9Rng.FRand()<StyShare;
|
| 179 |
+
UTexture* T=Sty?V9TexPool[V9Rng.RandRange(V9NumPhoto,V9TexPool.Num()-1)]:V9TexPool[V9Rng.RandRange(0,FMath::Max(0,V9NumPhoto-1))];
|
| 180 |
+
D->SetTextureParameterValue(TEXT("Tex"),T);D->SetScalarParameterValue(TEXT("Tile"),V9Rng.FRandRange(120.f,520.f));
|
| 181 |
+
const FLinearColor Tint=FLinearColor::LerpUsingHSV(FLinearColor::White,Pal[V9Rng.RandRange(0,Pal.Num()-1)],V9Rng.FRandRange(0.f,.45f));
|
| 182 |
+
D->SetVectorParameterValue(TEXT("Tint"),Tint*V9Rng.FRandRange(.8f,1.15f));D->SetScalarParameterValue(TEXT("Sat"),V9Rng.FRandRange(.5f,1.3f));
|
| 183 |
+
D->SetScalarParameterValue(TEXT("Rough"),V9Rng.FRandRange(.45f,.95f));V9MIDs.Add(D);return D;
|
| 184 |
+
}
|
| 185 |
+
if(V9FlatMat)
|
| 186 |
+
{
|
| 187 |
+
UMaterialInstanceDynamic* D=UMaterialInstanceDynamic::Create(V9FlatMat,this);
|
| 188 |
+
D->SetVectorParameterValue(TEXT("Color"),Pal[V9Rng.RandRange(0,Pal.Num()-1)]*V9Rng.FRandRange(.85f,1.1f));
|
| 189 |
+
D->SetScalarParameterValue(TEXT("Var"),V9Rng.FRandRange(0.f,.3f));D->SetScalarParameterValue(TEXT("Rough"),V9Rng.FRandRange(.4f,1.f));V9MIDs.Add(D);return D;
|
| 190 |
+
}
|
| 191 |
+
return nullptr;
|
| 192 |
+
};
|
| 193 |
+
int32 Comps=0;
|
| 194 |
+
for(TActorIterator<AActor> I(GetWorld());I;++I)
|
| 195 |
+
{
|
| 196 |
+
if(I->ActorHasTag(TEXT("whitebox"))||Cast<AGameDemoFighter>(*I)||*I==this)continue;
|
| 197 |
+
TArray<UMeshComponent*> Cs;I->GetComponents(Cs);
|
| 198 |
+
for(UMeshComponent* C:Cs)
|
| 199 |
+
{
|
| 200 |
+
if(!C->bRenderCustomDepth||C->CustomDepthStencilValue<1||C->CustomDepthStencilValue>6||C->ComponentHasTag(TEXT("v8fx")))continue;
|
| 201 |
+
TArray<UMaterialInterface*> Old;bool Any=false;
|
| 202 |
+
for(int32 K=0;K<C->GetNumMaterials();K++)
|
| 203 |
+
{
|
| 204 |
+
UMaterialInterface* M=C->GetMaterial(K);Old.Add(M);
|
| 205 |
+
if(!M||M->GetBlendMode()!=BLEND_Opaque)continue; // masked / translucent stay: replacing them would change the silhouettes
|
| 206 |
+
UMaterialInterface** Got=Map.Find(M);
|
| 207 |
+
if(!Got){UMaterialInterface* N=V9Rng.FRand()<Keep?M:MakeFor(M);Got=&Map.Add(M,N?N:M);}
|
| 208 |
+
if(*Got!=M){if(!Any){V9Orig.Add(TPair<TWeakObjectPtr<UMeshComponent>,TArray<UMaterialInterface*>>(C,TArray<UMaterialInterface*>()));Any=true;}C->SetMaterial(K,*Got);}
|
| 209 |
+
}
|
| 210 |
+
if(Any){V9Orig.Last().Value=Old;Comps++;}
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
V9MatSwaps+=Comps;
|
| 214 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V9 materials %s: %d originals -> %d components"),V9MatNames[V9Cur.Mat],Map.Num(),Comps);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
void APipelineCapture::V9NewLook()
|
| 218 |
+
{
|
| 219 |
+
V9PendingLook=false;V9LoadPools();
|
| 220 |
+
FV9Look L;
|
| 221 |
+
auto R=[&](float A,float B){return V9Rng.FRandRange(A,B);};
|
| 222 |
+
L.Mode=V9Rng.FRand()<V9StyleP?V9Rng.RandRange(1,9):0;
|
| 223 |
+
const float MR=V9Rng.FRand();L.Mat=MR<V9MatP?(MR<V9MatP*.2f?1:MR<V9MatP*.45f?2:MR<V9MatP*.8f?3:4):0;
|
| 224 |
+
const float TR=V9Rng.FRand();L.Tier=TR<V9UnlitP?3:TR<V9UnlitP+.18f?1:TR<V9UnlitP+.28f?2:0;
|
| 225 |
+
const float MB=V9Rng.FRand();L.Mip=MB<.7f?0.f:MB<.9f?1.5f:3.f;
|
| 226 |
+
L.Outline=V9Rng.FRand()<.55f;L.Keep=V9Rng.FRand()<.3f?R(.3f,.6f):R(0.f,.15f);
|
| 227 |
+
// optional forced look (tests): "mode:mat:tier", -1 = random
|
| 228 |
+
if(!V9Force.IsEmpty()){TArray<FString> P;V9Force.ParseIntoArray(P,TEXT(":"));
|
| 229 |
+
if(P.Num()>0&&FCString::Atoi(*P[0])>=0)L.Mode=FMath::Clamp(FCString::Atoi(*P[0]),0,9);
|
| 230 |
+
if(P.Num()>1&&FCString::Atoi(*P[1])>=0)L.Mat=FMath::Clamp(FCString::Atoi(*P[1]),0,5);
|
| 231 |
+
if(P.Num()>2&&FCString::Atoi(*P[2])>=0)L.Tier=FMath::Clamp(FCString::Atoi(*P[2]),0,3);}
|
| 232 |
+
if(V10Photo)V10PhotoLook(L);
|
| 233 |
+
if(V9Force==TEXT("cycle")&&!V10Photo){L.Mode=V9LookCount%10;L.Mat=(V9LookCount/2)%5;L.Tier=(V9LookCount%7==3)?3:(V9LookCount%5==1?1:0);}
|
| 234 |
+
const float H0=V9Rng.FRand();
|
| 235 |
+
switch(L.Mode)
|
| 236 |
+
{
|
| 237 |
+
case 1: L.P1=(float)V9Rng.RandRange(3,6);L.P2=R(1.f,2.f);break;
|
| 238 |
+
case 2: L.P1=R(2.f,3.f);L.P2=R(1.f,1.4f);break;
|
| 239 |
+
case 3: L.P1=(float)V9Rng.RandRange(3,8);L.P2=(float)V9Rng.RandRange(4,10);L.P3=R(0.f,1.f);break;
|
| 240 |
+
case 4: L.P1=R(4.f,8.f);L.P2=R(1.f,2.f);break;
|
| 241 |
+
case 5: L.CA=V9Hsv(H0,R(.3f,.8f),R(.05f,.2f));L.CB=V9Hsv(H0+R(-.15f,.15f)+(V9Rng.FRand()<.4f?.5f:0.f),R(.3f,.8f),R(.4f,.6f));L.CC=V9Hsv(H0+R(-.1f,.1f),R(.05f,.4f),R(.85f,1.f));break;
|
| 242 |
+
case 6: L.P1=(float)V9Rng.RandRange(1,2);L.P2=(float)V9Rng.RandRange(3,6);break;
|
| 243 |
+
case 7: L.P1=R(.3f,.9f);L.P2=R(1.f,2.f);L.CA=V9Hsv(R(.05f,.6f),R(.03f,.15f),R(.85f,.98f));break;
|
| 244 |
+
case 8: L.P1=R(1.f,3.f);L.P2=R(.4f,.9f);L.P3=R(0.f,.25f);L.CA=V9Hsv(H0,R(0.f,.3f),R(.6f,.95f));break;
|
| 245 |
+
case 9: L.P1=R(.1f,.9f);L.P2=R(.6f,1.6f);L.P3=V9Rng.FRand()<.5f?0.f:(float)V9Rng.RandRange(4,10);break;
|
| 246 |
+
default: break;
|
| 247 |
+
}
|
| 248 |
+
if(!V10Photo)
|
| 249 |
+
{
|
| 250 |
+
const float GS=V9Rng.FRand();
|
| 251 |
+
L.Sat=GS<.08f?R(.1f,.4f):GS<.15f?R(1.45f,1.8f):R(.65f,1.3f);L.Con=R(.85f,1.2f);L.Gam=R(.88f,1.12f);L.Temp=R(4800.f,8200.f);
|
| 252 |
+
L.Gain=FLinearColor::LerpUsingHSV(FLinearColor::White,V9Hsv(V9Rng.FRand(),1.f,1.f),V9Rng.FRand()<.3f?R(.05f,.18f):0.f);
|
| 253 |
+
}
|
| 254 |
+
if(V9Neutral&&!V10Photo){L.Sat=1;L.Con=1;L.Gam=1;L.Temp=6500;L.Gain=FLinearColor::White;L.Outline=true;} // baseline renders (v8 look) for comparisons
|
| 255 |
+
L.Index=V9LookCount++;
|
| 256 |
+
L.Name=FString::Printf(TEXT("%s|%s|%s|mip%.1f|%s"),V9ModeNames[L.Mode],V9MatNames[L.Mat],V9TierNames[L.Tier],L.Mip,L.Outline?TEXT("ol"):TEXT("no"));
|
| 257 |
+
if(V10Photo)L.Name=FString::Printf(TEXT("photo|%s|%s|%s|%s"),*L.LightName,*L.Biome,V9MatNames[L.Mat],L.Outline?TEXT("ol"):TEXT("no"));
|
| 258 |
+
V9Cur=L;V9LookStartFrame=Frame;
|
| 259 |
+
V9ModeHist.FindOrAdd(V9ModeNames[L.Mode])++;
|
| 260 |
+
if(IConsoleVariable* V=IConsoleManager::Get().FindConsoleVariable(TEXT("r.MipMapLODBias")))V->Set(L.Mip,ECVF_SetByCode);
|
| 261 |
+
V9ApplyMaterials();
|
| 262 |
+
TSharedPtr<FJsonObject> J=MakeShared<FJsonObject>();
|
| 263 |
+
J->SetNumberField(TEXT("index"),L.Index);J->SetNumberField(TEXT("frame"),Frame);J->SetNumberField(TEXT("camera_variant"),CameraVariant);J->SetStringField(TEXT("name"),L.Name);
|
| 264 |
+
J->SetStringField(TEXT("style"),V9ModeNames[L.Mode]);J->SetStringField(TEXT("materials"),V9MatNames[L.Mat]);J->SetStringField(TEXT("render_tier"),V9TierNames[L.Tier]);
|
| 265 |
+
J->SetNumberField(TEXT("mip_bias"),L.Mip);J->SetBoolField(TEXT("outline"),L.Outline);J->SetNumberField(TEXT("keep_original_share"),L.Keep);
|
| 266 |
+
J->SetArrayField(TEXT("style_params"),{V9Num(L.P1),V9Num(L.P2),V9Num(L.P3)});
|
| 267 |
+
J->SetArrayField(TEXT("grade_sat_con_gamma_temp"),{V9Num(L.Sat),V9Num(L.Con),V9Num(L.Gam),V9Num(L.Temp)});
|
| 268 |
+
if(V10Photo)V10LookJson(J);
|
| 269 |
+
V9LookLog.Add(MakeShared<FJsonValueObject>(J));
|
| 270 |
+
UE_LOG(LogTemp,Display,TEXT("DATASET_V9 look %d at frame %d: %s"),L.Index,Frame,*L.Name);
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
void APipelineCapture::V9BeforeRGB(USceneCaptureComponent2D* C)
|
| 274 |
+
{
|
| 275 |
+
if(!C)return;
|
| 276 |
+
const FV9Look& L=V9Cur;auto& PP=C->PostProcessSettings;
|
| 277 |
+
C->ShowFlags.SetLighting(L.Tier!=3);
|
| 278 |
+
C->ShowFlags.SetDynamicShadows(L.Tier<2);
|
| 279 |
+
C->ShowFlags.SetAmbientOcclusion(L.Tier==0);
|
| 280 |
+
PP.bOverride_DynamicGlobalIlluminationMethod=true;PP.DynamicGlobalIlluminationMethod=L.Tier==0?EDynamicGlobalIlluminationMethod::Lumen:EDynamicGlobalIlluminationMethod::None;
|
| 281 |
+
PP.bOverride_ReflectionMethod=true;PP.ReflectionMethod=L.Tier==0?EReflectionMethod::Lumen:EReflectionMethod::None;
|
| 282 |
+
PP.bOverride_ColorSaturation=true;PP.ColorSaturation=FVector4(L.Sat,L.Sat,L.Sat,1.f);
|
| 283 |
+
PP.bOverride_ColorContrast=true;PP.ColorContrast=FVector4(L.Con*1.04f,L.Con*1.04f,L.Con*1.04f,1.f);
|
| 284 |
+
PP.bOverride_ColorGamma=true;PP.ColorGamma=FVector4(L.Gam,L.Gam,L.Gam,1.f);
|
| 285 |
+
PP.bOverride_ColorGain=true;PP.ColorGain=FVector4(L.Gain.R,L.Gain.G,L.Gain.B,1.f);
|
| 286 |
+
PP.bOverride_WhiteTemp=true;PP.WhiteTemp=L.Temp;
|
| 287 |
+
bool Has=false;
|
| 288 |
+
for(FWeightedBlendable& B:PP.WeightedBlendables.Array)
|
| 289 |
+
{
|
| 290 |
+
if(V8OutlineMat&&B.Object==V8OutlineMat)B.Weight=L.Outline?1.f:0.f;
|
| 291 |
+
if(V9LookMID&&B.Object==V9LookMID){B.Weight=L.Mode>0?1.f:0.f;Has=true;}
|
| 292 |
+
}
|
| 293 |
+
if(V9LookMID)
|
| 294 |
+
{
|
| 295 |
+
if(!Has)PP.WeightedBlendables.Array.Add(FWeightedBlendable(L.Mode>0?1.f:0.f,V9LookMID));
|
| 296 |
+
UMaterialInstanceDynamic* D=V9LookMID;
|
| 297 |
+
D->SetScalarParameterValue(TEXT("Mode"),(float)L.Mode);D->SetScalarParameterValue(TEXT("P1"),L.P1);D->SetScalarParameterValue(TEXT("P2"),L.P2);
|
| 298 |
+
D->SetScalarParameterValue(TEXT("P3"),L.P3);D->SetScalarParameterValue(TEXT("SS"),(float)V8SS);
|
| 299 |
+
D->SetVectorParameterValue(TEXT("CA"),L.CA);D->SetVectorParameterValue(TEXT("CB"),L.CB);D->SetVectorParameterValue(TEXT("CC"),L.CC);
|
| 300 |
+
}
|
| 301 |
+
if(V10Photo)V10BeforeRGB(C);
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
// ---------------------------------------------------------------------------------------------------------------------
|
| 305 |
+
// capsule labels
|
| 306 |
+
// ---------------------------------------------------------------------------------------------------------------------
|
| 307 |
+
void APipelineCapture::V9BeforeCapture()
|
| 308 |
+
{
|
| 309 |
+
// tests only (-DatasetV9LookSeconds): forced switches also respect the cut grid (the change shows from this frame on)
|
| 310 |
+
const bool GridNow=V9CutGrid<=0||(Frame%V9CutGrid)==(V9CutPhase+1)%V9CutGrid;
|
| 311 |
+
if(V9PendingLook||(V9LookFrames>0&&Frame-V9LookStartFrame>=V9LookFrames&&CaptureStart>=0&&GridNow))V9NewLook();
|
| 312 |
+
if(!V9CapLabels)return;
|
| 313 |
+
for(APipelineWhitebox* P:WhiteboxCharacters)
|
| 314 |
+
{
|
| 315 |
+
if(!P||!P->Fighter)continue;
|
| 316 |
+
const int32 Id=P->Fighter->IsBoss?11:10;
|
| 317 |
+
// weapon capsule: longest axis of the weapon mesh bounds, radius from the other two extents
|
| 318 |
+
UStaticMeshComponent* W=(P->Fighter->IsBoss?V8WeaponB:V8WeaponP).Get();
|
| 319 |
+
if(W&&W->GetAttachParent()!=P->Fighter->GetMesh())W=nullptr;
|
| 320 |
+
TArray<UStaticMeshComponent*> WP;for(UStaticMeshComponent* X:P->Parts)if(X&&X->ComponentHasTag(TEXT("v9w")))WP.Add(X);
|
| 321 |
+
if(WP.Num()==0&&W&&WhiteMaterialRef)
|
| 322 |
+
{
|
| 323 |
+
for(const TCHAR* A:{TEXT("/Engine/BasicShapes/Cylinder.Cylinder"),TEXT("/Engine/BasicShapes/Sphere.Sphere"),TEXT("/Engine/BasicShapes/Sphere.Sphere")})
|
| 324 |
+
{
|
| 325 |
+
UStaticMeshComponent* C=NewObject<UStaticMeshComponent>(P);P->AddInstanceComponent(C);C->SetupAttachment(P->GetRootComponent());
|
| 326 |
+
C->SetStaticMesh(LoadObject<UStaticMesh>(nullptr,A));C->SetMobility(EComponentMobility::Movable);C->SetMaterial(0,WhiteMaterialRef);
|
| 327 |
+
C->SetCollisionEnabled(ECollisionEnabled::NoCollision);C->SetGenerateOverlapEvents(false);C->SetCastShadow(false);
|
| 328 |
+
C->SetAffectDistanceFieldLighting(false);C->SetAffectDynamicIndirectLighting(false);C->SetVisibleInRayTracing(false);C->SetVisibleInSceneCaptureOnly(true);
|
| 329 |
+
C->ComponentTags.Add(TEXT("v9w"));C->RegisterComponent();P->Parts.Add(C);WhiteboxComponents.Add(C);Whitebox->ShowOnlyComponent(C);WP.Add(C);
|
| 330 |
+
}
|
| 331 |
+
}
|
| 332 |
+
TArray<float>& Seg=V9WeaponSeg.FindOrAdd(P);Seg.Reset();
|
| 333 |
+
if(WP.Num()==3)
|
| 334 |
+
{
|
| 335 |
+
const bool Vis=W&&W->IsVisible()&&W->GetStaticMesh();
|
| 336 |
+
for(UStaticMeshComponent* X:WP)X->SetVisibility(Vis);
|
| 337 |
+
if(Vis)
|
| 338 |
+
{
|
| 339 |
+
const FBox B=W->GetStaticMesh()->GetBoundingBox();const FVector E=B.GetExtent()*W->GetComponentScale().GetAbs();const FVector Ctr=B.GetCenter();
|
| 340 |
+
const int32 Ax=E.X>=E.Y&&E.X>=E.Z?0:(E.Y>=E.Z?1:2);
|
| 341 |
+
FVector Dir=FVector::ZeroVector;Dir[Ax]=B.GetExtent()[Ax];
|
| 342 |
+
const FTransform T=W->GetComponentTransform();
|
| 343 |
+
const FVector A=T.TransformPosition(Ctr-Dir),Bp=T.TransformPosition(Ctr+Dir);
|
| 344 |
+
const float Len=FVector::Dist(A,Bp);
|
| 345 |
+
const float O1=E[(Ax+1)%3],O2=E[(Ax+2)%3];
|
| 346 |
+
const float Rad=FMath::Clamp(.5f*FMath::Sqrt(O1*O2),2.5f,FMath::Max(3.f,.08f*Len));
|
| 347 |
+
const FVector D=Bp-A;
|
| 348 |
+
WP[0]->SetWorldLocationAndRotation((A+Bp)*.5f,FQuat::FindBetweenNormals(FVector::UpVector,D.GetSafeNormal()));
|
| 349 |
+
WP[0]->SetWorldScale3D(FVector(Rad/50.f,Rad/50.f,FMath::Max(.001f,Len/100.f)));
|
| 350 |
+
WP[1]->SetWorldLocation(A);WP[2]->SetWorldLocation(Bp);WP[1]->SetWorldScale3D(FVector(Rad/50.f));WP[2]->SetWorldScale3D(FVector(Rad/50.f));
|
| 351 |
+
Seg={(float)A.X,(float)A.Y,(float)A.Z,(float)Bp.X,(float)Bp.Y,(float)Bp.Z,Rad};
|
| 352 |
+
}
|
| 353 |
+
}
|
| 354 |
+
for(UStaticMeshComponent* X:P->Parts)if(X&&(!X->bRenderCustomDepth||X->CustomDepthStencilValue!=Id)){X->SetRenderCustomDepth(true);X->SetCustomDepthStencilValue(Id);}
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
void APipelineCapture::V9LabelHide(USceneCaptureComponent2D* C)
|
| 359 |
+
{
|
| 360 |
+
TSet<UPrimitiveComponent*> Proxy;
|
| 361 |
+
for(APipelineWhitebox* P:WhiteboxCharacters)if(P)for(UStaticMeshComponent* X:P->Parts)Proxy.Add(X);
|
| 362 |
+
for(UPrimitiveComponent* P:WhiteboxComponents)if(!Proxy.Contains(P))C->HideComponent(P);
|
| 363 |
+
for(TActorIterator<AGameDemoFighter> I(GetWorld());I;++I){TArray<UPrimitiveComponent*> Cs;I->GetComponents(Cs);for(UPrimitiveComponent* X:Cs)C->HideComponent(X);}
|
| 364 |
+
for(UStaticMeshComponent* W:{V8WeaponP.Get(),V8WeaponB.Get()})if(W)C->HideComponent(W);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
bool APipelineCapture::V9UseCapsules() const {return V9&&V9CapLabels&&WhiteboxCharacters.Num()>0;}
|
| 368 |
+
|
| 369 |
+
void APipelineCapture::V9WriteFrame(TSharedPtr<FJsonObject> J)
|
| 370 |
+
{
|
| 371 |
+
TSharedPtr<FJsonObject> O=MakeShared<FJsonObject>();
|
| 372 |
+
O->SetNumberField(TEXT("look"),V9Cur.Index);O->SetStringField(TEXT("look_name"),V9Cur.Name);
|
| 373 |
+
O->SetBoolField(TEXT("capsule_labels"),V9UseCapsules());
|
| 374 |
+
O->SetArrayField(TEXT("frame_offset_cm"),{V9Num(V9Offset.X),V9Num(V9Offset.Y),V9Num(V9Offset.Z)});
|
| 375 |
+
TArray<TSharedPtr<FJsonValue>> Caps;
|
| 376 |
+
for(APipelineWhitebox* P:WhiteboxCharacters)
|
| 377 |
+
{
|
| 378 |
+
if(!P||!P->Fighter)continue;
|
| 379 |
+
TSharedPtr<FJsonObject> C=MakeShared<FJsonObject>();
|
| 380 |
+
C->SetStringField(TEXT("role"),P->Fighter->IsBoss?TEXT("boss"):TEXT("player"));C->SetNumberField(TEXT("class_id"),P->Fighter->IsBoss?11:10);
|
| 381 |
+
TArray<TSharedPtr<FJsonValue>> Ls;
|
| 382 |
+
static const TCHAR* LimbNames[11]={TEXT("pelvis_spine"),TEXT("spine_neck"),TEXT("head"),TEXT("l_upperarm"),TEXT("l_forearm"),TEXT("r_upperarm"),TEXT("r_forearm"),TEXT("l_thigh"),TEXT("l_calf"),TEXT("r_thigh"),TEXT("r_calf")};
|
| 383 |
+
for(int32 K=0;K<P->Limbs.Num();K++)
|
| 384 |
+
{
|
| 385 |
+
const FWhiteboxLimb& L=P->Limbs[K];
|
| 386 |
+
TSharedPtr<FJsonObject> E=MakeShared<FJsonObject>();E->SetStringField(TEXT("name"),K<11?LimbNames[K]:TEXT("limb"));
|
| 387 |
+
E->SetArrayField(TEXT("a"),{V9Num(L.A.X),V9Num(L.A.Y),V9Num(L.A.Z)});E->SetArrayField(TEXT("b"),{V9Num(L.B.X),V9Num(L.B.Y),V9Num(L.B.Z)});E->SetNumberField(TEXT("r"),L.Radius);
|
| 388 |
+
Ls.Add(MakeShared<FJsonValueObject>(E));
|
| 389 |
+
}
|
| 390 |
+
if(const TArray<float>* S=V9WeaponSeg.Find(P))if(S->Num()==7)
|
| 391 |
+
{
|
| 392 |
+
TSharedPtr<FJsonObject> E=MakeShared<FJsonObject>();E->SetStringField(TEXT("name"),TEXT("weapon"));
|
| 393 |
+
E->SetArrayField(TEXT("a"),{V9Num((*S)[0]),V9Num((*S)[1]),V9Num((*S)[2])});E->SetArrayField(TEXT("b"),{V9Num((*S)[3]),V9Num((*S)[4]),V9Num((*S)[5])});E->SetNumberField(TEXT("r"),(*S)[6]);
|
| 394 |
+
Ls.Add(MakeShared<FJsonValueObject>(E));
|
| 395 |
+
}
|
| 396 |
+
C->SetArrayField(TEXT("capsules"),Ls);Caps.Add(MakeShared<FJsonValueObject>(C));
|
| 397 |
+
}
|
| 398 |
+
O->SetArrayField(TEXT("characters"),Caps);
|
| 399 |
+
J->SetObjectField(TEXT("v9"),O);
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
void APipelineCapture::WriteV9Result(TSharedPtr<FJsonObject> Result)
|
| 403 |
+
{
|
| 404 |
+
if(!V9)return;
|
| 405 |
+
TSharedPtr<FJsonObject> O=MakeShared<FJsonObject>();
|
| 406 |
+
O->SetBoolField(TEXT("capsule_labels"),V9CapLabels);O->SetBoolField(TEXT("framing"),V9Frame);
|
| 407 |
+
O->SetArrayField(TEXT("ortho_width_range_cm"),{V9Num(V9WMin),V9Num(V9WMax)});O->SetNumberField(TEXT("wide_share"),V9WideP);
|
| 408 |
+
O->SetArrayField(TEXT("wide_width_range_cm"),{V9Num(V9WideMin),V9Num(V9WideMax)});O->SetArrayField(TEXT("pitch_range_deg"),{V9Num(V9PitchMin),V9Num(V9PitchMax)});
|
| 409 |
+
O->SetNumberField(TEXT("looks"),V9LookCount);O->SetNumberField(TEXT("cut_grid"),V9CutGrid);O->SetNumberField(TEXT("cut_phase"),V9CutPhase);O->SetNumberField(TEXT("resets_deferred_blocks"),V9CutsDeferred);
|
| 410 |
+
O->SetStringField(TEXT("clip_rule"),FString::Printf(TEXT("81-frame clips start at multiples of %d; cuts only between frame %d+%d*k and the next"),V9CutGrid,V9CutPhase,V9CutGrid));O->SetNumberField(TEXT("material_swapped_components"),V9MatSwaps);
|
| 411 |
+
O->SetNumberField(TEXT("texture_pool"),V9TexPool.Num());O->SetNumberField(TEXT("texture_pool_photo"),V9NumPhoto);O->SetNumberField(TEXT("shuffle_pool"),V9MatPool.Num());
|
| 412 |
+
TSharedPtr<FJsonObject> H=MakeShared<FJsonObject>();for(const auto& P:V9ModeHist)H->SetNumberField(P.Key,P.Value);O->SetObjectField(TEXT("style_histogram"),H);
|
| 413 |
+
O->SetArrayField(TEXT("look_log"),V9LookLog);
|
| 414 |
+
WriteV10Real(O);
|
| 415 |
+
Result->SetObjectField(TEXT("v9"),O);
|
| 416 |
+
}
|
code/ue_capture/run_all_v10.ps1
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param([int]$Frames=4800,[int]$Rounds=12,[string[]]$Roots=@('F:\GameCrafter_v10\raw','E:\GameCrafter_v10\raw','H:\GameCrafter_v10\raw','G:\GameCrafter_v10\raw'),
|
| 2 |
+
[datetime]$NoStartAfter=[datetime]'2026-10-23 18:00',[int]$MinFreeGB=30,[string[]]$Only=@(),[string]$TagPrefix='R10',[int]$SeedOffset=0,[string]$ExtraEngine='',[double]$LookSeconds=6)
|
| 3 |
+
# v10 real production ("realistic cinematic", same config as the approved v10real23 pilot): photoreal biome re-scatter on the scene's
|
| 4 |
+
# walkable ground, telephoto camera, player kept centred (no fight framing), a new look (biome variant, light preset, camera) every
|
| 5 |
+
# LookSeconds on the 96-frame cut grid so every 81-frame clip has one look. Per run: new seeds, random mirror X.
|
| 6 |
+
# After each run cond.png is written in the background. Stops at jobs\STOP_V10 or when no drive keeps MinFreeGB.
|
| 7 |
+
$ErrorActionPreference='Continue'
|
| 8 |
+
$cw='G:\GameCrafter\capture_work'; $rc=Join-Path $cw 'v6\run_capture_v6.ps1'; $py='E:\Anaconda3\python.exe'
|
| 9 |
+
$runlog="$cw\v10\out\run_all_v10.txt"
|
| 10 |
+
function Log([string]$m){ $line="$(Get-Date -Format o) $m"; Add-Content -Path $runlog -Value $line; Write-Output $line }
|
| 11 |
+
function PickRoot(){ foreach($r in $Roots){ $q=$r.Substring(0,1); $f=(Get-PSDrive -Name $q).Free/1GB; if($f -ge $MinFreeGB){ New-Item -ItemType Directory -Force -Path $r | Out-Null; return $r } }; return $null }
|
| 12 |
+
$scenes=@(Get-ChildItem $cw -Directory | Where-Object { $_.Name -match '^\d\d_' } | Sort-Object Name | ForEach-Object { $_.Name })
|
| 13 |
+
if($Only.Count){ $scenes=@($scenes | Where-Object { $Only -contains $_.Substring(0,2) }) }
|
| 14 |
+
$sig='[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags);'
|
| 15 |
+
$power=Add-Type -MemberDefinition $sig -Name 'PowerV10' -Namespace 'GameCrafterV10' -PassThru
|
| 16 |
+
$ls=$LookSeconds.ToString('0.##',[Globalization.CultureInfo]::InvariantCulture)
|
| 17 |
+
Log "run_all_v10 start scenes=$($scenes.Count) rounds=$Rounds frames=$Frames look=${ls}s until $NoStartAfter prefix=$TagPrefix seedoffset=$SeedOffset extra=$ExtraEngine"
|
| 18 |
+
$warm=@{}
|
| 19 |
+
for($r=1;$r -le $Rounds;$r++){
|
| 20 |
+
foreach($s in $scenes){
|
| 21 |
+
[void]$power::SetThreadExecutionState([uint32]2147483649)
|
| 22 |
+
if(Test-Path (Join-Path $cw 'jobs\STOP_V10')){ Log 'stop flag found'; exit 0 }
|
| 23 |
+
if((Get-Date) -gt $NoStartAfter){ Log "past $NoStartAfter, not starting more runs"; exit 0 }
|
| 24 |
+
$root=PickRoot; if(-not $root){ Log 'no drive with enough free space, stopping'; exit 0 }
|
| 25 |
+
$i=[int]$s.Substring(0,2); $seed=$i*1000+500+$r+$SeedOffset
|
| 26 |
+
$rng=New-Object System.Random $seed
|
| 27 |
+
$mx=$rng.NextDouble() -lt 0.5; $my=$false # mirror Y was not part of the approved v10 real pilot; keep it off
|
| 28 |
+
$eng="DatasetArtPass,DatasetV8,DatasetV8Share=1.0,DatasetV9,DatasetV9NoFraming,DatasetV10Real,DatasetV9LookSeconds=$ls"; if($ExtraEngine){ $eng+=','+$ExtraEngine }
|
| 29 |
+
$tag="${TagPrefix}_s$seed"
|
| 30 |
+
$done=$false; foreach($rr in $Roots){ $res=Join-Path $rr "${s}_$tag\capture_result.json"; if(Test-Path $res){ try{ if([bool](Get-Content $res -Raw | ConvertFrom-Json).ok){ $done=$true } }catch{} } }
|
| 31 |
+
if($done){ Log "skip $s $tag"; continue }
|
| 32 |
+
$dir=Join-Path $root "${s}_$tag"
|
| 33 |
+
if(Test-Path $dir){ Rename-Item $dir "${s}_${tag}_failed_$(Get-Date -Format yyyyMMddHHmmss)" }
|
| 34 |
+
$a=@('-NoProfile','-ExecutionPolicy','Bypass','-File',$rc,'-Scene',$s,'-Frames',"$Frames",'-Tag',$tag,'-Seed',"$seed",'-LayoutSeed',"$($seed*7+3)",
|
| 35 |
+
'-Appearance','default','-AppearanceSeed',"$($seed*3+1)",'-OutRoot',$root,'-EngineArgs',$eng)
|
| 36 |
+
if($mx){ $a+='-Mirror' }; if($my){ $a+='-MirrorY' }
|
| 37 |
+
if(-not $warm[$s]){ # first run of a scene after the build: short warm-up so shaders / textures are cached
|
| 38 |
+
$w=@($a | ForEach-Object { $_ }); $w[$w.IndexOf('-Frames')+1]='32'; $w[$w.IndexOf('-Tag')+1]="${tag}_warm"; $w[$w.IndexOf('-OutRoot')+1]='H:\GameCrafter_v10\warm'
|
| 39 |
+
& powershell.exe @w | Out-Null; Log "warmup $s exit $LASTEXITCODE"; $warm[$s]=$true }
|
| 40 |
+
Log "capture $s $tag root=$root mx=$mx my=$my"
|
| 41 |
+
$t0=Get-Date; & powershell.exe @a | Out-Null; $ec=$LASTEXITCODE
|
| 42 |
+
$okRun=$false; $extra=''; $res=Join-Path $dir 'capture_result.json'
|
| 43 |
+
if(Test-Path $res){ try{ $j=Get-Content $res -Raw | ConvertFrom-Json; $okRun=[bool]$j.ok; $extra="looks=$($j.v9.looks) variants=$((@($j.v9.v10_real.variants_used) | Select-Object -Unique).Count) fight_blocks=$($j.fight_blocks)/$($j.total_blocks)" }catch{} }
|
| 44 |
+
if(-not $okRun){
|
| 45 |
+
Log "capture $s $tag exit $ec ok=False -> retry in 120 s"; Start-Sleep 120
|
| 46 |
+
if(Test-Path $dir){ Rename-Item $dir "${s}_${tag}_failed_$(Get-Date -Format yyyyMMddHHmmss)" }
|
| 47 |
+
& powershell.exe @a | Out-Null; $ec=$LASTEXITCODE
|
| 48 |
+
if(Test-Path $res){ try{ $j=Get-Content $res -Raw | ConvertFrom-Json; $okRun=[bool]$j.ok; $extra="looks=$($j.v9.looks) variants=$((@($j.v9.v10_real.variants_used) | Select-Object -Unique).Count) fight_blocks=$($j.fight_blocks)/$($j.total_blocks) (retry)" }catch{} }
|
| 49 |
+
}
|
| 50 |
+
Log "capture $s $tag exit $ec ok=$okRun secs=$([int]((Get-Date)-$t0).TotalSeconds) $extra"
|
| 51 |
+
if($okRun){ Start-Process -FilePath $py -ArgumentList @("$cw\v9\post\cond_v9.py",$dir) -WindowStyle Hidden -RedirectStandardOutput "$dir\cond_stdout.txt" -RedirectStandardError "$dir\cond_stderr.txt" | Out-Null }
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
Log 'run_all_v10 done'
|
code/ue_capture/run_all_v9.ps1
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param([int]$Frames=4800,[int]$Rounds=20,[string[]]$Roots=@('D:\GameCrafter_v9\raw','E:\GameCrafter_v9\raw','F:\GameCrafter_v9\raw','H:\GameCrafter_v9\raw'),
|
| 2 |
+
[datetime]$NoStartAfter=[datetime]'2026-10-20 12:00',[int]$MinFreeGB=30,[string[]]$Only=@(),[string]$TagPrefix='P9',[int]$SeedOffset=0,[string]$ExtraEngine='')
|
| 3 |
+
# v9 production queue: diversity first. Per run (seeded): random base appearance, layout remix strength, cross-scene donors /
|
| 4 |
+
# strength / style donor, mirror X / Y, theme-aware dressing on / off; inside the run every camera variant gets a new random
|
| 5 |
+
# look (post-process style, material randomisation, render tier, mip bias, colour grade, outline). Capsule character labels,
|
| 6 |
+
# closer framed camera. After each run the cond.png images are written in the background. Stops at jobs\STOP_V9.
|
| 7 |
+
$ErrorActionPreference='Continue'
|
| 8 |
+
$cw='G:\GameCrafter\capture_work'; $rc=Join-Path $cw 'v6\run_capture_v6.ps1'; $py='E:\Anaconda3\python.exe'
|
| 9 |
+
$runlog="$cw\v9\out\run_all_v9.txt"
|
| 10 |
+
function Log([string]$m){ $line="$(Get-Date -Format o) $m"; Add-Content -Path $runlog -Value $line; Write-Output $line }
|
| 11 |
+
function PickRoot(){ foreach($r in $Roots){ $q=$r.Substring(0,1); $f=(Get-PSDrive -Name $q).Free/1GB; if($f -ge $MinFreeGB){ New-Item -ItemType Directory -Force -Path $r | Out-Null; return $r } }; return $null }
|
| 12 |
+
$scenes=@(Get-ChildItem $cw -Directory | Where-Object { $_.Name -match '^\d\d_' } | Sort-Object Name | ForEach-Object { $_.Name })
|
| 13 |
+
if($Only.Count){ $scenes=@($scenes | Where-Object { $Only -contains $_.Substring(0,2) }) }
|
| 14 |
+
$apps=@('default','default','default','golden','overcast','snow','autumn','palette')
|
| 15 |
+
$sig='[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags);'
|
| 16 |
+
$power=Add-Type -MemberDefinition $sig -Name 'PowerV9' -Namespace 'GameCrafterV9' -PassThru
|
| 17 |
+
Log "run_all_v9 start scenes=$($scenes.Count) rounds=$Rounds frames=$Frames until $NoStartAfter prefix=$TagPrefix seedoffset=$SeedOffset extra=$ExtraEngine"
|
| 18 |
+
for($r=1;$r -le $Rounds;$r++){
|
| 19 |
+
foreach($s in $scenes){
|
| 20 |
+
[void]$power::SetThreadExecutionState([uint32]2147483649)
|
| 21 |
+
if(Test-Path (Join-Path $cw 'jobs\STOP_V9')){ Log 'stop flag found'; exit 0 }
|
| 22 |
+
if((Get-Date) -gt $NoStartAfter){ Log "past $NoStartAfter, not starting more runs"; exit 0 }
|
| 23 |
+
$root=PickRoot; if(-not $root){ Log 'no drive with enough free space, stopping'; exit 0 }
|
| 24 |
+
$i=[int]$s.Substring(0,2); $seed=$i*1000+900+$r+$SeedOffset
|
| 25 |
+
$rng=New-Object System.Random $seed
|
| 26 |
+
$app=$apps[$rng.Next($apps.Count)]
|
| 27 |
+
$others=@(1..10 | Where-Object { $_ -ne $i } | ForEach-Object { '{0:D2}' -f $_ } | Sort-Object { $rng.Next() })
|
| 28 |
+
$nd=2+$rng.Next(3); $donors=($others[0..($nd-1)] -join '+')
|
| 29 |
+
$remix=[math]::Round(0.4+0.8*$rng.NextDouble(),2); $strength=[math]::Round(0.6+1.4*$rng.NextDouble(),2)
|
| 30 |
+
$style=''; $amount=0.0; if($rng.NextDouble() -lt 0.4){ $style=$others[$nd]; $amount=[math]::Round(0.5+0.5*$rng.NextDouble(),2) }
|
| 31 |
+
$mx=$rng.NextDouble() -lt 0.5; $my=$rng.NextDouble() -lt 0.5; $notheme=$rng.NextDouble() -lt 0.5
|
| 32 |
+
$eng='DatasetArtPass,DatasetV8,DatasetV8Share=1.0,DatasetV9'; if($notheme){ $eng+=',DatasetV8NoTheme' }; if($ExtraEngine){ $eng+=','+$ExtraEngine }
|
| 33 |
+
$tag="${TagPrefix}_${app}_s$seed"
|
| 34 |
+
$done=$false; foreach($rr in $Roots){ $res=Join-Path $rr "${s}_$tag\capture_result.json"; if(Test-Path $res){ try{ if([bool](Get-Content $res -Raw | ConvertFrom-Json).ok){ $done=$true } }catch{} } }
|
| 35 |
+
if($done){ Log "skip $s $tag"; continue }
|
| 36 |
+
$dir=Join-Path $root "${s}_$tag"
|
| 37 |
+
if(Test-Path $dir){ Rename-Item $dir "${s}_${tag}_failed_$(Get-Date -Format yyyyMMddHHmmss)" }
|
| 38 |
+
$a=@('-NoProfile','-ExecutionPolicy','Bypass','-File',$rc,'-Scene',$s,'-Frames',"$Frames",'-Tag',$tag,'-Seed',"$seed",'-LayoutSeed',"$($seed*7+3)",
|
| 39 |
+
'-Appearance',$app,'-AppearanceSeed',"$($seed*3+1)",'-OutRoot',$root,'-Remix','-RemixStrength',"$remix",'-Cross','-Donors',$donors,'-CrossStrength',"$strength",'-EngineArgs',$eng)
|
| 40 |
+
if($style){ $a+=@('-StyleDonor',$style,'-StyleAmount',"$amount") }
|
| 41 |
+
if($mx){ $a+='-Mirror' }; if($my){ $a+='-MirrorY' }
|
| 42 |
+
Log "capture $s $tag root=$root donors=$donors style=$style/$amount strength=$strength remix=$remix mx=$mx my=$my notheme=$notheme"
|
| 43 |
+
$t0=Get-Date; & powershell.exe @a | Out-Null
|
| 44 |
+
$okRun=$false; $extra=''; $res=Join-Path $dir 'capture_result.json'
|
| 45 |
+
if(Test-Path $res){ try{ $j=Get-Content $res -Raw | ConvertFrom-Json; $okRun=[bool]$j.ok; $extra="looks=$($j.v9.looks) tex=$($j.v9.texture_pool) styles=$($j.v9.style_histogram | ConvertTo-Json -Compress)" }catch{} }
|
| 46 |
+
Log "capture $s $tag exit $LASTEXITCODE ok=$okRun secs=$([int]((Get-Date)-$t0).TotalSeconds) $extra"
|
| 47 |
+
if($okRun){ Start-Process -FilePath $py -ArgumentList @("$cw\v9\post\cond_v9.py",$dir) -WindowStyle Hidden -RedirectStandardOutput "$dir\cond_stdout.txt" -RedirectStandardError "$dir\cond_stderr.txt" | Out-Null }
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
Log 'run_all_v9 done'
|
code/ue_capture/v10_masters4.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# v10 real diversity: rebuild the model masters M_V10Mesh (opaque) and M_V10Foliage (masked, two sided foliage) in place
|
| 2 |
+
# (the 258 material instances keep their textures) with a per-look cover layer: CovColor / CovAmt / CovRough put snow,
|
| 3 |
+
# moss, dust or sand on upward faces (world normal, value-noise patches), Tint / RMul give seasons and wet looks.
|
| 4 |
+
import unreal as u, os, traceback
|
| 5 |
+
MEL = u.MaterialEditingLibrary; EAL = u.EditorAssetLibrary
|
| 6 |
+
V10 = os.path.dirname(os.path.dirname(os.path.abspath(__file__))); LOG = os.path.join(V10, 'out', 'v10_masters4_log.txt'); open(LOG, 'w').close()
|
| 7 |
+
def log(m):
|
| 8 |
+
with open(LOG, 'a', encoding='utf-8') as f: f.write(str(m) + '\n')
|
| 9 |
+
F3, F1 = u.CustomMaterialOutputType.CMOT_FLOAT3, u.CustomMaterialOutputType.CMOT_FLOAT1
|
| 10 |
+
COV = r'''
|
| 11 |
+
float2 q = WP.xy / 70.0; float2 qi = floor(q); float2 qf = frac(q); qf = qf * qf * (3 - 2 * qf);
|
| 12 |
+
float a = frac(sin(dot(qi, float2(127.1, 311.7))) * 43758.5453), b = frac(sin(dot(qi + float2(1, 0), float2(127.1, 311.7))) * 43758.5453);
|
| 13 |
+
float c = frac(sin(dot(qi + float2(0, 1), float2(127.1, 311.7))) * 43758.5453), d = frac(sin(dot(qi + float2(1, 1), float2(127.1, 311.7))) * 43758.5453);
|
| 14 |
+
float nz = lerp(lerp(a, b, qf.x), lerp(c, d, qf.x), qf.y);
|
| 15 |
+
float2 r = WP.xy / 17.0; float2 ri = floor(r); float2 rf = frac(r); rf = rf * rf * (3 - 2 * rf);
|
| 16 |
+
float a2 = frac(sin(dot(ri, float2(127.1, 311.7))) * 43758.5453), b2 = frac(sin(dot(ri + float2(1, 0), float2(127.1, 311.7))) * 43758.5453);
|
| 17 |
+
float c2 = frac(sin(dot(ri + float2(0, 1), float2(127.1, 311.7))) * 43758.5453), d2 = frac(sin(dot(ri + float2(1, 1), float2(127.1, 311.7))) * 43758.5453);
|
| 18 |
+
float nz2 = lerp(lerp(a2, b2, rf.x), lerp(c2, d2, rf.x), rf.y);
|
| 19 |
+
float m = saturate(CovAmt * 1.6) * smoothstep(0.25 + 0.5 * (1 - CovAmt), 0.9, normalize(NW).z * 0.85 + nz * 0.3 + (nz2 - 0.5) * 0.3);
|
| 20 |
+
'''
|
| 21 |
+
def build(name, foliage):
|
| 22 |
+
m = u.load_asset('/Game/Xfer/V10/Materials/' + name)
|
| 23 |
+
defs = {}
|
| 24 |
+
for n in ('BC', 'NM', 'RT', 'OP'):
|
| 25 |
+
try: defs[n] = MEL.get_material_default_texture_parameter_value(m, n)
|
| 26 |
+
except Exception: pass
|
| 27 |
+
MEL.delete_all_material_expressions(m)
|
| 28 |
+
for f in ('used_with_instanced_static_meshes', 'used_with_nanite'): m.set_editor_property(f, True)
|
| 29 |
+
if foliage:
|
| 30 |
+
m.set_editor_property('blend_mode', u.BlendMode.BLEND_MASKED); m.set_editor_property('two_sided', True)
|
| 31 |
+
m.set_editor_property('shading_model', u.MaterialShadingModel.MSM_TWO_SIDED_FOLIAGE); m.set_editor_property('opacity_mask_clip_value', .8)
|
| 32 |
+
m.set_editor_property('tangent_space_normal', False)
|
| 33 |
+
uv = MEL.create_material_expression(m, u.MaterialExpressionTextureCoordinate, -1700, 0)
|
| 34 |
+
wp = MEL.create_material_expression(m, u.MaterialExpressionWorldPosition, -1700, 120)
|
| 35 |
+
nw = MEL.create_material_expression(m, u.MaterialExpressionVertexNormalWS, -1700, 220)
|
| 36 |
+
T = {}
|
| 37 |
+
names = [('BC', u.MaterialSamplerType.SAMPLERTYPE_COLOR), ('NM', u.MaterialSamplerType.SAMPLERTYPE_NORMAL), ('RT', u.MaterialSamplerType.SAMPLERTYPE_LINEAR_COLOR)] + ([('OP', u.MaterialSamplerType.SAMPLERTYPE_LINEAR_COLOR)] if foliage else [])
|
| 38 |
+
for k, (nm, st) in enumerate(names):
|
| 39 |
+
e = MEL.create_material_expression(m, u.MaterialExpressionTextureObjectParameter, -1500, -200 + 150 * k); e.set_editor_property('parameter_name', nm); e.set_editor_property('sampler_type', st)
|
| 40 |
+
if defs.get(nm): e.set_editor_property('texture', defs[nm])
|
| 41 |
+
T[nm] = e
|
| 42 |
+
P = {}
|
| 43 |
+
sc = [('RMul', 1.0), ('MetalAmt', 0.0), ('AOAmt', 1.0), ('SSSAmt', .55), ('CovAmt', 0.0), ('CovRough', .8), ('CovDetail', .8), ('Bright', 1.12 if foliage else 1.0), ('SeasonAmt', 0.0)] + ([('UpBend', .5), ('AOScale', .5)] if foliage else [])
|
| 44 |
+
for k, (nm, dv) in enumerate(sc):
|
| 45 |
+
e = MEL.create_material_expression(m, u.MaterialExpressionScalarParameter, -1500, 500 + 80 * k); e.set_editor_property('parameter_name', nm); e.set_editor_property('default_value', dv); P[nm] = e
|
| 46 |
+
for k, (nm, dv) in enumerate([('Tint', u.LinearColor(1, 1, 1, 1)), ('RCh', u.LinearColor(0, 1, 0, 0)), ('CovColor', u.LinearColor(.9, .92, .95, 1)), ('SeasonCol', u.LinearColor(1, .45, .12, 1))]):
|
| 47 |
+
e = MEL.create_material_expression(m, u.MaterialExpressionVectorParameter, -1500, 1300 + 90 * k); e.set_editor_property('parameter_name', nm); e.set_editor_property('default_value', dv); P[nm] = e
|
| 48 |
+
def node(code, ins, out, y, x=-700):
|
| 49 |
+
c = MEL.create_material_expression(m, u.MaterialExpressionCustom, x, y); c.set_editor_property('code', code); c.set_editor_property('output_type', out)
|
| 50 |
+
L = []
|
| 51 |
+
for n in ['UV'] + ins:
|
| 52 |
+
ci = u.CustomInput(); ci.set_editor_property('input_name', n); L.append(ci)
|
| 53 |
+
c.set_editor_property('inputs', L); MEL.connect_material_expressions(uv, '', c, 'UV')
|
| 54 |
+
for n in ins:
|
| 55 |
+
src = T.get(n) or P.get(n) or {'WP': wp, 'NW': nw}.get(n)
|
| 56 |
+
MEL.connect_material_expressions(src, '', c, n)
|
| 57 |
+
return c
|
| 58 |
+
samp = 'Texture2DSampleBias(BC, BCSampler, UV, -1)' if foliage else 'Texture2DSample(BC, BCSampler, UV)'
|
| 59 |
+
SEA = 'float lum = dot(col, float3(0.3, 0.59, 0.11)); col = lerp(col, lum * SeasonCol.rgb * 2.2, saturate(SeasonAmt));'
|
| 60 |
+
MEL.connect_material_property(node(COV + 'float3 col = %s.rgb * Tint.rgb * Bright; ' % samp + SEA + ' float lc = dot(col, float3(0.3, 0.59, 0.11)); float3 cv = CovColor.rgb * lerp(1.0, saturate(0.45 + 2.2 * lc), CovDetail); return lerp(col, cv, m);', ['BC', 'Tint', 'Bright', 'CovColor', 'CovAmt', 'CovDetail', 'WP', 'NW', 'SeasonCol', 'SeasonAmt'], F3, -300), '', u.MaterialProperty.MP_BASE_COLOR)
|
| 61 |
+
if foliage:
|
| 62 |
+
tn = node('float2 t = Texture2DSample(NM, NMSampler, UV).xy * 2 - 1; return float3(t, sqrt(saturate(1 - dot(t, t))));', ['NM'], F3, -100, -1000)
|
| 63 |
+
tr = MEL.create_material_expression(m, u.MaterialExpressionTransform, -800, -100)
|
| 64 |
+
tr.set_editor_property('transform_source_type', u.MaterialVectorCoordTransformSource.TRANSFORMSOURCE_TANGENT); tr.set_editor_property('transform_type', u.MaterialVectorCoordTransform.TRANSFORM_WORLD)
|
| 65 |
+
MEL.connect_material_expressions(tn, '', tr, '')
|
| 66 |
+
bend = MEL.create_material_expression(m, u.MaterialExpressionCustom, -500, -100); bend.set_editor_property('code', 'return normalize(lerp(normalize(Nw), float3(0, 0, 1), saturate(UpBend)));'); bend.set_editor_property('output_type', F3)
|
| 67 |
+
L = []
|
| 68 |
+
for n in ('Nw', 'UpBend'):
|
| 69 |
+
ci = u.CustomInput(); ci.set_editor_property('input_name', n); L.append(ci)
|
| 70 |
+
bend.set_editor_property('inputs', L); MEL.connect_material_expressions(tr, '', bend, 'Nw'); MEL.connect_material_expressions(P['UpBend'], '', bend, 'UpBend')
|
| 71 |
+
MEL.connect_material_property(bend, '', u.MaterialProperty.MP_NORMAL)
|
| 72 |
+
MEL.connect_material_property(node('return lerp(1, Texture2DSample(RT, RTSampler, UV).r, AOAmt * AOScale);', ['RT', 'AOAmt', 'AOScale'], F1, 250), '', u.MaterialProperty.MP_AMBIENT_OCCLUSION)
|
| 73 |
+
MEL.connect_material_property(node('return Texture2DSampleBias(OP, OPSampler, UV, -1).r;', ['OP'], F1, 400), '', u.MaterialProperty.MP_OPACITY_MASK)
|
| 74 |
+
MEL.connect_material_property(node(COV + 'float3 col = Texture2DSample(BC, BCSampler, UV).rgb * Tint.rgb; ' + SEA + ' float lc = dot(col, float3(0.3, 0.59, 0.11)); float3 cv = CovColor.rgb * lerp(1.0, saturate(0.45 + 2.2 * lc), CovDetail); return lerp(col, cv, m) * SSSAmt;', ['BC', 'Tint', 'SSSAmt', 'CovColor', 'CovAmt', 'CovDetail', 'WP', 'NW', 'SeasonCol', 'SeasonAmt'], F3, 550), '', u.MaterialProperty.MP_SUBSURFACE_COLOR)
|
| 75 |
+
else:
|
| 76 |
+
MEL.connect_material_property(node('float2 t = Texture2DSample(NM, NMSampler, UV).xy * 2 - 1; return float3(t, sqrt(saturate(1 - dot(t, t))));', ['NM'], F3, -100), '', u.MaterialProperty.MP_NORMAL)
|
| 77 |
+
MEL.connect_material_property(node('return Texture2DSample(RT, RTSampler, UV).b * MetalAmt;', ['RT', 'MetalAmt'], F1, 250), '', u.MaterialProperty.MP_METALLIC)
|
| 78 |
+
MEL.connect_material_property(node('return lerp(1, Texture2DSample(RT, RTSampler, UV).r, AOAmt);', ['RT', 'AOAmt'], F1, 400), '', u.MaterialProperty.MP_AMBIENT_OCCLUSION)
|
| 79 |
+
MEL.connect_material_property(node(COV + 'return lerp(saturate(dot(Texture2DSample(RT, RTSampler, UV).rgb, RCh.rgb) * RMul), CovRough, m);', ['RT', 'RCh', 'RMul', 'CovRough', 'CovAmt', 'WP', 'NW'], F1, 100), '', u.MaterialProperty.MP_ROUGHNESS)
|
| 80 |
+
MEL.recompile_material(m); EAL.save_loaded_asset(m, False); log('%s rebuilt (cover layer, foliage=%s)' % (name, foliage))
|
| 81 |
+
for nm, fol in (('M_V10Mesh', False), ('M_V10Foliage', True)):
|
| 82 |
+
try: build(nm, fol)
|
| 83 |
+
except Exception: log('FAIL %s %s' % (nm, traceback.format_exc()))
|
| 84 |
+
log('V10_MASTERS4_DONE')
|