| ... | ... | @@ -29,7 +29,7 @@ SCRIPTS = Path(__file__).resolve().parent |
| 29 | 29 | sys.path.insert(0, str(SCRIPTS)) |
| 30 | 30 | |
| 31 | 31 | import diff_fuzz.assets as assets # noqa: E402 |
| 32 | | from diff_fuzz.assets import CONTAINER_ROOT, generate_assets, make_comp, make_loader, make_saver, step_spline # noqa: E402 |
| 32 | from diff_fuzz.assets import CONTAINER_ROOT, generate_assets, linear_spline, make_comp, make_loader, make_saver, step_spline # noqa: E402 |
| 33 | 33 | from diff_fuzz.runner import alpha_mae_pct, run_comp_both # noqa: E402 |
| 34 | 34 | from gen_compatibility import TOOL_METADATA # noqa: E402 |
| 35 | 35 | |
| ... | ... | @@ -43,6 +43,11 @@ SIZE = 256 |
| 43 | 43 | FRAME_TIMEOUT = 20 |
| 44 | 44 | GOLDEN = 0.6180339887498949 |
| 45 | 45 | |
| 46 | |
| 47 | class FuID(str): |
| 48 | pass |
| 49 | |
| 50 | |
| 46 | 51 | # Tools the generic wiring cannot drive yet, with the reason recorded in the ledger. |
| 47 | 52 | UNSUPPORTED_RIG = { |
| 48 | 53 | "Loader": "needs a footage clip; every probe already exercises it", |
| ... | ... | @@ -59,14 +64,18 @@ UNSUPPORTED_RIG = { |
| 59 | 64 | "PolylineStroke": "needs painted strokes", |
| 60 | 65 | "Multistroke": "needs painted strokes", |
| 61 | 66 | "PaintMask": "needs painted strokes", |
| 62 | | "TimeSpeed": "time remap of a still plate is an identity", |
| 63 | | "TimeStretcher": "time remap of a still plate is an identity", |
| 67 | "SurfaceFBXMesh": "needs a mesh file", |
| 64 | 68 | "GridWarp": "needs mesh-point data", |
| 65 | 69 | } |
| 66 | | UNSUPPORTED_DOMAINS = { |
| 67 | | "DataType3D": "3D scene rig not wired", |
| 68 | | "MtlGraph3D": "3D material rig not wired", |
| 69 | | "Particles": "particle rig not wired", |
| 70 | UNRIGGED_DOMAINS = ("DataType3D", "MtlGraph3D", "Particles") |
| 71 | RIGS = { |
| 72 | "scene": { |
| 73 | "Camera3D", "Cube3D", "Displace3D", "Duplicate3D", "ImagePlane3D", "LightAmbient", "LightDirectional", "LightPoint", |
| 74 | "LightSpot", "Merge3D", "Override3D", "Renderer3D", "ReplaceMaterial3D", "ReplaceNormals3D", "Shape3D", "Text3D", "Transform3D", |
| 75 | }, |
| 76 | "material": {"MtlBlinn", "MtlPhong", "MtlCookTorrance", "BumpMap", "Texture2DOperator", "TextureTransformOperator"}, |
| 77 | "particle": {"pEmitter", "pRender", "pMerge", "pDirectionalForce", "pDrag", "pTurbulence", "pPointForce", "pBounce", "pKill"}, |
| 78 | "time": {"TimeSpeed", "TimeStretcher"}, |
| 70 | 79 | } |
| 71 | 80 | |
| 72 | 81 | SLIDER_CONTROLS = { |
| ... | ... | @@ -74,23 +83,40 @@ SLIDER_CONTROLS = { |
| 74 | 83 | "ColorWheelControl", "ColorSuppressionControl", None, |
| 75 | 84 | } |
| 76 | 85 | CHOICE_CONTROLS = {"CheckboxControl", "MultiButtonControl", "MultiButtonIDControl", "ComboControl", "ComboIDControl"} |
| 77 | | # Inputs whose variation tests plumbing the engine intentionally lacks, or that resize the frame. |
| 86 | # Inputs whose variation tests plumbing the engine intentionally lacks, that resize the frame, or that need |
| 87 | # data the rigs lack (Renderer3D deep output, Displace3D camera, TimeSpeed/TimeStretcher optical flow: Fusion fails the frame). |
| 78 | 88 | DENY_IDS = { |
| 79 | 89 | "MotionBlur", "ShutterAngle", "CenterBias", "SampleSpread", "UseGPU", "HideInputs", "HiQOnly", |
| 80 | 90 | "Width", "Height", "PixelAspect", "Depth", "UseFrameFormatSettings", "AutoResolution", "ProcessMode", |
| 81 | 91 | "UseObject", "UseMaterial", "ObjectID", "MaterialID", "CorrectEdges", "ProxyScale", "MaskWidth", "MaskHeight", |
| 92 | "RendererType", "OutputType", "PointCamera", "InterpolateBetweenFrames", |
| 82 | 93 | } |
| 83 | | DENY_PREFIXES = ("Gamut.", "ProcessLayers", "Comments", "Layer", "Motion", "Reset", "Stereo") |
| 94 | # TimeSpeed fails the frame in Fusion once a reversed Speed reaches ~-24 frames of source time. |
| 95 | INPUT_RANGES = {("TimeSpeed", "Speed"): (-2.0, 3.0)} |
| 96 | DENY_PREFIXES = ("Gamut.", "ProcessLayers", "Comments", "Layer", "Motion", "Reset", "Stereo", "EnableWarp.") |
| 84 | 97 | DENY_SUFFIXES = ("_LayerSelect", "Nest", "Notify") |
| 85 | 98 | MASK_IDS = ("ApplyMaskInverted", "MultiplyByMask", "FitMask", "MaskChannel", "MaskLow", "MaskHigh", "MaskClipBlack", "MaskClipWhite") |
| 86 | 99 | IMAGE_INPUT_IDS = ("Input", "Background", "Foreground", "Image", "Source", "Image1", "Image2", "Image3", "BlurImage") |
| 100 | # Renderer3D pinned to OpenGL: the catalog only lists RendererSoftware.* inputs, whose lighting toggles are remapped in `rig_frame`. |
| 101 | RENDERER3D = { |
| 102 | "Width": SIZE, "Height": SIZE, "RendererType": FuID("RendererOpenGL"), |
| 103 | "RendererOpenGL.LightingEnabled": 1, "RendererOpenGL.ShadowsEnabled": 1, |
| 104 | } |
| 105 | EMITTER = {"RandomSeed": 42, "Style": FuID("ParticleStyleBlob"), "Number": 20, "Velocity": 0.05} |
| 106 | PRENDER = {"OutputMode": FuID("TwoD"), "Width": SIZE, "Height": SIZE} |
| 87 | 107 | TOOL_OVERRIDES: Dict[str, Dict[str, Any]] = { |
| 88 | 108 | "TextPlus": {"StyledText": "Fission", "Size": 0.12}, |
| 109 | "Text3D": {"StyledText": "FISSION", "Font": "Open Sans", "Size": 0.25}, |
| 110 | "Renderer3D": RENDERER3D, |
| 111 | "Camera3D": {"Transform3DOp.Translate.Z": 3.0}, |
| 112 | "LightPoint": {"Transform3DOp.Translate.X": 1.2, "Transform3DOp.Translate.Y": 2.0, "Transform3DOp.Translate.Z": 2.0}, |
| 113 | "LightSpot": {"Transform3DOp.Translate.Y": 2.0, "Transform3DOp.Translate.Z": 3.0, "Transform3DOp.Rotate.X": -35.0}, |
| 114 | "LightDirectional": {"Transform3DOp.Rotate.X": -40.0, "Transform3DOp.Rotate.Y": 25.0}, |
| 115 | "pEmitter": EMITTER, |
| 116 | "pRender": PRENDER, |
| 89 | 117 | } |
| 90 | | |
| 91 | | |
| 92 | | class FuID(str): |
| 93 | | pass |
| 118 | # Image-slot a texture plugs into on tools that otherwise render untextured. |
| 119 | TEXTURE_SLOT = {"Shape3D": "MaterialInput", "ImagePlane3D": "MaterialInput", "Cube3D": "FrontMaterialInput"} |
| 94 | 120 | |
| 95 | 121 | |
| 96 | 122 | def lua_key(name: str) -> str: |
| ... | ... | @@ -157,13 +183,13 @@ class Fuzzer: |
| 157 | 183 | self.out_id = self.spec["outputs"][0]["id"] if self.spec["outputs"] else "Output" |
| 158 | 184 | self.wired_images = [i for i in IMAGE_INPUT_IDS if self.inputs.get(i, {}).get("data_type") == "Image"] |
| 159 | 185 | self.shape_inputs = [i["id"] for i in self.spec["inputs"] if i.get("data_type") == "ShapeTree"] |
| 186 | self.rig = next((r for r, tools_ in RIGS.items() if tool in tools_), None) |
| 160 | 187 | |
| 161 | 188 | def skip_reason(self) -> Optional[str]: |
| 162 | 189 | if self.tool in UNSUPPORTED_RIG: |
| 163 | 190 | return UNSUPPORTED_RIG[self.tool] |
| 164 | | for dom, why in UNSUPPORTED_DOMAINS.items(): |
| 165 | | if self.out_type == dom or any(i.get("data_type") == dom for i in self.spec["inputs"]): |
| 166 | | return why |
| 191 | if self.rig is None and any(d in {self.out_type, *self.in_types} for d in UNRIGGED_DOMAINS): |
| 192 | return "no 3D/material/particle rig for this tool" |
| 167 | 193 | return None |
| 168 | 194 | |
| 169 | 195 | # ---- variation sampling ------------------------------------------------------------- |
| ... | ... | @@ -200,6 +226,7 @@ class Fuzzer: |
| 200 | 226 | return alt[int(u * len(alt)) % len(alt)] if alt else default |
| 201 | 227 | lo = max(i["min_scale"], i.get("min_allowed", -1e6)) |
| 202 | 228 | hi = min(i["max_scale"], i.get("max_allowed", 1e6)) |
| 229 | lo, hi = INPUT_RANGES.get((self.tool, i["id"]), (lo, hi)) |
| 203 | 230 | v = lo + u * (hi - lo) |
| 204 | 231 | return int(round(v)) if i.get("integer") else round(v, 5) |
| 205 | 232 | |
| ... | ... | @@ -246,6 +273,104 @@ class Fuzzer: |
| 246 | 273 | fixed[dim] = SIZE |
| 247 | 274 | return fixed |
| 248 | 275 | |
| 276 | def rig_shared(self) -> List[str]: |
| 277 | """Nodes every frame's rig reuses: a lit textured sphere scene, and the animated plate for the time rig.""" |
| 278 | a = ("PlateA", "Output") |
| 279 | sphere = {"Shape": FuID("SurfaceSphereInputs")} |
| 280 | t3 = lambda x=0.0, y=0.0, z=0.0: {"Transform3DOp.Translate.X": x, "Transform3DOp.Translate.Y": y, "Transform3DOp.Translate.Z": z} |
| 281 | if self.rig == "time": |
| 282 | return [ |
| 283 | linear_spline("TimeA", {0: 0.0, 48: 1.0}), |
| 284 | linear_spline("TimeB", {0: 1.0, 48: 0.0}), |
| 285 | op_block("TimeBG", "Background", { |
| 286 | "Width": SIZE, "Height": SIZE, "Type": FuID("Horizontal"), "TopLeftBlue": 0.2, "TopRightBlue": 0.2, |
| 287 | "TopLeftAlpha": 1, "TopRightAlpha": 1, |
| 288 | }, { |
| 289 | "TopLeftRed": ("TimeA", "Value"), "TopLeftGreen": ("TimeB", "Value"), |
| 290 | "TopRightRed": ("TimeB", "Value"), "TopRightGreen": ("TimeA", "Value"), |
| 291 | }), |
| 292 | ] |
| 293 | if self.rig not in ("scene", "material"): |
| 294 | return [] |
| 295 | return [ |
| 296 | op_block("Cam", "Camera3D", {"Transform3DOp.Translate.Z": 3.0}, {}), |
| 297 | op_block("Pt", "LightPoint", t3(1.5, 1.5, 3.0), {}), |
| 298 | op_block("Amb", "LightAmbient", {"Intensity": 0.25}, {}), |
| 299 | op_block("BaseDir", "LightDirectional", {"Intensity": 0.4, "Transform3DOp.Rotate.X": -30.0, "Transform3DOp.Rotate.Y": 20.0}, {}), |
| 300 | op_block("Sph", "Shape3D", sphere, {"MaterialInput": a}), |
| 301 | op_block("SphL", "Shape3D", {**sphere, "SurfaceSphereInputs.Radius": 0.5, **t3(-0.7)}, {"MaterialInput": a}), |
| 302 | op_block("BoxR", "Shape3D", {"Shape": FuID("SurfaceCubeInputs"), "SurfaceCubeInputs.Size": 0.8, **t3(0.8)}, {"MaterialInput": ("PlateB", "Output")}), |
| 303 | op_block("WSph", "Shape3D", {**sphere, "SurfaceSphereInputs.Radius": 0.5}, {}), |
| 304 | op_block("Wall", "Shape3D", {"Shape": FuID("SurfacePlaneInputs"), "SurfacePlaneInputs.Width": 6.0, "SurfacePlaneInputs.Height": 6.0, **t3(z=-0.8)}, {}), |
| 305 | op_block("Noise", "FastNoise", {"Width": SIZE, "Height": SIZE}, {}), |
| 306 | op_block("RedMtl", "MtlBlinn", {"Diffuse.Color.Red": 0.9, "Diffuse.Color.Green": 0.15, "Diffuse.Color.Blue": 0.1}, {}), |
| 307 | op_block("BaseTex", "Texture2DOperator", {}, {"Input": a}), |
| 308 | ] |
| 309 | |
| 310 | def rig_frame(self, f: int, name: str, inputs: Dict[str, Any], links: Dict[str, Tuple[str, str]]) -> Tuple[List[str], str]: |
| 311 | """Harness for one variation: tool `name` placed in its rig; returns (nodes, op feeding the Switch tree).""" |
| 312 | t, a = self.tool, ("PlateA", "Output") |
| 313 | if self.rig == "time": |
| 314 | links.update({i: ("TimeBG", "Output") for i in self.wired_images}) |
| 315 | return [op_block(name, self.kind, inputs, links)], name |
| 316 | if self.rig == "particle": |
| 317 | emitter = (f"E{f}", "Output") |
| 318 | nodes = [] if t == "pEmitter" else [op_block(emitter[0], "pEmitter", EMITTER, {})] |
| 319 | if t == "pMerge": |
| 320 | nodes.append(op_block(f"E2_{f}", "pEmitter", {**EMITTER, "RandomSeed": 7, "SphereRgn.Translate.X": 0.3}, {})) |
| 321 | links.update({"Particles1": emitter, "Particles2": (f"E2_{f}", "Output")}) |
| 322 | elif t != "pEmitter": |
| 323 | links["Input"] = emitter |
| 324 | nodes.append(op_block(name, self.kind, inputs, links)) |
| 325 | if t == "pRender": |
| 326 | return nodes, name |
| 327 | return nodes + [op_block(f"R{f}", "pRender", PRENDER, {"Input": (name, self.out_id)})], f"R{f}" |
| 328 | |
| 329 | tool_out = (name, self.out_id) |
| 330 | lit = ["Sph", "Pt", "Amb", "Cam"] |
| 331 | if self.rig == "material": |
| 332 | nodes, mtl = [], (name, "MaterialOutput") |
| 333 | if t in ("MtlBlinn", "MtlPhong", "MtlCookTorrance"): |
| 334 | links["Diffuse.Color.Material"] = a |
| 335 | elif t == "BumpMap": |
| 336 | links["Input"] = ("Noise", "Output") |
| 337 | nodes.append(op_block(f"Bm{f}", "MtlBlinn", {}, {"Diffuse.Color.Material": a, "Bumpmap.Material": mtl})) |
| 338 | mtl = (f"Bm{f}", "MaterialOutput") |
| 339 | elif t == "TextureTransformOperator": |
| 340 | links["MaterialInput"] = ("BaseTex", "MaterialOutput") |
| 341 | nodes += [op_block(name, self.kind, inputs, links), op_block(f"S{f}", "Shape3D", {"Shape": FuID("SurfaceSphereInputs")}, {"MaterialInput": mtl})] |
| 342 | scene = [(f"S{f}", "Output")] + [(n, "Output") for n in lit[1:]] |
| 343 | else: |
| 344 | scene = [(n, "Output") for n in lit] |
| 345 | if t in ("Shape3D", "Cube3D", "ImagePlane3D", "Text3D"): |
| 346 | if t in TEXTURE_SLOT: |
| 347 | links[TEXTURE_SLOT[t]] = a |
| 348 | scene[0] = tool_out |
| 349 | elif t in ("LightAmbient", "LightDirectional", "LightPoint", "LightSpot"): |
| 350 | scene = [(n, "Output") for n in ("WSph", "Wall", "Cam")] + [tool_out] |
| 351 | if t == "LightAmbient": |
| 352 | scene.append(("BaseDir", "Output")) |
| 353 | elif t == "Camera3D": |
| 354 | scene[3] = tool_out |
| 355 | elif t == "Merge3D": |
| 356 | links.update({"SceneInput1": ("SphL", "Output"), "SceneInput2": ("BoxR", "Output")}) |
| 357 | scene[0] = tool_out |
| 358 | elif t == "Renderer3D": |
| 359 | inputs = {k.replace("RendererSoftware.", "RendererOpenGL.") if k.endswith(("LightingEnabled", "ShadowsEnabled")) else k: v for k, v in inputs.items()} |
| 360 | links["SceneInput"] = (f"M{f}", "Output") |
| 361 | else: |
| 362 | links["SceneInput"] = ("Sph", "Output") |
| 363 | if t == "Displace3D": |
| 364 | links["Input"] = ("Noise", "Output") |
| 365 | elif t == "ReplaceMaterial3D": |
| 366 | links["MaterialInput"] = ("RedMtl", "MaterialOutput") |
| 367 | scene[0] = tool_out |
| 368 | nodes = [op_block(name, self.kind, inputs, links)] |
| 369 | nodes.append(op_block(f"M{f}", "Merge3D", {}, {f"SceneInput{k + 1}": src for k, src in enumerate(scene)})) |
| 370 | if t == "Renderer3D": |
| 371 | return nodes, name |
| 372 | return nodes + [op_block(f"Ren{f}", "Renderer3D", RENDERER3D, {"SceneInput": (f"M{f}", "Output")})], f"Ren{f}" |
| 373 | |
| 249 | 374 | def build(self, plates: Dict[str, str]) -> Tuple[str, List[Tuple[int, str]]]: |
| 250 | 375 | tools: List[str] = [ |
| 251 | 376 | make_loader("PlateA", plates["color"]), |
| ... | ... | @@ -261,6 +386,7 @@ class Fuzzer: |
| 261 | 386 | "BottomRightRed": 1, "BottomRightGreen": 1, "BottomRightBlue": 1, "BottomRightAlpha": 0.2, |
| 262 | 387 | }, {}), |
| 263 | 388 | ] |
| 389 | tools += self.rig_shared() |
| 264 | 390 | if self.shape_inputs or self.out_type == "ShapeTree" or self.kind == "sRender": |
| 265 | 391 | tools.append(op_block("ShapeA", "sRectangle", {}, {})) |
| 266 | 392 | tools.append(op_block("ShapeB", "sEllipse", {}, {})) |
| ... | ... | @@ -281,6 +407,12 @@ class Fuzzer: |
| 281 | 407 | links["EffectMask"] = ("MaskSrc", "Output") |
| 282 | 408 | inputs = {**fixed, **overrides} |
| 283 | 409 | name = f"T{f}" |
| 410 | if self.rig: |
| 411 | nodes, out = self.rig_frame(f, name, inputs, links) |
| 412 | tools += nodes |
| 413 | outs.append(out) |
| 414 | cases.append((f, label)) |
| 415 | continue |
| 284 | 416 | tools.append(op_block(name, self.kind, inputs, links)) |
| 285 | 417 | out = name |
| 286 | 418 | if self.out_type == "Mask": |
| ... | ... | @@ -299,6 +431,8 @@ class Fuzzer: |
| 299 | 431 | tools += tree |
| 300 | 432 | tools.append(make_saver(root, f"fn_{self.tool_slug()}")) |
| 301 | 433 | comp = make_comp("\n".join(tools + splines), len(outs) - 1, w=SIZE, h=SIZE) |
| 434 | if self.rig == "time": # Fusion fails any request outside GlobalRange, and retiming reaches far outside the render range |
| 435 | comp = comp.replace(f"GlobalRange = {{ 0, {len(outs) - 1} }}", "GlobalRange = { -100, 200 }") |
| 302 | 436 | return comp, cases |
| 303 | 437 | |
| 304 | 438 | def tool_slug(self) -> str: |