File size: 1,809 Bytes
82ea528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import torch


def mix(latent_image, noise_image, mix_percent):
    return ((1 - mix_percent) * latent_image + mix_percent *
                          noise_image) / ((mix_percent**2 + (1-mix_percent)**2) ** 0.5)

            


class FluxNoiseMixerNode:
    @classmethod
    def INPUT_TYPES(s):
        return {"required": {
                "latent": ("LATENT", ),
                "noise": ("LATENT", ),
                "mix_percent": ("FLOAT", {"default": 0.5, "min": 0, "max": 1.0, "step": 0.01}),
                "random_noise": ("FLOAT", {"default": 0.0, "min": 0, "max": 100.0, "step": 0.01}),
                "mix_type": (['mix', 'add'],),
                "random_mix_type": (['mix', 'add'],),
                "take_diff": ("BOOLEAN", ),
            }}

    RETURN_TYPES = ("LATENT",)
    FUNCTION = "append"

    CATEGORY = "fluxtapoz"

    def append(self, latent, noise, mix_percent, random_noise, mix_type, random_mix_type, take_diff):
        latent_image = latent.copy()
        noise = noise['samples']
        latent = latent_image['samples']

        random_noise_latent = torch.randn_like(noise)
        if random_mix_type == 'mix':
            noise = mix(noise, random_noise_latent, random_noise)
            # noise = (noise * (1-random_noise) + random_noise_latent * (random_noise))
        elif random_mix_type == 'add':
            noise += random_noise_latent * random_noise

        if mix_type == 'mix':
            new_latent = mix(latent, noise, mix_percent)
            # new_latent = (latent * (1-mix_percent) + noise * (mix_percent))
        elif mix_type == 'add':
            new_latent = latent + noise * mix_percent

        if take_diff:
            new_latent = new_latent - latent * mix_percent
        latent_image['samples'] = new_latent
        return (latent_image, )