-
Notifications
You must be signed in to change notification settings - Fork 5
/
ColorReplacerShader.cpp
52 lines (43 loc) · 1.58 KB
/
ColorReplacerShader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "client.h"
#include "ColorReplacerShader.h"
const static char replacer_shader[] =
"uniform sampler2D texture;\n"
"uniform vec3 color1;\n"
"uniform vec3 replace1;\n"
"uniform float eps;\n"
"void main() {\n"
" vec4 pixel = texture2D(texture, gl_TexCoord[0].xy); \n"
" if(pixel.r > color1.r - eps && pixel.r < color1.r + eps && pixel.g > color1.g - eps && pixel.g < color1.g + eps && pixel.b > color1.b - eps && pixel.b < color1.b + eps ){\n"
" pixel = vec4(replace1, pixel.a );\n"
" }\n"
" pixel.r = gl_Color.r * pixel.r;\n"
" pixel.g = gl_Color.g * pixel.g;\n"
" pixel.b = gl_Color.b * pixel.b;\n"
" pixel.a = gl_Color.a * pixel.a;\n"
" gl_FragColor = pixel;\n"
"}\n";
bool ColorReplacerShader::init(){
return load( replacer_shader );
}
void ColorReplacerShader::updateUniforms(){
#if !(TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE || defined(__linux__) )
float fromcol[]={ from_color.r, from_color.g, from_color.b};
GLuint uniid1=glGetUniformLocation(program,"color1");
glUniform3fv( uniid1,1,fromcol);
float tocol[]={ to_color.r, to_color.g, to_color.b };
GLuint uniid2=glGetUniformLocation(program,"replace1");
glUniform3fv( uniid2,1,tocol);
GLuint uniid3=glGetUniformLocation(program,"texture");
glUniform1i(uniid3, 0 );
GLuint uniid4=glGetUniformLocation(program,"eps");
glUniform1f(uniid4, epsilon );
#endif
}
void ColorReplacerShader::onTrack( RemoteHead *rh ) {
if(!tracker) {
tracker = new TrackerColorReplacerShader(rh,this);
}
tracker->scanShader();
tracker->broadcastDiff( false );
tracker->flipCurrentBuffer();
}