diff --git a/scripts/fuzz_node.py b/scripts/fuzz_node.py index a93842fd342ff7083fe1474805b598bf029564a0..077e9a2221267887bb80d6d085a2bf2d0eb395c3 100644 --- a/scripts/fuzz_node.py +++ b/scripts/fuzz_node.py @@ -29,7 +29,7 @@ SCRIPTS = Path(__file__).resolve().parent sys.path.insert(0, str(SCRIPTS)) import diff_fuzz.assets as assets # noqa: E402 -from diff_fuzz.assets import CONTAINER_ROOT, generate_assets, make_comp, make_loader, make_saver, step_spline # noqa: E402 +from diff_fuzz.assets import CONTAINER_ROOT, generate_assets, linear_spline, make_comp, make_loader, make_saver, step_spline # noqa: E402 from diff_fuzz.runner import alpha_mae_pct, run_comp_both # noqa: E402 from gen_compatibility import TOOL_METADATA # noqa: E402 @@ -43,6 +43,11 @@ SIZE = 256 FRAME_TIMEOUT = 20 GOLDEN = 0.6180339887498949 + +class FuID(str): + pass + + # Tools the generic wiring cannot drive yet, with the reason recorded in the ledger. UNSUPPORTED_RIG = { "Loader": "needs a footage clip; every probe already exercises it", @@ -59,14 +64,18 @@ UNSUPPORTED_RIG = { "PolylineStroke": "needs painted strokes", "Multistroke": "needs painted strokes", "PaintMask": "needs painted strokes", - "TimeSpeed": "time remap of a still plate is an identity", - "TimeStretcher": "time remap of a still plate is an identity", + "SurfaceFBXMesh": "needs a mesh file", "GridWarp": "needs mesh-point data", } -UNSUPPORTED_DOMAINS = { - "DataType3D": "3D scene rig not wired", - "MtlGraph3D": "3D material rig not wired", - "Particles": "particle rig not wired", +UNRIGGED_DOMAINS = ("DataType3D", "MtlGraph3D", "Particles") +RIGS = { + "scene": { + "Camera3D", "Cube3D", "Displace3D", "Duplicate3D", "ImagePlane3D", "LightAmbient", "LightDirectional", "LightPoint", + "LightSpot", "Merge3D", "Override3D", "Renderer3D", "ReplaceMaterial3D", "ReplaceNormals3D", "Shape3D", "Text3D", "Transform3D", + }, + "material": {"MtlBlinn", "MtlPhong", "MtlCookTorrance", "BumpMap", "Texture2DOperator", "TextureTransformOperator"}, + "particle": {"pEmitter", "pRender", "pMerge", "pDirectionalForce", "pDrag", "pTurbulence", "pPointForce", "pBounce", "pKill"}, + "time": {"TimeSpeed", "TimeStretcher"}, } SLIDER_CONTROLS = { @@ -74,23 +83,40 @@ SLIDER_CONTROLS = { "ColorWheelControl", "ColorSuppressionControl", None, } CHOICE_CONTROLS = {"CheckboxControl", "MultiButtonControl", "MultiButtonIDControl", "ComboControl", "ComboIDControl"} -# Inputs whose variation tests plumbing the engine intentionally lacks, or that resize the frame. +# Inputs whose variation tests plumbing the engine intentionally lacks, that resize the frame, or that need +# data the rigs lack (Renderer3D deep output, Displace3D camera, TimeSpeed/TimeStretcher optical flow: Fusion fails the frame). DENY_IDS = { "MotionBlur", "ShutterAngle", "CenterBias", "SampleSpread", "UseGPU", "HideInputs", "HiQOnly", "Width", "Height", "PixelAspect", "Depth", "UseFrameFormatSettings", "AutoResolution", "ProcessMode", "UseObject", "UseMaterial", "ObjectID", "MaterialID", "CorrectEdges", "ProxyScale", "MaskWidth", "MaskHeight", + "RendererType", "OutputType", "PointCamera", "InterpolateBetweenFrames", } -DENY_PREFIXES = ("Gamut.", "ProcessLayers", "Comments", "Layer", "Motion", "Reset", "Stereo") +# TimeSpeed fails the frame in Fusion once a reversed Speed reaches ~-24 frames of source time. +INPUT_RANGES = {("TimeSpeed", "Speed"): (-2.0, 3.0)} +DENY_PREFIXES = ("Gamut.", "ProcessLayers", "Comments", "Layer", "Motion", "Reset", "Stereo", "EnableWarp.") DENY_SUFFIXES = ("_LayerSelect", "Nest", "Notify") MASK_IDS = ("ApplyMaskInverted", "MultiplyByMask", "FitMask", "MaskChannel", "MaskLow", "MaskHigh", "MaskClipBlack", "MaskClipWhite") IMAGE_INPUT_IDS = ("Input", "Background", "Foreground", "Image", "Source", "Image1", "Image2", "Image3", "BlurImage") +# Renderer3D pinned to OpenGL: the catalog only lists RendererSoftware.* inputs, whose lighting toggles are remapped in `rig_frame`. +RENDERER3D = { + "Width": SIZE, "Height": SIZE, "RendererType": FuID("RendererOpenGL"), + "RendererOpenGL.LightingEnabled": 1, "RendererOpenGL.ShadowsEnabled": 1, +} +EMITTER = {"RandomSeed": 42, "Style": FuID("ParticleStyleBlob"), "Number": 20, "Velocity": 0.05} +PRENDER = {"OutputMode": FuID("TwoD"), "Width": SIZE, "Height": SIZE} TOOL_OVERRIDES: Dict[str, Dict[str, Any]] = { "TextPlus": {"StyledText": "Fission", "Size": 0.12}, + "Text3D": {"StyledText": "FISSION", "Font": "Open Sans", "Size": 0.25}, + "Renderer3D": RENDERER3D, + "Camera3D": {"Transform3DOp.Translate.Z": 3.0}, + "LightPoint": {"Transform3DOp.Translate.X": 1.2, "Transform3DOp.Translate.Y": 2.0, "Transform3DOp.Translate.Z": 2.0}, + "LightSpot": {"Transform3DOp.Translate.Y": 2.0, "Transform3DOp.Translate.Z": 3.0, "Transform3DOp.Rotate.X": -35.0}, + "LightDirectional": {"Transform3DOp.Rotate.X": -40.0, "Transform3DOp.Rotate.Y": 25.0}, + "pEmitter": EMITTER, + "pRender": PRENDER, } - - -class FuID(str): - pass +# Image-slot a texture plugs into on tools that otherwise render untextured. +TEXTURE_SLOT = {"Shape3D": "MaterialInput", "ImagePlane3D": "MaterialInput", "Cube3D": "FrontMaterialInput"} def lua_key(name: str) -> str: @@ -157,13 +183,13 @@ class Fuzzer: self.out_id = self.spec["outputs"][0]["id"] if self.spec["outputs"] else "Output" self.wired_images = [i for i in IMAGE_INPUT_IDS if self.inputs.get(i, {}).get("data_type") == "Image"] self.shape_inputs = [i["id"] for i in self.spec["inputs"] if i.get("data_type") == "ShapeTree"] + self.rig = next((r for r, tools_ in RIGS.items() if tool in tools_), None) def skip_reason(self) -> Optional[str]: if self.tool in UNSUPPORTED_RIG: return UNSUPPORTED_RIG[self.tool] - for dom, why in UNSUPPORTED_DOMAINS.items(): - if self.out_type == dom or any(i.get("data_type") == dom for i in self.spec["inputs"]): - return why + if self.rig is None and any(d in {self.out_type, *self.in_types} for d in UNRIGGED_DOMAINS): + return "no 3D/material/particle rig for this tool" return None # ---- variation sampling ------------------------------------------------------------- @@ -200,6 +226,7 @@ class Fuzzer: return alt[int(u * len(alt)) % len(alt)] if alt else default lo = max(i["min_scale"], i.get("min_allowed", -1e6)) hi = min(i["max_scale"], i.get("max_allowed", 1e6)) + lo, hi = INPUT_RANGES.get((self.tool, i["id"]), (lo, hi)) v = lo + u * (hi - lo) return int(round(v)) if i.get("integer") else round(v, 5) @@ -246,6 +273,104 @@ class Fuzzer: fixed[dim] = SIZE return fixed + def rig_shared(self) -> List[str]: + """Nodes every frame's rig reuses: a lit textured sphere scene, and the animated plate for the time rig.""" + a = ("PlateA", "Output") + sphere = {"Shape": FuID("SurfaceSphereInputs")} + t3 = lambda x=0.0, y=0.0, z=0.0: {"Transform3DOp.Translate.X": x, "Transform3DOp.Translate.Y": y, "Transform3DOp.Translate.Z": z} + if self.rig == "time": + return [ + linear_spline("TimeA", {0: 0.0, 48: 1.0}), + linear_spline("TimeB", {0: 1.0, 48: 0.0}), + op_block("TimeBG", "Background", { + "Width": SIZE, "Height": SIZE, "Type": FuID("Horizontal"), "TopLeftBlue": 0.2, "TopRightBlue": 0.2, + "TopLeftAlpha": 1, "TopRightAlpha": 1, + }, { + "TopLeftRed": ("TimeA", "Value"), "TopLeftGreen": ("TimeB", "Value"), + "TopRightRed": ("TimeB", "Value"), "TopRightGreen": ("TimeA", "Value"), + }), + ] + if self.rig not in ("scene", "material"): + return [] + return [ + op_block("Cam", "Camera3D", {"Transform3DOp.Translate.Z": 3.0}, {}), + op_block("Pt", "LightPoint", t3(1.5, 1.5, 3.0), {}), + op_block("Amb", "LightAmbient", {"Intensity": 0.25}, {}), + op_block("BaseDir", "LightDirectional", {"Intensity": 0.4, "Transform3DOp.Rotate.X": -30.0, "Transform3DOp.Rotate.Y": 20.0}, {}), + op_block("Sph", "Shape3D", sphere, {"MaterialInput": a}), + op_block("SphL", "Shape3D", {**sphere, "SurfaceSphereInputs.Radius": 0.5, **t3(-0.7)}, {"MaterialInput": a}), + op_block("BoxR", "Shape3D", {"Shape": FuID("SurfaceCubeInputs"), "SurfaceCubeInputs.Size": 0.8, **t3(0.8)}, {"MaterialInput": ("PlateB", "Output")}), + op_block("WSph", "Shape3D", {**sphere, "SurfaceSphereInputs.Radius": 0.5}, {}), + op_block("Wall", "Shape3D", {"Shape": FuID("SurfacePlaneInputs"), "SurfacePlaneInputs.Width": 6.0, "SurfacePlaneInputs.Height": 6.0, **t3(z=-0.8)}, {}), + op_block("Noise", "FastNoise", {"Width": SIZE, "Height": SIZE}, {}), + op_block("RedMtl", "MtlBlinn", {"Diffuse.Color.Red": 0.9, "Diffuse.Color.Green": 0.15, "Diffuse.Color.Blue": 0.1}, {}), + op_block("BaseTex", "Texture2DOperator", {}, {"Input": a}), + ] + + def rig_frame(self, f: int, name: str, inputs: Dict[str, Any], links: Dict[str, Tuple[str, str]]) -> Tuple[List[str], str]: + """Harness for one variation: tool `name` placed in its rig; returns (nodes, op feeding the Switch tree).""" + t, a = self.tool, ("PlateA", "Output") + if self.rig == "time": + links.update({i: ("TimeBG", "Output") for i in self.wired_images}) + return [op_block(name, self.kind, inputs, links)], name + if self.rig == "particle": + emitter = (f"E{f}", "Output") + nodes = [] if t == "pEmitter" else [op_block(emitter[0], "pEmitter", EMITTER, {})] + if t == "pMerge": + nodes.append(op_block(f"E2_{f}", "pEmitter", {**EMITTER, "RandomSeed": 7, "SphereRgn.Translate.X": 0.3}, {})) + links.update({"Particles1": emitter, "Particles2": (f"E2_{f}", "Output")}) + elif t != "pEmitter": + links["Input"] = emitter + nodes.append(op_block(name, self.kind, inputs, links)) + if t == "pRender": + return nodes, name + return nodes + [op_block(f"R{f}", "pRender", PRENDER, {"Input": (name, self.out_id)})], f"R{f}" + + tool_out = (name, self.out_id) + lit = ["Sph", "Pt", "Amb", "Cam"] + if self.rig == "material": + nodes, mtl = [], (name, "MaterialOutput") + if t in ("MtlBlinn", "MtlPhong", "MtlCookTorrance"): + links["Diffuse.Color.Material"] = a + elif t == "BumpMap": + links["Input"] = ("Noise", "Output") + nodes.append(op_block(f"Bm{f}", "MtlBlinn", {}, {"Diffuse.Color.Material": a, "Bumpmap.Material": mtl})) + mtl = (f"Bm{f}", "MaterialOutput") + elif t == "TextureTransformOperator": + links["MaterialInput"] = ("BaseTex", "MaterialOutput") + nodes += [op_block(name, self.kind, inputs, links), op_block(f"S{f}", "Shape3D", {"Shape": FuID("SurfaceSphereInputs")}, {"MaterialInput": mtl})] + scene = [(f"S{f}", "Output")] + [(n, "Output") for n in lit[1:]] + else: + scene = [(n, "Output") for n in lit] + if t in ("Shape3D", "Cube3D", "ImagePlane3D", "Text3D"): + if t in TEXTURE_SLOT: + links[TEXTURE_SLOT[t]] = a + scene[0] = tool_out + elif t in ("LightAmbient", "LightDirectional", "LightPoint", "LightSpot"): + scene = [(n, "Output") for n in ("WSph", "Wall", "Cam")] + [tool_out] + if t == "LightAmbient": + scene.append(("BaseDir", "Output")) + elif t == "Camera3D": + scene[3] = tool_out + elif t == "Merge3D": + links.update({"SceneInput1": ("SphL", "Output"), "SceneInput2": ("BoxR", "Output")}) + scene[0] = tool_out + elif t == "Renderer3D": + inputs = {k.replace("RendererSoftware.", "RendererOpenGL.") if k.endswith(("LightingEnabled", "ShadowsEnabled")) else k: v for k, v in inputs.items()} + links["SceneInput"] = (f"M{f}", "Output") + else: + links["SceneInput"] = ("Sph", "Output") + if t == "Displace3D": + links["Input"] = ("Noise", "Output") + elif t == "ReplaceMaterial3D": + links["MaterialInput"] = ("RedMtl", "MaterialOutput") + scene[0] = tool_out + nodes = [op_block(name, self.kind, inputs, links)] + nodes.append(op_block(f"M{f}", "Merge3D", {}, {f"SceneInput{k + 1}": src for k, src in enumerate(scene)})) + if t == "Renderer3D": + return nodes, name + return nodes + [op_block(f"Ren{f}", "Renderer3D", RENDERER3D, {"SceneInput": (f"M{f}", "Output")})], f"Ren{f}" + def build(self, plates: Dict[str, str]) -> Tuple[str, List[Tuple[int, str]]]: tools: List[str] = [ make_loader("PlateA", plates["color"]), @@ -261,6 +386,7 @@ class Fuzzer: "BottomRightRed": 1, "BottomRightGreen": 1, "BottomRightBlue": 1, "BottomRightAlpha": 0.2, }, {}), ] + tools += self.rig_shared() if self.shape_inputs or self.out_type == "ShapeTree" or self.kind == "sRender": tools.append(op_block("ShapeA", "sRectangle", {}, {})) tools.append(op_block("ShapeB", "sEllipse", {}, {})) @@ -281,6 +407,12 @@ class Fuzzer: links["EffectMask"] = ("MaskSrc", "Output") inputs = {**fixed, **overrides} name = f"T{f}" + if self.rig: + nodes, out = self.rig_frame(f, name, inputs, links) + tools += nodes + outs.append(out) + cases.append((f, label)) + continue tools.append(op_block(name, self.kind, inputs, links)) out = name if self.out_type == "Mask": @@ -299,6 +431,8 @@ class Fuzzer: tools += tree tools.append(make_saver(root, f"fn_{self.tool_slug()}")) comp = make_comp("\n".join(tools + splines), len(outs) - 1, w=SIZE, h=SIZE) + if self.rig == "time": # Fusion fails any request outside GlobalRange, and retiming reaches far outside the render range + comp = comp.replace(f"GlobalRange = {{ 0, {len(outs) - 1} }}", "GlobalRange = { -100, 200 }") return comp, cases def tool_slug(self) -> str: