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65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
"""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

MASK_THRESHOLD = 128

# Diffusion is kept away from the mask boundary; see masks.prepare_safe_diffusion_mask.
DIFFUSION_EDGE_GUARD = 8

# Lighting transfer
LIGHTING_BLUR_SIGMA = 35
LIGHTING_TRANSFER_STRENGTH = 0.50
MIN_LIGHT_RATIO = 0.74
MAX_LIGHT_RATIO = 1.14

# Shadow transfer
SHADOW_BLUR_SIGMA = 22
SHADOW_TRANSFER_STRENGTH = 0.58
MIN_SHADOW_RATIO = 0.58

# 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": {
        "diffusion_strength": 0.46,
        "guidance": 3.0,
        "controlnet": 0.25,
        "steps": 28,
        "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": {
        "diffusion_strength": 0.36,
        "guidance": 3.0,
        "controlnet": 0.15,
        "steps": 24,
        "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"])


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 ""
    )

    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