Fix compare shader(s)
This commit is contained in:
parent
74051fe676
commit
1171c37f88
3 changed files with 47 additions and 9 deletions
14
compare.glsl
14
compare.glsl
|
|
@ -4,16 +4,16 @@
|
|||
|
||||
// try isampler2D, ivec4 etc.? Probably not
|
||||
uniform vec2 size;
|
||||
uniform vec2 offs;
|
||||
uniform sampler2D base;
|
||||
uniform sampler2D curr;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 pos = gl_FragCoord.xy/size;
|
||||
// vec4 color = texture(curr, pos); // fails for some reason!?
|
||||
// vec4 basecolor = texture(base, pos); // fails too...
|
||||
// color.xyz = abs(color.xyz - basecolor.xyz);
|
||||
// gl_FragColor = color;
|
||||
// gl_FragColor = basecolor;
|
||||
gl_FragColor = vec4(1.0);
|
||||
vec2 pos = (gl_FragCoord.xy-offs)/size;
|
||||
pos.y = 1.0 - pos.y;
|
||||
vec4 color = texture2D(curr, pos);
|
||||
vec4 basecolor = texture2D(base, pos);
|
||||
color.xyz = abs(color.xyz - basecolor.xyz);
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
|
|
|||
20
compare_med.glsl
Normal file
20
compare_med.glsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Compute the pixelwise diff between two textures.
|
||||
// Computes the diff for each color chanel separately (r, g, b).
|
||||
// Assumes both images are not transparent.
|
||||
|
||||
// try isampler2D, ivec4 etc.? Probably not
|
||||
uniform vec2 size;
|
||||
uniform vec2 offs;
|
||||
uniform sampler2D base;
|
||||
uniform sampler2D curr;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 pos = (gl_FragCoord.xy-offs)/size;
|
||||
pos.y = 1.0 - pos.y;
|
||||
vec4 color = texture2D(curr, pos);
|
||||
vec4 basecolor = texture2D(base, pos);
|
||||
color.xyz = color.xyz - basecolor.xyz;
|
||||
color.xyz = (vec3(1.0, 1.0, 1.0) + color.xyz)/2.0;
|
||||
gl_FragColor = color;
|
||||
}
|
||||
22
src/main.cpp
22
src/main.cpp
|
|
@ -14,6 +14,9 @@
|
|||
* - show fitness for individuals?
|
||||
* - show stats for generation?
|
||||
*
|
||||
* 1.5) mating screen
|
||||
* -
|
||||
*
|
||||
* 2) fitness screen
|
||||
* - show original image
|
||||
* - show currently evaluated image
|
||||
|
|
@ -67,7 +70,19 @@ int main() {
|
|||
|
||||
compshdr.setUniform("base", base);
|
||||
compshdr.setUniform("curr", comp);
|
||||
compshdr.setUniform("size", 240, 240);
|
||||
compshdr.setUniform("size", sf::Vector2f(240, 240));
|
||||
compshdr.setUniform("offs", sf::Vector2f(0, 0));
|
||||
|
||||
sf::Shader medcompshdr;
|
||||
medcompshdr.loadFromFile("compare_med.glsl", sf::Shader::Fragment);
|
||||
if (!medcompshdr.isAvailable()) {
|
||||
std::cout << "The medshader is not available\n";
|
||||
return 1;
|
||||
}
|
||||
medcompshdr.setUniform("base", comp);
|
||||
medcompshdr.setUniform("curr", base);
|
||||
medcompshdr.setUniform("size", sf::Vector2f(240, 240));
|
||||
medcompshdr.setUniform("offs", sf::Vector2f(240, 0));
|
||||
|
||||
// Set the resolution parameter (the resoltion is divided to make the fire smaller)
|
||||
// shader.setParameter("resolution", sf::Vector2f(winW / 2, winH / 2));
|
||||
|
|
@ -92,7 +107,7 @@ int main() {
|
|||
// sf::Vector2i mousePos = sf::Mouse::getPosition(window);
|
||||
// shader.setParameter("mouse", sf::Vector2f(mousePos.x, mousePos.y - winH));
|
||||
|
||||
// Draw the sprites, one with the shader on it
|
||||
// Draw the sprites
|
||||
window.clear();
|
||||
|
||||
window.draw(sprbase);
|
||||
|
|
@ -103,6 +118,9 @@ int main() {
|
|||
sprcomp.setPosition(0, 240);
|
||||
window.draw(sprcomp, &compshdr);
|
||||
|
||||
sprcomp.setPosition(240, 240);
|
||||
window.draw(sprcomp, &medcompshdr);
|
||||
|
||||
window.display();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue