Added background to refinement shader
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
int main(int argc, char* args[]) {
|
||||
GLFWwindow* window;
|
||||
GLuint tex1, tex2;
|
||||
GLuint texFG, texBG;
|
||||
int textw, texth;
|
||||
int textw2, texth2;
|
||||
|
||||
@@ -92,20 +92,19 @@ int main(int argc, char* args[]) {
|
||||
|
||||
|
||||
|
||||
tex1 = LoadTexture("../img/tests/flieger.jpg",&textw,&texth);
|
||||
printf("Tex1: %d\n", tex1);
|
||||
texBG = LoadTexture("../img/backgrounds/sky.jpg",&textw2,&texth2);
|
||||
texFG = LoadTexture("../img/tests/flieger.jpg",&textw,&texth);
|
||||
printf("Tex1: %d\n", texFG);
|
||||
glfwSetWindowSize(window, textw, texth);
|
||||
glViewport(0, 0, 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;
|
||||
glGenTextures(1, &renderedTexture);
|
||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
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);
|
||||
// Poor filtering. Needed !
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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 textureLocFore = glGetUniformLocation(programRefineID, "foreground");
|
||||
GLint textureLocBack = glGetUniformLocation(programRefineID, "background");
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, tex1);
|
||||
glBindTexture(GL_TEXTURE_2D, texFG);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, texBG);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, renderedTexture);
|
||||
|
||||
@@ -199,6 +201,7 @@ int main(int argc, char* args[]) {
|
||||
|
||||
glUseProgram(programRefineID);
|
||||
glUniform1i(textureLocTri, 2);
|
||||
glUniform1i(textureLocBack, 1);
|
||||
glUniform1i(textureLocFore, 0);
|
||||
|
||||
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
1385320478 source:d:\owncloud\documents\programmierung\cpp\opengl-test-two\main.cpp
|
||||
<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>
|
||||
<GLFW/glfw3.h>
|
||||
<SDL2/SDL.h>
|
||||
<SDL2/SDL_image.h>
|
||||
<stdio.h>
|
||||
<iostream>
|
||||
<fstream>
|
||||
<vector>
|
||||
<stdexcept>
|
||||
"loaders.h"
|
||||
|
||||
1473015242 d:\owncloud\documents\programmierung\cpp\imanox-chroma-matting\opengl-test-two\include\glfw\glfw3.h
|
||||
<stddef.h>
|
||||
|
||||
@@ -9,6 +9,7 @@ out vec3 color;
|
||||
// Values that stay constant for the whole mesh.
|
||||
uniform sampler2D trimap;
|
||||
uniform sampler2D foreground;
|
||||
uniform sampler2D background;
|
||||
|
||||
|
||||
int IS_BACKGROUND = 0;
|
||||
@@ -24,6 +25,10 @@ vec3 getForeColor(vec2 uvCoord) {
|
||||
return texture(foreground, uvCoord).rgb;
|
||||
}
|
||||
|
||||
vec3 getBackColor(vec2 uvCoord) {
|
||||
return texture(background, uvCoord).rgb;
|
||||
}
|
||||
|
||||
int getState(vec3 c) {
|
||||
if (all(lessThanEqual(c, vec3(0.2f)))) {
|
||||
return IS_BACKGROUND;
|
||||
@@ -42,5 +47,9 @@ void main(){
|
||||
|
||||
if (status==IS_FOREGROUND) {
|
||||
color = getForeColor(UV).rgb;
|
||||
} else if (status==IS_BACKGROUND) {
|
||||
color = getBackColor(UV).rgb;
|
||||
} else {
|
||||
// render undefined area
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ int IS_UNDEFINED = 1;
|
||||
int IS_FOREGROUND = 2;
|
||||
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) {
|
||||
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))) &&
|
||||
all(greaterThanEqual(c, vec3(47.0f/255.0f, 204.0f/255.0f, 9.0f/255.0f)))*/
|
||||
// 0, 255, 0
|
||||
if (all( lessThanEqual(c, vec3(2.0f/255.0f, 255.0f/255.0f, 2.0f/255.0f))) &&
|
||||
all(greaterThanEqual(c, vec3(0.0f/255.0f, 253.0f/255.0f, 0.0f/255.0f)))
|
||||
if (all( lessThanEqual(c, greenValue+difference)) &&
|
||||
all(greaterThanEqual(c, greenValue-difference))
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -43,9 +47,9 @@ bool isBackground(vec3 c) {
|
||||
void main(){
|
||||
int status = UNSET;
|
||||
|
||||
for(int w=-5;w<=5;w++){
|
||||
for(int h=-5;h<=5;h++){
|
||||
if (w+h==-10) { // first pixel
|
||||
for(int w=-radius;w<=radius;w++){
|
||||
for(int h=-radius;h<=radius;h++){
|
||||
if (w+h==-radius*2) { // first pixel
|
||||
if (isBackground(getColor(UV+vec2(pixWidth*w, pixHeight*h)))) {
|
||||
status = IS_BACKGROUND;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user