Repository: PixiEditor/PixiEditor
File: src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/NoiseNode.cs (C#)

Code before:
                                           else if (iFeature == 1) {
                                               dist = f2;
                                           }
                                           else if (iFeature == 2) {
                                               dist = f2 - f1;
                                           }
                                   
                                           noiseSum += dist * amplitude;
                                           amplitudeSum += amplitude;
                                           amplitude *= 0.5;
                                       }
                                   
                                       return half4(noiseSum / amplitudeSum);
                                   }
                                   """;
        
        Uniforms uniforms = new Uniforms();
        uniforms.Add("iSeed", new Uniform("iSeed", seed));
        uniforms.Add("iFrequency", new Uniform("iFrequency", frequency));
        uniforms.Add("iOctaves", new Uniform("iOctaves", octaves));
        uniforms.Add("iRandomness", new Uniform("iRandomness", randomness));
        uniforms.Add("iFeature", new Uniform("iFeature", feature));
        uniforms.Add("iAngleOffset", new Uniform("iAngleOffset", angleOffset));
        
        return Shader.Create(voronoiShaderCode, uniforms, out _);
    }

    public override Node CreateCopy() => new NoiseNode();
}

public enum NoiseType
{
    TurbulencePerlin,
    FractalPerlin,
    Voronoi
}

public enum VoronoiFeature
{
    F1 = 0, // Distance to the closest feature point
    F2 = 1, // Distance to the second-closest feature point
    F2MinusF1 = 2
}


Review comment (suggestion):
While this is probably fine, you can create this shader once in the constructor and update it with

`shader.WithUpdatedUniforms(uniforms);` each `OnPaint`

This automatically also disposes (frees memory) of old shader.

Code after:
                                           float2 samplePos = uv * freq;
                                           
                                           float dist = 0.0;
                                           float2 distances = getVoronoiDistances(samplePos, iSeed + float(octave) * FEATURE_SEED_SCALE);
                                           float f1 = distances.x;
                                           float f2 = distances.y;
                                           
                                           if (iFeature == 0) {
                                               dist = f1;
                                           }
                                           else if (iFeature == 1) {
                                               dist = f2;
                                           }
                                           else if (iFeature == 2) {
                                               dist = f2 - f1;
                                           }
                                   
                                           noiseSum += dist * amplitude;
                                           amplitudeSum += amplitude;
                                           amplitude *= 0.5;
                                       }
                                   
                                       return half4(noiseSum / amplitudeSum);
                                   }
                                   """;
        
        Uniforms uniforms = new Uniforms();
        uniforms.Add("iSeed", new Uniform("iSeed", seed));
        uniforms.Add("iFrequency", new Uniform("iFrequency", frequency));
        uniforms.Add("iOctaves", new Uniform("iOctaves", octaves));
        uniforms.Add("iRandomness", new Uniform("iRandomness", randomness));
        uniforms.Add("iFeature", new Uniform("iFeature", feature));
        uniforms.Add("iAngleOffset", new Uniform("iAngleOffset", angleOffset));

        if (voronoiShader == null)
        {
            voronoiShader = Shader.Create(voronoiShaderCode, uniforms, out _);
        }
        else
        {
            voronoiShader = voronoiShader.WithUpdatedUniforms(uniforms);
        }
        
        return voronoiShader;
    }

    public override Node CreateCopy() => new NoiseNode();
}

public enum NoiseType
{