Added background to refinement shader

This commit is contained in:
Caesar2011
2016-09-12 19:13:19 +02:00
parent a1c76d1e7f
commit afb288cbf3
5 changed files with 31 additions and 18 deletions

BIN
img/backgrounds/sky.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

@@ -10,7 +10,7 @@
int main(int argc, char* args[]) { int main(int argc, char* args[]) {
GLFWwindow* window; GLFWwindow* window;
GLuint tex1, tex2; GLuint texFG, texBG;
int textw, texth; int textw, texth;
int textw2, texth2; int textw2, texth2;
@@ -92,20 +92,19 @@ int main(int argc, char* args[]) {
tex1 = LoadTexture("../img/tests/flieger.jpg",&textw,&texth); texBG = LoadTexture("../img/backgrounds/sky.jpg",&textw2,&texth2);
printf("Tex1: %d\n", tex1); texFG = LoadTexture("../img/tests/flieger.jpg",&textw,&texth);
printf("Tex1: %d\n", texFG);
glfwSetWindowSize(window, textw, texth); glfwSetWindowSize(window, textw, texth);
glViewport(0, 0, textw, texth); glViewport(0, 0, textw, texth);
glfwSetWindowSizeLimits(window, textw, texth, textw, texth); glfwSetWindowSizeLimits(window, textw, texth, textw, texth);
// The texture we'<re going to render to // The texture we're going to render to
GLuint renderedTexture; GLuint renderedTexture;
glGenTextures(1, &renderedTexture); glGenTextures(1, &renderedTexture);
// "Bind" the newly created texture : all future texture functions will modify this texture
glBindTexture(GL_TEXTURE_2D, renderedTexture); glBindTexture(GL_TEXTURE_2D, renderedTexture);
// Give an empty image to OpenGL ( the last "0" )
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, textw, texth, 0,GL_RGB, GL_UNSIGNED_BYTE, 0); glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, textw, texth, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
// Poor filtering. Needed !
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -129,9 +128,12 @@ int main(int argc, char* args[]) {
GLint textureLocTri = glGetUniformLocation(programRefineID, "trimap"); GLint textureLocTri = glGetUniformLocation(programRefineID, "trimap");
GLint textureLocFore = glGetUniformLocation(programRefineID, "foreground"); GLint textureLocFore = glGetUniformLocation(programRefineID, "foreground");
GLint textureLocBack = glGetUniformLocation(programRefineID, "background");
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex1); glBindTexture(GL_TEXTURE_2D, texFG);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texBG);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, renderedTexture); glBindTexture(GL_TEXTURE_2D, renderedTexture);
@@ -199,6 +201,7 @@ int main(int argc, char* args[]) {
glUseProgram(programRefineID); glUseProgram(programRefineID);
glUniform1i(textureLocTri, 2); glUniform1i(textureLocTri, 2);
glUniform1i(textureLocBack, 1);
glUniform1i(textureLocFore, 0); glUniform1i(textureLocFore, 0);

View File

@@ -2,16 +2,13 @@
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp 1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
<iostream> <iostream>
1473145022 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp 1473703631 source:d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\main.cpp
<GL/glew.h> <GL/glew.h>
<GLFW/glfw3.h> <GLFW/glfw3.h>
<SDL2/SDL.h> <SDL2/SDL.h>
<SDL2/SDL_image.h>
<stdio.h>
<iostream>
<fstream> <fstream>
<vector>
<stdexcept> <stdexcept>
"loaders.h"
1473015242 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h 1473015242 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
<stddef.h> <stddef.h>

View File

@@ -9,6 +9,7 @@ out vec3 color;
// Values that stay constant for the whole mesh. // Values that stay constant for the whole mesh.
uniform sampler2D trimap; uniform sampler2D trimap;
uniform sampler2D foreground; uniform sampler2D foreground;
uniform sampler2D background;
int IS_BACKGROUND = 0; int IS_BACKGROUND = 0;
@@ -24,6 +25,10 @@ vec3 getForeColor(vec2 uvCoord) {
return texture(foreground, uvCoord).rgb; return texture(foreground, uvCoord).rgb;
} }
vec3 getBackColor(vec2 uvCoord) {
return texture(background, uvCoord).rgb;
}
int getState(vec3 c) { int getState(vec3 c) {
if (all(lessThanEqual(c, vec3(0.2f)))) { if (all(lessThanEqual(c, vec3(0.2f)))) {
return IS_BACKGROUND; return IS_BACKGROUND;
@@ -42,5 +47,9 @@ void main(){
if (status==IS_FOREGROUND) { if (status==IS_FOREGROUND) {
color = getForeColor(UV).rgb; color = getForeColor(UV).rgb;
} else if (status==IS_BACKGROUND) {
color = getBackColor(UV).rgb;
} else {
// render undefined area
} }
} }

View File

@@ -21,6 +21,10 @@ int IS_UNDEFINED = 1;
int IS_FOREGROUND = 2; int IS_FOREGROUND = 2;
int UNSET = -1; int UNSET = -1;
vec3 greenValue = vec3(0.0f, 1.0f, 0.0f);
vec3 difference = vec3(40.0f/255.0f);
int radius = 10;
vec3 getColor(vec2 uvCoord) { vec3 getColor(vec2 uvCoord) {
return texture(myTextureSampler, uvCoord).rgb; return texture(myTextureSampler, uvCoord).rgb;
@@ -31,8 +35,8 @@ bool isBackground(vec3 c) {
if (all( lessThanEqual(c, vec3(51.0f/255.0f, 208.0f/255.0f, 13.0f/255.0f))) && if (all( lessThanEqual(c, vec3(51.0f/255.0f, 208.0f/255.0f, 13.0f/255.0f))) &&
all(greaterThanEqual(c, vec3(47.0f/255.0f, 204.0f/255.0f, 9.0f/255.0f)))*/ all(greaterThanEqual(c, vec3(47.0f/255.0f, 204.0f/255.0f, 9.0f/255.0f)))*/
// 0, 255, 0 // 0, 255, 0
if (all( lessThanEqual(c, vec3(2.0f/255.0f, 255.0f/255.0f, 2.0f/255.0f))) && if (all( lessThanEqual(c, greenValue+difference)) &&
all(greaterThanEqual(c, vec3(0.0f/255.0f, 253.0f/255.0f, 0.0f/255.0f))) all(greaterThanEqual(c, greenValue-difference))
) { ) {
return true; return true;
} else { } else {
@@ -43,9 +47,9 @@ bool isBackground(vec3 c) {
void main(){ void main(){
int status = UNSET; int status = UNSET;
for(int w=-5;w<=5;w++){ for(int w=-radius;w<=radius;w++){
for(int h=-5;h<=5;h++){ for(int h=-radius;h<=radius;h++){
if (w+h==-10) { // first pixel if (w+h==-radius*2) { // first pixel
if (isBackground(getColor(UV+vec2(pixWidth*w, pixHeight*h)))) { if (isBackground(getColor(UV+vec2(pixWidth*w, pixHeight*h)))) {
status = IS_BACKGROUND; status = IS_BACKGROUND;
} else { } else {