コード例 #1
0
    public ScaleStage(GlobalSettings global, PerStageSettings per_stage)    // from settings Constructor
    {
        evolution_settings = new Evolution_Settings()
        {
            populationPoolNumber        = per_stage.populationPoolNumber,
            maximumNumberOfBrushStrokes = per_stage.maximumNumberOfBrushStrokes,
            brushTexture         = global.brushTexture,
            mutationChance       = global.mutationChance,
            brushSizeLowerBound  = per_stage.brushSizeLowerBound,
            brushSizeHigherBound = per_stage.brushSizeHigherBound,
        };

        fitness_settings = new Fitness_Settings()
        {
            costume_mask     = per_stage.costume_mask,
            ColorWeight      = global.ColorWeight,
            LuminacityWeight = global.LuminacityWeight,
            fitnessPowFactor = global.fitnessPowFactor,
        };

        scale_settings = new Scale_Settings()
        {
            sigma = per_stage.sigma,
            gaussian_kernel_size      = per_stage.gaussian_kernel_size,
            sobel_step_size           = per_stage.sobel_step_size,
            position_domain_threshold = per_stage.position_domain_threshold,
            apply_mask = per_stage.apply_mask,
        };
    }
コード例 #2
0
 public Evolution_Settings(Evolution_Settings other)                          // Copy Constructor
 {
     populationPoolNumber        = other.populationPoolNumber;
     maximumNumberOfBrushStrokes = other.maximumNumberOfBrushStrokes;
     brushTexture         = other.brushTexture;
     mutationChance       = other.mutationChance;
     brushSizeLowerBound  = other.brushSizeLowerBound;
     brushSizeHigherBound = other.brushSizeHigherBound;
 }
コード例 #3
0
 public ScaleStage(ScaleStage other)                                    // Copy Constructor
 {
     evolution_settings = new Evolution_Settings(other.evolution_settings);
     fitness_settings   = new Fitness_Settings(other.fitness_settings);
     scale_settings     = new Scale_Settings(other.scale_settings);
 }
コード例 #4
0
    private FitnessData fitness_data;                                     // container holding all fitness info

    // ----------------------------------------------------------------------------------------------------------------------------------------------------------------
    // Constructor
    // ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    public ScaleStage()                                                    // Default Constructor
    {
        evolution_settings = new Evolution_Settings();
        fitness_settings   = new Fitness_Settings();
        scale_settings     = new Scale_Settings();
    }
コード例 #5
0
    public void Bind_Compute_Resources(Texture target_image, Compute_Resources compute_resources, Evolution_Settings evolution_settings)   // binds all the buffers and textures and the uniforms that dont change in runtime to the relevant compute shader
    {
        bind_population_pool_buffer(compute_resources.population_pool_buffer);
        bind_second_gen_buffer(compute_resources.second_gen_population_pool_buffer);
        bind_per_pixel_fitness_buffer(compute_resources.per_pixel_fitnes_buffer);
        bind_rows_sum_buffer(compute_resources.per_row_sum_buffer);
        bind_population_pool_fitness_buffer(compute_resources.population_pool_fitness_buffer);
        bind_population_accumlative_probablities_buffer(compute_resources.population_accumlative_prob_buffer);
        bind_second_gen_parent_ids_buffer(compute_resources.second_gen_parents_ids_buffer);
        bind_fittest_member_buffer(compute_resources.fittest_member_buffer);
        bind_position_domain_buffer(compute_resources.position_domain_buffer);
        bind_positon_domain_arguments_buffer(compute_resources.positon_domain_arguments_buffer);

        bind_original_texture(target_image);
        bind_forged_texture(compute_resources.compute_forged_in_render_texture);
        bind_orignal_gradient_texture(compute_resources.original_image_gradient);
        bind_sobel_out(compute_resources.sobel_out);
        bind_original_blured(compute_resources.original_image_blured);
        bind_gaussian_out(compute_resources.gaussian_out);
        bind_debug_texture(compute_resources.debug_texture);

        set_image_dimensions((uint)target_image.width, (uint)target_image.height);
        set_evolution_settings(evolution_settings.populationPoolNumber, evolution_settings.maximumNumberOfBrushStrokes);
    }
コード例 #6
0
    public RenderTexture gaussian_out;                                       // out put of the gaussian filter. Since gaussian is multipass, you need this for buffer. You can combine it with other textures, however for debug porpuses I leave it like this
    // ____________________________________________________________________________________________________
    // Constructor
    public void Consruct_Buffers(Texture Image_to_reproduce, RenderTexture stage_base, Evolution_Settings evolution_setting)
    {
        int  pixel_count_in_image  = Image_to_reproduce.width * Image_to_reproduce.height;
        uint total_number_of_genes = evolution_setting.populationPoolNumber * evolution_setting.maximumNumberOfBrushStrokes;                               // although population_pool is the array of populations, each population memberis implied through the max number of brushes. It is in parsing an array of genes.

        population_pool_buffer            = new ComputeBuffer((int)total_number_of_genes, sizeof(float) * 8 + sizeof(int) * 1);                            // for the stride size look ath the DNA.cs and defination of Genes.
        second_gen_population_pool_buffer = new ComputeBuffer((int)total_number_of_genes, sizeof(float) * 8 + sizeof(int) * 1);                            // exact same layout as the one above
        per_pixel_fitnes_buffer           = new ComputeBuffer((int)pixel_count_in_image, sizeof(float) * 2);                                               // this buffer has one entry per image pixel. So width*height
        per_row_sum_buffer                 = new ComputeBuffer((int)Image_to_reproduce.height, sizeof(float) * 2);                                         // This will have one entry per row of the image. So as many as the height value of the render target. Each of these entries will hold the sum of that row
        population_pool_fitness_buffer     = new ComputeBuffer((int)evolution_setting.populationPoolNumber, sizeof(float) * 2);
        population_accumlative_prob_buffer = new ComputeBuffer((int)evolution_setting.populationPoolNumber, sizeof(float));                                // You could combin this and the fitnes buffer together, I am keeping them seprated for the sake of debuging ease
        second_gen_parents_ids_buffer      = new ComputeBuffer((int)evolution_setting.populationPoolNumber, sizeof(int) * 2);                              // ids (int) paris. Needs to change to smoething else if you have more than 2 parent
        fittest_member_buffer              = new ComputeBuffer(1, sizeof(float) + sizeof(int));                                                            // This is a single value. Not sure how to bind it as random read write access without creating an entire buffer
        position_domain_buffer             = new ComputeBuffer((int)pixel_count_in_image, sizeof(float) * 2, ComputeBufferType.Append);                    // We dont know how large the search domain is a head of the time. It depends on the gaussian/ sobel parameters, so we use an append buffer
        position_domain_buffer.SetCounterValue(0);
        positon_domain_arguments_buffer = new ComputeBuffer(1, sizeof(int) * 4, ComputeBufferType.IndirectArguments);                                      // This is used to hold count number of the append buffer. The value of its length is coppied in to this in run time
        int[] ini_value = new int[4] {
            0, 0, 0, 0
        };
        positon_domain_arguments_buffer.SetData(ini_value);

        // -----------------------
        // Textures Initialization
        active_texture_target = new RenderTexture(Image_to_reproduce.width, Image_to_reproduce.height,
                                                  0, RenderTextureFormat.ARGB32)
        {
            wrapMode = TextureWrapMode.Clamp,
        };
        active_texture_target.Create();
        compute_forged_in_render_texture = new RenderTexture(active_texture_target)
        {
            wrapMode = TextureWrapMode.Clamp,
        };
        compute_forged_in_render_texture.Create();

        debug_texture = new RenderTexture(Image_to_reproduce.width, Image_to_reproduce.height,
                                          0, RenderTextureFormat.ARGB32)
        {
            wrapMode          = TextureWrapMode.Clamp,
            enableRandomWrite = true,
        };

        debug_texture.Create();

        clear_base = new RenderTexture(stage_base);
        clear_base.Create();
        Graphics.Blit(stage_base, clear_base);

        original_image_gradient = new RenderTexture(active_texture_target)
        {
            wrapMode = TextureWrapMode.Clamp,
        };
        original_image_gradient.Create();

        original_image_blured = new RenderTexture(active_texture_target)
        {
            wrapMode = TextureWrapMode.Clamp,
        };

        original_image_blured.Create();

        sobel_out = new RenderTexture(active_texture_target)
        {
            wrapMode          = TextureWrapMode.Clamp,
            enableRandomWrite = true,                   // This image is written to in compute shader as a random accesed resources
        };

        sobel_out.Create();

        gaussian_out = new RenderTexture(active_texture_target)
        {
            wrapMode          = TextureWrapMode.Clamp,
            enableRandomWrite = true,                   // This image is written to in compute shader as a random accesed resources
        };

        gaussian_out.Create();
    }