Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
05-16 20:20
관리 메뉴

nomad-programmer

[CG/Houdini] Seamless Noise 본문

CG/Houdini

[CG/Houdini] Seamless Noise

scii 2023. 1. 9. 16:30
// point vop - snippet node

float pi = 3.1415926535897932384;

float dx = end[0] - start[0];
float dy = end[1] - start[1];

float coord0, coord1, coord2, coord3;
vector4 coords4d;

if(type == "simplex" || type == "perlin"){
    float total = 0;
    float amplitude = max_amplitude;
    float max_value = 0;

    for(int i = 0; i <= turbulence; i++){
        if(seamless == true){
            coord0 = start[0] + cos((position[0] * tiling[0] + tiled_offset[0] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[0];
            coord1 = start[1] + cos((position[1] * tiling[1] + tiled_offset[1] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[1];
            coord2 = start[0] + sin((position[0] * tiling[0] + tiled_offset[0] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[2];
            coord3 = start[1] + sin((position[1] * tiling[1] + tiled_offset[1] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[3];
            coords4d = set(coord0, coord1, coord2, coord3);
        }
        else{
            coord0 = (position[0] + tiled_offset[0]) * frequency + offset[0];
            coord1 = (position[1] + tiled_offset[1]) * frequency + offset[1];
            coord2 = (position[0] + tiled_offset[0]) * frequency + offset[2];
            coord3 = (position[1] + tiled_offset[1]) * frequency + offset[3];
            coords4d = set(coord0, coord1, coord2, coord3);
        }

        if(type == "simplex"){
            total += xnoise(coords4d) * amplitude;
        }
        else if(type == "perlin"){
            total += noise(coords4d) * amplitude;
        }
        else{
            noise = 0;
            return;
        }

        max_value += amplitude;
        amplitude *= roughness;
        frequency *= 2;
    }

    noise = fit01(total / max_value, min_amplitude, max_amplitude);

    if(0 <= noise){
        noise = pow(noise, attenuation);
    }
    else{
        noise = -pow(abs(noise), attenuation);
    }
}
else if (type == "worley" || type == "voronoi"){
    float f1, f2, f3, f4;
    vector4 temp_position1, temp_position2;
    int temp_seed;

    if(seamless == true){
        coord0 = start[0] + cos((position[0] * tiling[0] + tiled_offset[0] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[0];
        coord1 = start[1] + cos((position[1] * tiling[1] + tiled_offset[1] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[1];
        coord2 = start[0] + sin((position[0] * tiling[0] + tiled_offset[0] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[2];
        coord3 = start[1] + sin((position[1] * tiling[1] + tiled_offset[1] % 1) * 2 * pi) * dx / (2 * pi) * frequency + offset[3];
        coords4d = set(coord0, coord1, coord2, coord3);
    }
    else{
        coord0 = (position[0] + tiled_offset[0]) * frequency + offset[0];
        coord1 = (position[1] + tiled_offset[1]) * frequency + offset[1];
        coord2 = (position[0] + tiled_offset[0]) * frequency + offset[2];
        coord3 = (position[1] + tiled_offset[1]) * frequency + offset[3];
        coords4d = set(coord0, coord1, coord2, coord3);
    }

    if(type == "worley"){
        wnoise(coords4d, temp_seed, f1, f2, f3, f4);
        noise = f2 - f1;
        if(0 == mode)
            noise = f1;
        else if(1 == mode)
            noise = f2;
        else if(2 == mode)
            noise = f2 - f1;
        else if(3 == mode)
            noise = 2 * f3 - f2 - f1;
        else
            noise = 0;
    }
    else if(type == "voronoi"){
        vnoise(coords4d, set(1, 1, 1, 1), temp_seed, f1, f2, temp_position1, temp_position2);
        if(0 == mode)
            noise = f1;
        else if(1 == mode)
            noise = f2;
        else if(2 == mode)
            noise = f2 - f1;
        else
            noise = 0;
    }
    else{
        noise = 0;
        return;
    }

    noise = fit01(noise, min_amplitude, max_amplitude);

    if(0 <= noise){
        noise = pow(noise, attenuation);
    }
    else{
        noise = -pow(abs(noise), attenuation);
    }
}
else{
    noise = 0;
}

if(clamp == true){
    noise = clamp(noise, min_clamp, max_clamp);
}

'CG > Houdini' 카테고리의 다른 글

[CG/Houdini] License 서버 관련  (0) 2020.11.05
[Houdini] Visual Studio Code 에서 VEX 사용하기  (0) 2020.06.21
Comments