Skip to content
Snippets Groups Projects
Commit 3d765f8c authored by Florent Berthaut's avatar Florent Berthaut
Browse files

Changed to shader files

parent 390fc25e
No related branches found
No related tags found
No related merge requests found
#version 130
uniform sampler2D sliceTex;
uniform float viewportWidth;
uniform float viewportHeight;
uniform float shapeID;
uniform float shapeIDBit;
uniform float mirrored;
uniform float thickness;
uniform int surface;
out vec4 color;
void main(void) {
float coordX = (gl_FragCoord.x-0.5)/viewportWidth;
float coordY = (gl_FragCoord.y-0.5)/viewportHeight;
ivec2 sliSize = textureSize(sliceTex, 0);
vec4 sli = texelFetch(sliceTex,
ivec2(coordX*float(sliSize.x),
coordY*float(sliSize.y)),
0);
float pixZ=abs(gl_FragCoord.z);
float cutZ=abs(sli.z);
// keep all ids of back surfaces after depth map
if(pixZ>cutZ && cutZ>0) {
if((mirrored<1 && !gl_FrontFacing)
|| (mirrored>0 && gl_FrontFacing)) {
color = vec4(shapeID, 0,
(abs(pixZ-cutZ)<thickness/1000.0 && surface>0)?1:0,
shapeIDBit);
}
else { //occlude back when front face also behind
color = vec4(-shapeID, 0, 0, -shapeIDBit);
}
}
else {
discard;
}
};
#version 130
in vec3 vertex;
uniform mat4 modelMat;
uniform mat4 viewMat;
uniform mat4 viewProjMat;
uniform float mirrored;
void main(void) {
vec4 posWS = modelMat * vec4(vertex, 1.0);
if(mirrored<1) {
posWS.x = -posWS.x;
}
gl_Position = viewProjMat * posWS;
}
#version 430
layout(binding=0) uniform sampler2D sliceTex;
uniform float viewportWidth;
uniform float viewportHeight;
uniform float shapeID;
uniform float shapeIDBit;
uniform float mirrored;
uniform float thickness;
uniform int surface;
out vec4 color;
void main(void) {
float coordX = (gl_FragCoord.x-0.5)/viewportWidth;
float coordY = (gl_FragCoord.y-0.5)/viewportHeight;
ivec2 sliSize = textureSize(sliceTex, 0);
vec4 sli = texelFetch(sliceTex,
ivec2(coordX*float(sliSize.x),
coordY*float(sliSize.y)),
0);
float pixZ=abs(gl_FragCoord.z);
float cutZ=abs(sli.z);
// keep all ids of back surfaces after depth map
if(pixZ>cutZ && cutZ>0) {
if((mirrored<1 && !gl_FrontFacing)
|| (mirrored>0 && gl_FrontFacing)) {
color = vec4(shapeID, 0,
(abs(pixZ-cutZ)<thickness/1000.0 && surface>0)?1:0,
shapeIDBit);
}
else { //occlude back when front face also behind
color = vec4(-shapeID, 0, 0, -shapeIDBit);
}
}
else {
discard;
}
};
#version 430
in vec3 vertex;
uniform mat4 modelMat;
uniform mat4 viewMat;
uniform mat4 viewProjMat;
uniform float mirrored;
void main(void) {
vec4 posWS = modelMat * vec4(vertex, 1.0);
if(mirrored<1) {
posWS.x = -posWS.x;
}
gl_Position = viewProjMat * posWS;
}
#version 130
in float kept;
in vec3 viewRay;
flat in int outDepthID;
out vec4 color;
void main(void) {
float thresh=0.8;
if(kept>=thresh) {
color = vec4((kept-thresh)/(1.0-thresh),
float(outDepthID),
gl_FragCoord.z,
length(viewRay));
}
else {
discard;
}
// color = vec4(1.0, 1.0, 0.0, 1.0);
};
#version 130
#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b);
#define mn3(a, b, c) s2(a, b); s2(a, c);
#define mx3(a, b, c) s2(b, c); s2(a, c);
#define mnmx3(a, b, c) mx3(a, b, c); s2(a, b);
#define mnmx4(a, b, c, d) s2(a, b); s2(c, d); s2(a, c); s2(b, d);
#define mnmx5(a, b, c, d, e) s2(a,b); s2(c,d);mn3(a,c,e);mx3(b,d,e);
#define mnmx6(a,b,c,d,e,f) s2(a,d);s2(b,e);s2(c,f);mn3(a,b,c);mx3(d,e,f);
in vec3 vertex;
uniform sampler2D depthCamTex;
uniform sampler2D depthCamTexFil;
uniform sampler2D markersTex;
uniform mat4 modelMat;
uniform mat4 viewMat;
uniform mat4 viewProjMat;
uniform float camXReso;
uniform float camYReso;
uniform float camXZFactor;
uniform float camYZFactor;
uniform int camFilter;
uniform int background;
uniform float camContThresh;
uniform float camMarkers;
uniform int depthType;
uniform int depthID;
uniform float outputCurs;
uniform float mirrored;
out vec3 viewRay;
out float kept;
flat out int outDepthID;
void main(void) {
vec4 depthPos = vec4(0, 0, 0, 1);
vec4 posWS = vec4(0, 0, 0, 1);
//depth camera
if(depthType==0) {
vec2 coords = vertex.xy;
//get marker if any
if(camMarkers>0) {
outDepthID = int(float(texture(markersTex,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 255.0);
}
else {
outDepthID=depthID+1;
}
//get depth pixel in camera texture
float depth =
float(texture(depthCamTex,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 65535.0;
kept=1.0;
float backgroundDepth=0;
if(background>0) {
float backDepth = float(texture(depthCamTex,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 65535.0;
if(backDepth<depth) {
depth=backDepth;
backgroundDepth=1;
}
}
if(depth<=500.0 || depth>8000.0) {
kept=0.0;
}
else if(backgroundDepth==0) {
//filter out contours
float maxD=camContThresh;
bool contour=false;
for(int dX = -1; dX <= 1; ++dX) {
for(int dY = -1; dY <= 1; ++dY) {
if(abs(float(texture(depthCamTex,
vec2((coords.x+dX)/camXReso,
(coords.y+dY)/camYReso)).r)
* 65535.0
- depth) > maxD) {
contour=true;
}
}
}
if(contour) {
kept=0.0;
}
//see if needs filtering
if(camFilter>0) {
float filtDepth = float(texture(depthCamTexFil,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 65535.0;
//select either filtered version or current one
//depending on movement
if(abs(filtDepth-depth)<camContThresh) {
float filRatio = abs(filtDepth-depth)/camContThresh;
depth=(1-filRatio)*filtDepth+(filRatio)*depth;
}
}
}
//test distance again
if(depth<=500.0 || depth>8000.0) {
kept=0.0;
}
//compute position in world units
depthPos = vec4((vertex.x/camXReso-0.5)
*depth*camXZFactor,
(0.5-(vertex.y/camYReso))
*depth*camYZFactor,
depth,
1.0);
//get world pos
posWS = modelMat * depthPos;
}
//other slicing shapes
else {
outDepthID=depthID+1;
kept=1.0;
depthPos=vec4(vertex, 1.0);
posWS = modelMat * depthPos;
if(mirrored<1) {
posWS.x = -posWS.x;
}
}
//keep/interpolate ray from view to each vertex
viewRay = (posWS.xyz - vec3(viewMat[3][0],
viewMat[3][1],
viewMat[3][2]));
gl_Position = viewProjMat * posWS;
};
#version 430
in float kept;
in vec3 viewRay;
flat in int outDepthID;
out vec4 color;
void main(void) {
float thresh=0.8;
if(kept>=thresh) {
color = vec4((kept-thresh)/(1.0-thresh),
float(outDepthID),
gl_FragCoord.z,
length(viewRay));
}
else {
discard;
}
// color = vec4(1.0, 1.0, 0.0, 1.0);
};
#version 430
#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b);
#define mn3(a, b, c) s2(a, b); s2(a, c);
#define mx3(a, b, c) s2(b, c); s2(a, c);
#define mnmx3(a, b, c) mx3(a, b, c); s2(a, b);
#define mnmx4(a, b, c, d) s2(a, b); s2(c, d); s2(a, c); s2(b, d);
#define mnmx5(a, b, c, d, e) s2(a,b); s2(c,d);mn3(a,c,e);mx3(b,d,e);
#define mnmx6(a,b,c,d,e,f) s2(a,d);s2(b,e);s2(c,f);mn3(a,b,c);mx3(d,e,f);
in vec3 vertex;
layout(binding=0) uniform sampler2D depthCamTex;
layout(binding=1) uniform sampler2D depthCamTexFil;
layout(binding=2) uniform sampler2D markersTex;
//layout(r32ui, binding=2) uniform coherent uimage2D outputTex;
uniform mat4 modelMat;
uniform mat4 viewMat;
uniform mat4 viewProjMat;
uniform float camXReso;
uniform float camYReso;
uniform float camXZFactor;
uniform float camYZFactor;
uniform int camFilter;
uniform int background;
uniform float camContThresh;
uniform float camMarkers;
uniform int depthType;
uniform int depthID;
uniform float outputCurs;
uniform float mirrored;
out vec3 viewRay;
out float kept;
flat out int outDepthID;
void main(void) {
vec4 depthPos = vec4(0, 0, 0, 1);
vec4 posWS = vec4(0, 0, 0, 1);
//depth camera
if(depthType==0) {
vec2 coords = vertex.xy;
//get marker if any
if(camMarkers>0) {
outDepthID = int(float(texture(markersTex,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 255.0);
}
else {
outDepthID=depthID+1;
}
//get depth pixel in camera texture
float depth =
float(texture(depthCamTex,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 65535.0;
kept=1.0;
float backgroundDepth=0;
if(background>0) {
float backDepth = float(texture(depthCamTex,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 65535.0;
if(backDepth<depth) {
depth=backDepth;
backgroundDepth=1;
}
}
if(depth<=500.0 || depth>8000.0) {
kept=0.0;
}
else if(backgroundDepth==0) {
//filter out contours
float maxD=camContThresh;
bool contour=false;
for(int dX = -1; dX <= 1; ++dX) {
for(int dY = -1; dY <= 1; ++dY) {
if(abs(float(texture(depthCamTex,
vec2((coords.x+dX)/camXReso,
(coords.y+dY)/camYReso)).r)
* 65535.0
- depth) > maxD) {
contour=true;
}
}
}
if(contour) {
kept=0.0;
}
//see if needs filtering
if(camFilter>0) {
float filtDepth = float(texture(depthCamTexFil,
vec2(coords.x/camXReso,
coords.y/camYReso)).r)
* 65535.0;
//select either filtered version or current one
//depending on movement
if(abs(filtDepth-depth)<camContThresh) {
float filRatio = abs(filtDepth-depth)/camContThresh;
depth=(1-filRatio)*filtDepth+(filRatio)*depth;
}
}
}
//test distance again
if(depth<=500.0 || depth>8000.0) {
kept=0.0;
}
//compute position in world units
depthPos = vec4((vertex.x/camXReso-0.5)
*depth*camXZFactor,
(0.5-(vertex.y/camYReso))
*depth*camYZFactor,
depth,
1.0);
//get world pos
posWS = modelMat * depthPos;
}
//other slicing shapes
else {
outDepthID=depthID+1;
kept=1.0;
depthPos=vec4(vertex, 1.0);
posWS = modelMat * depthPos;
if(mirrored<1) {
posWS.x = -posWS.x;
}
}
/*
//output minimum point on z axis if output is active
if(outputCurs>0 && kept>0.0) {
imageAtomicMin(outputTex,ivec2(0,int(depthID)+500),
int(floor(1000.0+posWS.z/10.0)*1000000
+floor(posWS.y/10.0+500.0)*1000
+floor(posWS.x/10.0+500.0)));
// imageAtomicMin(outputTex,ivec2(0, int(depthID)+500),4400600);
// imageAtomicMin(outputTex,ivec2(0, int(depthID)+500),6400600);
}
*/
//keep/interpolate ray from view to each vertex
viewRay = (posWS.xyz - vec3(viewMat[3][0],
viewMat[3][1],
viewMat[3][2]));
gl_Position = viewProjMat * posWS;
};
#!/usr/bin/env python
import sys, os
from waflib import Utils
def options(opt):
opt.load('compiler_cxx')
......@@ -59,9 +60,9 @@ def configure(conf):
'/usr/include/libxml2',
'/usr/include/opencv4',
'/usr/local/include/opencv4',
'/usr/include/opencv4',
'/usr/local/include/openni2',
'/usr/include/openni2']
'/usr/include/openni2',
'build/']
conf.env.LIB_OS = ['jpeg', 'X11', 'm',
'xml2', 'GLU', 'GL', 'pthread',
'glfw', 'GLEW',
......@@ -70,12 +71,12 @@ def configure(conf):
'opencv_calib3d', 'opencv_imgproc',
'opencv_imgcodecs', 'opencv_videoio',
'opencv_aruco', 'opencv_features2d',
'assimp', 'portaudio']
'assimp', 'rtaudio']
conf.env.LIBPATH_OS = ['/usr/local/lib/']
conf.env.DEFINES_OS = ['POSIX=1','GL42=1', 'LINUX=1']
conf.env.DEFINES_OS = ['POSIX=1','GL43=1', 'LINUX=1']
#release specific
conf.env.CXXFLAGS = ['-O3', '-Wall', '-std=c++2a']
conf.env.CXXFLAGS = ['-O3', '-w', '-std=c++2a']
conf.env.DEFINES = ['DEBUG(x)=//x']
#debug specific
......@@ -104,6 +105,22 @@ def build(bld):
installPath = '/opt/bin/'
macApp = 'True'
#Create shaders.h.in file to integrate shaders in binary
shaders = ""
for s in ["render", "post", "select", "slice", "calib"] :
for v in ["43", "30"] :
shaders += 'std::string '+s+v+'FS = R"('\
+ Utils.readf('src/shaders/'+s+v+'.fs')\
+ ')";\n\n'
shaders += 'std::string '+s+v+'VS = R"('\
+ Utils.readf('src/shaders/'+s+v+'.vs')\
+ ')";\n\n'
Utils.writef('build/shaders.h.in', shaders)
bld(rule='touch shaders.h.in',
source=bld.path.ant_glob('src/shaders/*'),
target="shaders.h.in")
bld.program(
source = bld.path.ant_glob('src/gui/*.cpp')
+ bld.path.ant_glob('src/modules/*.cpp')
......@@ -111,7 +128,7 @@ def build(bld):
+ bld.path.ant_glob('src/osc/*.cpp')
+ bld.path.ant_glob('src/audio/*.cpp')
+ bld.path.ant_glob('src/*.cpp'),
use = ['OS','ringbuf','oscpack'],
use = ['OS','ringbuf','oscpack', 'shaders.h.in'],
target = 'rivill'+bld.variant,
vnum = '0.0.1',
mac_app = macApp,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment