"""Per-material diffusion tuning and prompt text. Structure --------- Each entry in MATERIALS carries the numeric tuning for that material -- how much of the image diffusion may change (diffusion_strength), how hard it is pushed toward the prompt (guidance), how strongly depth constrains it (controlnet), and the step count. Those numbers are the tuned part and are shared between floors and walls: marble responds the same way to diffusion whichever plane it sits on. What differs by plane is the *wording*. SDXL follows prompts literally, so telling it to preserve "plank positions" and "floor contact shadows" while it looks at a wall makes it fight the geometry. Every material therefore has a "floor" and a "wall" prompt pair under one set of numbers. The floor text is the tuned original and should be treated as such. The wall text mirrors it clause for clause -- same preserve-the-product framing, same realism vocabulary -- with floor nouns swapped for wall nouns and the floor-specific negatives (contact shadows, plank layouts, mirror floor) replaced by wall-specific ones. """ from __future__ import annotations from config.refine import REFINE_GENERIC_PROMPT MASK_THRESHOLD = 128 # Diffusion is kept away from the mask boundary; see masks.prepare_safe_diffusion_mask. DIFFUSION_EDGE_GUARD = 8 # Lighting transfer # # These were originally a *correction* band: gentle nudges to a composite that # already carried the room's light. Ours does not -- `enable_shading_transfer` # is off in visualizer.gpu.toml, so the WebGL composite is a flat tile paste and # this stage is the only thing that can light it. Measured on the bathroom # reference at the old settings: the room needs a median ratio of 0.75 and a # p1 of 0.46, 44% of pixels sat pinned against the 0.74 rail, and only 35% of # the lighting gap was closed -- shadows simply never arrived. # # The rails are deliberately asymmetric now. Darkening is the safe direction: # multiplying a bright tile down just makes it dark. Brightening is the # dangerous one -- pushing a dark tile up against a bright floor blows out to a # white smear -- so the upper rail stays tight while the lower one opens up. # # Widening the lower rail to 0.30 and raising strength to 0.90 cuts mean # low-frequency luminance error from 0.135 to 0.028 (4.8x) and lands the floor # band on 0.688 against the original's 0.684. LIGHTING_BLUR_SIGMA = 35 LIGHTING_TRANSFER_STRENGTH = 0.90 MIN_LIGHT_RATIO = 0.30 MAX_LIGHT_RATIO = 1.25 # Shadow transfer # # Local contrast rather than overall level: the residual left after dividing by # a 22px blur, darkening only. Opened up alongside the lighting rails above, # for the same reason -- there is no shadow in the composite to preserve, only # shadow to add. SHADOW_BLUR_SIGMA = 22 SHADOW_TRANSFER_STRENGTH = 0.75 MIN_SHADOW_RATIO = 0.45 # Shadow restoration after diffusion, gentler than the pre-pass above. POST_SHADOW_BLUR_SIGMA = 16 POST_SHADOW_TRANSFER_STRENGTH = 0.25 # Post-diffusion detail recovery, per material family. DETAIL_RECOVERY = { "wood": {"fine": 0.20, "pattern": 0.42}, "marble": {"fine": 0.14, "pattern": 0.32}, "default": {"fine": 0.15, "pattern": 0.25}, } CAMERA_NOISE_SIGMA = 0.20 SURFACE_KINDS = ("floor", "wall") BASE_PROMPTS = { "floor": """ real camera photograph of an existing interior, the flooring shown in the input is already completely finished and is the exact final flooring product, preserve the exact existing flooring, preserve exact floor pattern, preserve exact material design, preserve exact veins, preserve exact plank positions, preserve exact grain, preserve exact tile positions, preserve exact grout positions, preserve exact floor perspective, preserve exact scale, preserve exact orientation, preserve exact colors, do not redesign the floor, do not replace the floor, do not generate another flooring product, only reproduce realistic photographic material response, natural inherited room illumination, subtle realistic exposure variation, subtle natural surface roughness, soft realistic reflections, soft indirect illumination, subtle ambient occlusion, natural floor contact shadows, soft photographic highlight response, real optical camera photograph """, "wall": """ real camera photograph of an existing interior, the wall surface shown in the input is already completely finished and is the exact final wall covering product, preserve the exact existing wall surface, preserve exact wall pattern, preserve exact material design, preserve exact veins, preserve exact panel positions, preserve exact grain, preserve exact tile positions, preserve exact grout positions, preserve exact wall perspective, preserve exact scale, preserve exact orientation, preserve exact colors, do not redesign the wall, do not replace the wall covering, do not generate another wall product, only reproduce realistic photographic material response, natural inherited room illumination, subtle realistic exposure variation, subtle natural surface roughness, soft realistic reflections, soft indirect illumination, subtle ambient occlusion, soft contact shading where the wall meets floor and ceiling, soft photographic highlight response, real optical camera photograph """, } BASE_NEGATIVES = { "floor": """ new flooring, different flooring, replacement floor, redesigned floor, changed floor pattern, new planks, new boards, new tiles, new marble veins, new wood grain, new seams, new grout, parquet, herringbone, checkerboard, square wood tiles, decorative plank layout, basket weave, mosaic wood, generated floor, procedural texture, artificial pattern, synthetic floor, cgi, 3d render, plastic surface, mask seam, edge halo, black border, white border, dark outline, bright outline, floor bleeding into wall, floor bleeding into furniture, floor bleeding into doorway, changed wall, changed furniture, changed television, changed cabinet, changed speaker, changed chair """, "wall": """ new wall covering, different wall covering, replacement wall, redesigned wall, changed wall pattern, new panels, new boards, new tiles, new marble veins, new wood grain, new seams, new grout, wallpaper pattern, decorative mural, painted feature wall, brick pattern, stone cladding pattern, mosaic feature panel, generated wall, procedural texture, artificial pattern, synthetic wall, cgi, 3d render, plastic surface, mask seam, edge halo, black border, white border, dark outline, bright outline, wall bleeding into ceiling, wall bleeding into floor, wall bleeding into furniture, wall bleeding into window, wall bleeding into doorway, changed ceiling, changed floor, changed furniture, changed television, changed cabinet, changed artwork, changed window frame """, } MATERIALS: dict[str, dict] = { "marble": { # Was 0.46/28 -- 13 real steps, six times every other material and the # reason marble both cost the most and looked the worst. At that # strength SDXL stopped photographing the tile and started redesigning # it: continuous invented veining, checkerboard grid dissolved. The # room's light now arrives from the photometric stage rather than from # diffusion, so this only has to make the material read as photographed. "diffusion_strength": 0.20, "guidance": 3.0, "controlnet": 0.25, "steps": 22, "microdetail": 0.12, "local_contrast": 0.045, "floor": { "prompt": """ existing installed natural marble flooring, preserve the recognizable marble design, preserve the major existing marble veins, preserve the flooring perspective, preserve flooring placement and geometry, preserve overall marble colors, preserve clearly visible existing marble veining, preserve medium-scale mineral pattern definition, natural flowing veins with soft organic transitions, veins should remain clearly defined without becoming harsh, preserve subtle tonal boundaries within the marble, do not blur or wash out the marble pattern, convert the existing projected flooring into a physically realistic photographed marble surface, real polished stone surface, natural microscopic stone texture, subtle surface roughness variation, realistic polished marble reflections, soft broken reflections from the room, natural reflection falloff with viewing angle, subtle local exposure variations, realistic indirect illumination, realistic material response, soft contact shading, natural ambient occlusion, subtle imperfections in polish, fine photographic material detail, real marble photographed with a real camera """, "negative": """ different marble product, completely different marble pattern, major new veins, dramatic new veins, different flooring geometry, different perspective, different tile layout, changed room, changed furniture, plastic marble, flat texture, uniform lighting, uniform surface, cgi, 3d render, synthetic texture, overly glossy floor, mirror floor, fake reflections """, }, "wall": { "prompt": """ existing installed natural marble wall cladding, preserve the recognizable marble design, preserve the major existing marble veins, preserve the wall perspective, preserve slab placement and geometry, preserve overall marble colors, preserve clearly visible existing marble veining, preserve medium-scale mineral pattern definition, natural flowing veins with soft organic transitions, veins should remain clearly defined without becoming harsh, preserve subtle tonal boundaries within the marble, do not blur or wash out the marble pattern, convert the existing projected wall covering into a physically realistic photographed marble surface, real polished stone surface, natural microscopic stone texture, subtle surface roughness variation, realistic polished marble reflections, soft grazing reflections along the wall, natural reflection falloff with viewing angle, subtle local exposure variations, realistic indirect illumination, realistic material response, soft contact shading at wall edges, natural ambient occlusion in corners, subtle imperfections in polish, fine photographic material detail, real marble wall photographed with a real camera """, "negative": """ different marble product, completely different marble pattern, major new veins, dramatic new veins, different wall geometry, different perspective, different slab layout, changed room, changed furniture, plastic marble, flat texture, uniform lighting, uniform surface, cgi, 3d render, synthetic texture, overly glossy wall, mirror wall, fake reflections """, }, }, "wood": { # Same correction as marble, milder: 0.36/24 was 9 real steps and let # grain and plank edges drift off the tile that was actually applied. "diffusion_strength": 0.18, "guidance": 3.0, "controlnet": 0.15, "steps": 22, "microdetail": 0.12, "local_contrast": 0.015, "floor": { "prompt": """ existing real wooden floor, existing flooring product is already correct, preserve every exact existing plank, preserve exact plank positions, preserve plank widths, preserve plank lengths, preserve plank direction, preserve clearly visible existing wood grain, preserve medium-scale wood grain patterns, preserve grain lines and tonal variation, preserve knots and natural wood character when present, wood grain must remain visually defined, do not smooth away the wood grain, do not blur grain boundaries, keep the wooden texture, realistic natural timber microtexture, natural satin material response, subtle room reflections, real wooden flooring photographed indoors """, "negative": """ new wood floor, different wood, new planks, different planks, new wood grain, changed wood grain, parquet, herringbone, checkerboard, square wood tiles, decorative plank layout, warped boards, fake grain, plastic wood, blurred wood grain, washed out grain, smoothed wood texture, featureless wood, soft blurry grain, lost wood grain, """, }, "wall": { "prompt": """ existing real wood wall panelling, existing wall product is already correct, preserve every exact existing board, preserve exact board positions, preserve board widths, preserve board lengths, preserve board direction, preserve clearly visible existing wood grain, preserve medium-scale wood grain patterns, preserve grain lines and tonal variation, preserve knots and natural wood character when present, wood grain must remain visually defined, do not smooth away the wood grain, do not blur grain boundaries, keep the wooden texture, realistic natural timber microtexture, natural satin material response, subtle grazing light along the panelling, real wood wall panelling photographed indoors """, "negative": """ new wood panelling, different wood, new boards, different boards, new wood grain, changed wood grain, slatted acoustic panel, shiplap pattern, chevron panelling, decorative board layout, warped boards, fake grain, plastic wood, blurred wood grain, washed out grain, smoothed wood texture, featureless wood, soft blurry grain, lost wood grain, """, }, }, "porcelain": { "diffusion_strength": 0.09, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.025, "local_contrast": 0.010, "floor": { "prompt": """ existing real porcelain flooring, preserve exact tile product, preserve exact tile pattern, preserve exact tile positions, preserve exact grout, preserve exact tile dimensions, preserve exact colors, very subtle ceramic texture, restrained realistic reflection, real porcelain photographed indoors """, "negative": """ new tiles, different tiles, changed tiles, new grout, changed grout, new tile pattern, checkerboard, different flooring, plastic porcelain, mirror floor """, }, "wall": { "prompt": """ existing real porcelain wall tiling, preserve exact tile product, preserve exact tile pattern, preserve exact tile positions, preserve exact grout, preserve exact tile dimensions, preserve exact colors, very subtle ceramic texture, restrained realistic reflection, real porcelain wall tiling photographed indoors """, "negative": """ new tiles, different tiles, changed tiles, new grout, changed grout, new tile pattern, subway tile pattern, different wall covering, plastic porcelain, mirror wall """, }, }, "ceramic": { "diffusion_strength": 0.09, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.03, "local_contrast": 0.012, "floor": { "prompt": """ existing real ceramic flooring, preserve exact tile layout, preserve exact tile design, preserve exact grout positions, preserve exact colors, subtle ceramic microtexture, natural indoor material response """, "negative": """ new tiles, different tiles, new grout, changed grout, new floor pattern, plastic ceramic, mirror surface """, }, "wall": { "prompt": """ existing real ceramic wall tiling, preserve exact tile layout, preserve exact tile design, preserve exact grout positions, preserve exact colors, subtle ceramic microtexture, natural indoor material response """, "negative": """ new tiles, different tiles, new grout, changed grout, new wall pattern, subway tile pattern, plastic ceramic, mirror surface """, }, }, "stone": { "diffusion_strength": 0.10, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.04, "local_contrast": 0.015, "floor": { "prompt": """ existing real natural stone flooring, preserve exact stone pattern, preserve exact mineral structure, preserve exact existing texture, subtle natural pores, natural stone response, real stone photographed indoors """, "negative": """ new stone pattern, new cracks, new veins, different stone, changed texture layout, artificial stone, plastic stone """, }, "wall": { "prompt": """ existing real natural stone wall cladding, preserve exact stone pattern, preserve exact mineral structure, preserve exact existing texture, subtle natural pores, natural stone response, real stone wall photographed indoors """, "negative": """ new stone pattern, new cracks, new veins, different stone, changed texture layout, dry stone wall, stacked stone pattern, artificial stone, plastic stone """, }, }, "laminate": { "diffusion_strength": 0.09, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.03, "local_contrast": 0.012, "floor": { "prompt": """ existing laminate flooring, preserve exact existing flooring product, preserve exact plank positions, preserve exact printed pattern, preserve exact direction, subtle embossed surface detail, natural satin indoor response """, "negative": """ new laminate, new boards, changed boards, new floor pattern, parquet, herringbone, checkerboard, square tiles, plastic appearance """, }, "wall": { "prompt": """ existing laminate wall panelling, preserve exact existing panel product, preserve exact panel positions, preserve exact printed pattern, preserve exact direction, subtle embossed surface detail, natural satin indoor response """, "negative": """ new laminate, new panels, changed panels, new wall pattern, shiplap pattern, chevron panelling, square tiles, plastic appearance """, }, }, "vinyl": { "diffusion_strength": 0.09, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.025, "local_contrast": 0.010, "floor": { "prompt": """ existing vinyl flooring, preserve exact existing floor design, preserve exact floor geometry, preserve exact pattern, subtle realistic embossing, restrained material response, real vinyl photographed indoors """, "negative": """ new vinyl pattern, changed floor, different floor design, plastic toy surface, excessive gloss """, }, "wall": { "prompt": """ existing vinyl wall covering, preserve exact existing wall design, preserve exact wall geometry, preserve exact pattern, subtle realistic embossing, restrained material response, real vinyl wall covering photographed indoors """, "negative": """ new vinyl pattern, changed wall, different wall design, wallpaper seam, plastic toy surface, excessive gloss """, }, }, "carpet": { "diffusion_strength": 0.12, "guidance": 2.0, "controlnet": 0.14, "steps": 24, "microdetail": 0.08, "local_contrast": 0.025, "floor": { "prompt": """ existing real carpet, preserve exact carpet product, preserve exact carpet pattern, preserve exact carpet color, subtle natural fibers, subtle textile microstructure, real carpet photographed indoors """, "negative": """ new carpet, different carpet, changed pattern, changed color, plastic fibers, artificial carpet """, }, "wall": { "prompt": """ existing real textile wall covering, preserve exact textile product, preserve exact textile pattern, preserve exact textile color, subtle natural fibers, subtle woven microstructure, real fabric wall covering photographed indoors """, "negative": """ new textile, different textile, changed pattern, changed color, hanging curtain folds, draped fabric, plastic fibers, artificial fabric """, }, }, "concrete": { "diffusion_strength": 0.10, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.04, "local_contrast": 0.015, "floor": { "prompt": """ existing real concrete flooring, preserve exact existing concrete appearance, preserve exact tonal pattern, fine natural mineral texture, tiny natural pores, natural matte response, real concrete photographed indoors """, "negative": """ new concrete texture, new cracks, new stains, different concrete, changed floor, plastic concrete """, }, "wall": { "prompt": """ existing real concrete wall surface, preserve exact existing concrete appearance, preserve exact tonal pattern, fine natural mineral texture, tiny natural pores, natural matte response, real concrete wall photographed indoors """, "negative": """ new concrete texture, new cracks, new stains, different concrete, board formed pattern, tie hole pattern, changed wall, plastic concrete """, }, }, "generic": { "diffusion_strength": 0.09, "guidance": 1.8, "controlnet": 0.15, "steps": 24, "microdetail": 0.025, "local_contrast": 0.010, "floor": { "prompt": """ existing real flooring, the flooring product is already completely correct, preserve exact flooring design, preserve exact geometry, preserve exact pattern, preserve exact texture layout, subtle realistic material response, real floor photographed inside a real room """, "negative": """ new floor, different floor, changed floor, new floor pattern, changed texture, synthetic flooring, plastic material """, }, "wall": { "prompt": """ existing real wall surface, the wall product is already completely correct, preserve exact wall design, preserve exact geometry, preserve exact pattern, preserve exact texture layout, subtle realistic material response, real wall photographed inside a real room """, "negative": """ new wall, different wall, changed wall, new wall pattern, changed texture, synthetic wall covering, plastic material """, }, }, } def normalize_material_type(material_type: str | None) -> str: """Map an arbitrary catalogue value onto a known profile key. Unknown materials fall back to "generic" rather than raising: a tile the catalogue has not annotated yet should still refine, just conservatively. """ if not material_type: return "generic" key = str(material_type).strip().lower() return key if key in MATERIALS else "generic" def normalize_surface_kind(surface_kind: str | None) -> str: key = str(surface_kind or "floor").strip().lower() return key if key in SURFACE_KINDS else "floor" def detail_recovery_for(material_type: str | None) -> dict: return DETAIL_RECOVERY.get(normalize_material_type(material_type), DETAIL_RECOVERY["default"]) # --------------------------------------------------------------------------- # Generic prompts # # The material is already in the pixels: WebGL composites the real tile before # SDXL ever runs, and at 2-4 real denoise steps the prompt is not what decides # what the surface is made of. Its job is "this is a photograph, keep it one", # which is the same sentence for every material. # # Naming the material is worse than staying quiet about it, because the # material is a keyword guess against the tile's *name*: # # "Black Marble Herringbone" -> wood (plank seams, grain) # "Terracotta Ivory Marble Checker"-> marble (continuous polished slab) # "Old French Fan Mosaic" -> generic # # Only about a third of the catalogue lands on a profile that matches, and a # wrong one does real damage: it tells SDXL to convert the material rather # than photograph it. # # The negatives drop every decorative-layout term the old list carried # ("checkerboard", "herringbone", "parquet", "basket weave", "brick pattern"). # Those were meant to stop SDXL inventing a layout, but a negative prompt # cannot distinguish "do not invent a checkerboard" from "remove the # checkerboard that is already there" -- and a good part of the catalogue is # checkerboards. Deciding which patterns are legitimate is not this stage's # job; preserving whatever was applied is. # # What stays is structural and true regardless of material: do not redesign, # do not bleed past the mask, no CGI look, no halo at the boundary. # --------------------------------------------------------------------------- GENERIC_PROMPTS = { "floor": """ existing real flooring, already the exact final product, preserve exact flooring design, preserve exact pattern and tile layout, preserve exact geometry and perspective, preserve exact scale and orientation, preserve exact colors, preserve whatever surface figure is present, keep every existing seam, joint and boundary exactly where it is, only reproduce realistic photographic material response, physically plausible surface roughness, soft broken reflections from the room, natural reflection falloff with viewing angle, subtle local exposure variation, realistic indirect illumination, natural ambient occlusion and contact shading, fine photographic material detail, real floor photographed inside a real room with a real camera """, "wall": """ existing real wall surface, already the exact final product, preserve exact wall covering design, preserve exact pattern and tile layout, preserve exact geometry and perspective, preserve exact scale and orientation, preserve exact colors, preserve whatever surface figure is present, keep every existing seam, joint and boundary exactly where it is, only reproduce realistic photographic material response, physically plausible surface roughness, soft broken reflections from the room, natural reflection falloff with viewing angle, subtle local exposure variation, realistic indirect illumination, soft contact shading where the wall meets floor and ceiling, fine photographic material detail, real wall photographed inside a real room with a real camera """, } GENERIC_NEGATIVES = { "floor": """ new flooring, different flooring, replacement floor, redesigned floor, changed floor pattern, different tile layout, different perspective, different geometry, invented seams, invented joints, invented grout lines, blurred pattern, washed out pattern, smoothed away detail, generated floor, procedural texture, artificial pattern, synthetic floor, cgi, 3d render, plastic surface, flat texture, uniform lighting, mirror floor, fake reflections, mask seam, edge halo, black border, white border, dark outline, bright outline, floor bleeding into wall, floor bleeding into furniture, floor bleeding into doorway, changed wall, changed furniture, changed cabinet, changed fixture """, "wall": """ new wall covering, different wall covering, replacement wall, redesigned wall, changed wall pattern, different tile layout, different perspective, different geometry, invented seams, invented joints, invented grout lines, blurred pattern, washed out pattern, smoothed away detail, generated wall, procedural texture, artificial pattern, synthetic wall, cgi, 3d render, plastic surface, flat texture, uniform lighting, fake reflections, mask seam, edge halo, black border, white border, dark outline, bright outline, wall bleeding into ceiling, wall bleeding into floor, wall bleeding into furniture, wall bleeding into window, changed ceiling, changed floor, changed furniture, changed artwork, changed window frame """, } def build_prompts( material_type: str | None, surface_kind: str | None = "floor", material_description: str = "", ) -> tuple[str, str, dict]: """Return (prompt, negative_prompt, profile) for one material on one plane.""" key = normalize_material_type(material_type) kind = normalize_surface_kind(surface_kind) profile = MATERIALS[key] variant = profile[kind] description_block = ( f"\nExisting {kind} material:\n\n{material_description.strip()}\n" if material_description and material_description.strip() else "" ) if REFINE_GENERIC_PROMPT: # One material-neutral prompt per plane. The per-material text below is # kept, unused, so this is a one-flag revert. prompt = f""" {GENERIC_PROMPTS[kind]} {description_block}""" negative_prompt = GENERIC_NEGATIVES[kind] return prompt, negative_prompt, profile prompt = f""" {BASE_PROMPTS[kind]} {description_block} Material specific instructions: {variant["prompt"]} """ negative_prompt = f""" {BASE_NEGATIVES[kind]} Material specific restrictions: {variant["negative"]} """ return prompt, negative_prompt, profile