<commit_before>//
//  Reduce.cpp
//  Vertex2D
//
//  Created by <NAME> on 14/04/2016.
//  Copyright (c) 2016 <NAME>. All rights reserved.
//

#include "Reduce.h"

namespace Fluid
{

const char * ReduceVert = GLSL(
   in vec2 a_Position;
   in vec2 a_TexCoords;
   out vec2 v_texCoord;

   uniform mat4 u_Projection;
   uniform sampler2D u_texture;

   const vec2 off = vec2(0.5);

   void main()
   {
       gl_Position = u_Projection * vec4(a_Position, 0.0, 1.0);

       vec2 h = textureSize(u_texture, 0);
       vec2 k = ceil(h/vec2(2.0));

       v_texCoord = (vec2(2.0) * (a_TexCoords * k - off) + off) / h;
   }
);

const char * ReduceFrag = GLSL(
   in vec2 v_texCoord;
   out vec4 colour_out;
   
   uniform sampler2D u_texture;
   
   const vec4 q = vec4(1.0);
   
   void main()
   {
       vec4 p;
       p.x = texture(u_texture, v_texCoord).x;
       p.y = textureOffset(u_texture, v_texCoord, ivec2(0,1)).x;
       p.z = textureOffset(u_texture, v_texCoord, ivec2(1,0)).x;
       p.w = textureOffset(u_texture, v_texCoord, ivec2(1,1)).x;
       
       colour_out = vec4(dot(p,q), 0.0, 0.0, 0.0);
   }
);

const char * MultiplyFrag = GLSL(
     in vec2 v_texCoord;
     out vec4 colour_out;

     uniform sampler2D u_texture;
     uniform sampler2D u_other;

     void main()
     {
         float x = texture(u_texture, v_texCoord).x;
         float y = texture(u_other, v_texCoord).x;
         
         colour_out = vec4(x*y, 0.0, 0.0, 0.0);
     }
);

Reduce::Reduce(glm::vec2 size)
    : reduce(ReduceVert, ReduceFrag)
    , multiply(Renderer::Shader::TexturePositionVert, MultiplyFrag)
{
    while(size.x > 1.0f && size.y > 1.0f)
    {
        s.emplace_back(size, 1);
        size = glm::ceil(size/glm::vec2(2.0f));
    }

    reduce.Use().Set("u_texture", 0).Unuse();
    multiply.Use().Set("u_texture", 0).Set("u_other", 1).Unuse();
}

}<commit_msg>improved reduce operator<commit_after>//
//  Reduce.cpp
//  Vertex2D
//
//  Created by <NAME> on 14/04/2016.
//  Copyright (c) 2016 <NAME>. All rights reserved.
//

#include "Reduce.h"

namespace Fluid
{

const char * ReduceFrag = GLSL(
   out vec4 colour_out;
   
   uniform sampler2D u_texture;
   
   void main()
   {
       ivec2 pos = 2 * ivec2(gl_FragCoord.xy - 0.5);

       float x = 0.0;
       x += texelFetch(u_texture, pos + ivec2(0,0), 0).x;
       x += texelFetch(u_texture, pos + ivec2(1,0), 0).x;
       x += texelFetch(u_texture, pos + ivec2(0,1), 0).x;
       x += texelFetch(u_texture, pos + ivec2(1,1), 0).x;

       colour_out = vec4(x, 0.0, 0.0, 0.0);
   }
);

const char * MultiplyFrag = GLSL(
     in vec2 v_texCoord;
     out vec4 colour_out;

     uniform sampler2D u_texture;
     uniform sampler2D u_other;

     void main()
     {
         float x = texture(u_texture, v_texCoord).x;
         float y = texture(u_other, v_texCoord).x;
         
         colour_out = vec4(x*y, 0.0, 0.0, 0.0);
     }
);

Reduce::Reduce(glm::vec2 size)
    : reduce(Renderer::Shader::PositionVert, ReduceFrag)
    , multiply(Renderer::Shader::TexturePositionVert, MultiplyFrag)
{
    while(size.x > 1.0f && size.y > 1.0f)
    {
        s.emplace_back(size, 1);
        size = glm::ceil(size/glm::vec2(2.0f));
    }

    reduce.Use().Set("u_texture", 0).Unuse();
    multiply.Use().Set("u_texture", 0).Set("u_other", 1).Unuse();
}

}
{'fraction_non_alphanumeric': 0.155052790346908, 'fraction_numerical': 0.04555052790346908, 'mean_word_length': 2.479538300104932, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4877760', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1345, 'n_words': 270}