diff --git a/compare.glsl b/compare.glsl index 9f31b4f..0eb5fec 100644 --- a/compare.glsl +++ b/compare.glsl @@ -1,11 +1,10 @@ // Compute the pixelwise diff between two textures, one row at a time. // Assumes both images are not transparent. -// Warning: Only works on rows <= ((2**8)**4)/255 = 16843009 +// Warning: Only works on rows <= 65793 +// Formula for max pixels per row: (256^3)/255 -// try isampler2D, ivec4 etc.? Probably not uniform vec2 size; uniform bool horizontal; -// uniform vec2 offs; uniform sampler2D base; uniform sampler2D curr; @@ -34,38 +33,10 @@ void main(void) // encode to rgba channels in current pixel vec4 col = vec4(0.0, 0.0, 0.0, 1.0); -// total = total/255.0; + col.r = floor(mod(total*255.0, 256.0))/255.0; col.g = floor(mod(total*255.0/256.0, 256.0))/255.0; col.b = floor(mod(total*255.0/65536.0, 256.0))/255.0; -// color.g = 0.0; -// color.b = 0.0; -// color.g = mod(total, 256.0/255.0); -// color.r = float(mod(total, 256))/255.0; -// total = total/256; -// color.r = 1.0/255.0; -// color.r = mod(total, 256.0/255.0); -// total = (total - color.r) / (256.0/255.0); -// color.g = mod(total, 256.0/255.0); total = (total - color.g) / (256.0/255.0); -// color.b = mod(total, 256.0/255.0); -// color.a = 1.0; - -// color.r = 0; gl_FragColor = col; -// color.a = mod(total, 256.0/255.0); - -// gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0); } - -/* -void main(void) -{ - vec2 pos = gl_FragCoord.xy/size; - vec4 color = texture2D(curr, pos); - pos.y = 1.0 - pos.y; - vec4 basecolor = texture2D(base, pos); - color.rgb = abs(color.rgb - basecolor.rgb); - gl_FragColor = color; -} -*/ diff --git a/src/Fitness.cpp b/src/Fitness.cpp index 5142726..36dab02 100644 --- a/src/Fitness.cpp +++ b/src/Fitness.cpp @@ -2,28 +2,20 @@ #include -#include -Fitness::Fitness(sf::Texture target, float scale) : + +Fitness::Fitness(sf::Texture target) : dummy(sf::TriangleFan, 4) { this->target = target; - sf::Vector2u targetSize = this->target.getSize(); - this->tex.create(targetSize.x, targetSize.y); -// this->view.reset(sf::FloatRect(0, 0, targetSize.x, targetSize.y)); -// this->view.setViewport(sf::FloatRect(0, 0, 1, 1)); - this->horizontal = targetSize.x >= targetSize.y; -// this->horizontal = true; - std::cout << "Horizontal mode: " << horizontal << " " << targetSize.x << "." << targetSize.y << std::endl; if (this->horizontal) { targetSize.x = 1; } else { targetSize.y = 1; -// this->comp.create(targetSize.x*scale, 2); } this->comp.create(targetSize.x, targetSize.y); @@ -51,59 +43,36 @@ bool Fitness::loadShader(std::string filename) } -unsigned long long Fitness::of(Chromosome chr) +unsigned long long Fitness::of(const Chromosome& chr) { - // first, render a reduced, shaderized version to RenderTextures + // first, render chr to a texture, so we can just compare two textures this->tex.clear(); this->tex.draw(chr); this->tex.display(); + // compare the two textures using the SUPER ADVANCED shader this->comp.clear(sf::Color::Blue); -// this->comp.setView(this->view); this->comp.draw(this->dummy, &this->compshdr); -// this->comp.draw(this->sprite, &this->compshdr); -// this->comp.draw(this->sprite); this->comp.display(); - // then, download the result as an image and add the pixels + // then, download the result as an image and extract the result sf::Image image = this->comp.getTexture().copyToImage(); sf::Vector2u size = image.getSize(); -// std::cout << "Image size: " << size.x << " " << size.y << std::endl; - unsigned long long fitness = 0; -// for (unsigned int x=0; xhorizontal) { for (unsigned int y=0; y