diff --git a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h index 1e10b72d0b0..add7058a5ee 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h @@ -217,9 +217,7 @@ void CGAL::QGLViewer::initializeGL() { QSurfaceFormat cur_f = QOpenGLContext::currentContext()->format(); const char* rt =(cur_f.renderableType() == QSurfaceFormat::OpenGLES) ? "GLES" : "GL"; - qDebug()<<"Using context " - <resources/shader_instanced.vert resources/shader_no_light_no_selection.frag resources/shader_c3t3_spheres.vert + resources/shader_c3t3_spheres.frag resources/shader_c3t3_edges.vert resources/shader_c3t3_edges.frag resources/shader_c3t3.vert @@ -84,6 +85,7 @@ resources/compatibility_shaders/shader_c3t3_edges.frag resources/compatibility_shaders/shader_c3t3_edges.vert resources/compatibility_shaders/shader_c3t3_spheres.vert + resources/compatibility_shaders/shader_c3t3_spheres.frag resources/compatibility_shaders/shader_c3t3.frag resources/compatibility_shaders/shader_c3t3.vert resources/compatibility_shaders/shader_instanced.vert diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 4b58030049f..ee0f20745ec 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -1359,9 +1359,9 @@ QOpenGLShaderProgram* Viewer::getShaderProgram(int name) const case PROGRAM_CUTPLANE_SPHERES: { QOpenGLShaderProgram* program = isOpenGL_4_3() - ? declare_program(name, ":/cgal/Polyhedron_3/resources/shader_c3t3_spheres.vert" , ":/cgal/Polyhedron_3/resources/shader_c3t3.frag") + ? declare_program(name, ":/cgal/Polyhedron_3/resources/shader_c3t3_spheres.vert" , ":/cgal/Polyhedron_3/resources/shader_c3t3_spheres.frag") : declare_program(name, ":/cgal/Polyhedron_3/resources/compatibility_shaders/shader_c3t3_spheres.vert" , - ":/cgal/Polyhedron_3/resources/compatibility_shaders/shader_c3t3.frag"); + ":/cgal/Polyhedron_3/resources/compatibility_shaders/shader_c3t3_spheres.frag"); program->setProperty("hasLight", true); program->setProperty("hasNormals", true); program->setProperty("hasCenter", true); diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_c3t3_spheres.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_c3t3_spheres.frag new file mode 100644 index 00000000000..26eb7b16578 --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_c3t3_spheres.frag @@ -0,0 +1,69 @@ + +varying highp vec4 color; +varying highp vec4 fP; +varying highp vec3 fN; +uniform highp vec4 light_pos; +uniform highp vec4 light_diff; +uniform highp vec4 light_spec; +uniform highp vec4 light_amb; +uniform highp float spec_power ; +uniform int is_two_side; +uniform bool is_selected; +uniform highp float near; +uniform highp float far; +uniform highp float width; +uniform highp float height; +uniform bool comparing; +uniform bool writing; +uniform sampler2D sampler; +uniform highp float alpha; + +highp float depth(float z) +{ + return (2 * near) / (far + near - z * (far - near)); +} + +void main(void) { + float d = depth(gl_FragCoord.z); + float test = texture2D(sampler, vec2(gl_FragCoord.x/width, gl_FragCoord.y/height)).r; + if(comparing && d <= test) + discard; + if(writing) + gl_FragColor = vec4(d,d,d,1.0); + else + { + if(color.w<0.) + { + + highp vec4 my_color = vec4(color.xyz, 1.); + highp vec3 L = light_pos.xyz - fP.xyz; + highp vec3 V = -fP.xyz; + highp vec3 N; + if(fN == vec3(0.0,0.0,0.0)) + { + gl_FragColor = my_color; + return; + } + else + N = normalize(fN); + L = normalize(L); + V = normalize(V); + highp vec3 R = reflect(-L, N); + highp vec4 diffuse; + if(is_two_side == 1) + diffuse = abs(dot(N,L)) * light_diff * my_color; + else + diffuse = max(dot(N,L), 0.0) * light_diff * my_color; + highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; + highp vec4 ret_color = vec4((my_color*light_amb).xyz + diffuse.xyz + specular.xyz,1); + if(is_selected) + gl_FragColor = vec4(ret_color.r+70.0/255.0, ret_color.g+70.0/255.0, ret_color.b+70.0/255.0, alpha); + else + gl_FragColor = vec4(ret_color.xyz, alpha); + } + else + discard; + } +} + + diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3_spheres.frag b/Polyhedron/demo/Polyhedron/resources/shader_c3t3_spheres.frag new file mode 100644 index 00000000000..9a40fe3dd2d --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3_spheres.frag @@ -0,0 +1,72 @@ +#version 150 +in vec4 color; +in vec4 fP; +in vec3 fN; +uniform vec4 light_pos; +uniform vec4 light_diff; +uniform vec4 light_spec; +uniform vec4 light_amb; +uniform float spec_power ; +uniform int is_two_side; +uniform bool is_selected; +uniform float near; +uniform float far; +uniform float width; +uniform float height; +uniform bool comparing; +uniform bool writing; +uniform sampler2D sampler; +uniform float alpha; +uniform bool is_surface; +uniform vec4 is_visible_bitset; +uniform bool is_filterable; +out vec4 out_color; + +float depth(float z) +{ + return (2 * near) / (far + near - z * (far - near)); +} + +void main(void) { + float d = depth(gl_FragCoord.z); + float test = texture(sampler, vec2(gl_FragCoord.x/width, gl_FragCoord.y/height)).r; + if(comparing && d <= test) + discard; + if(writing) + out_color = vec4(d,d,d,1.0); + else + { + if(color.w<0 || is_surface) + { + vec4 my_color = vec4(color.xyz, 1.); + vec3 L = light_pos.xyz - fP.xyz; + vec3 V = -fP.xyz; + vec3 N; + if(fN == vec3(0.0,0.0,0.0)) + { + out_color = my_color; + return; + } + else + N = normalize(fN); + L = normalize(L); + V = normalize(V); + vec3 R = reflect(-L, N); + vec4 diffuse; + if(is_two_side == 1) + diffuse = abs(dot(N,L)) * light_diff * my_color; + else + diffuse = max(dot(N,L), 0.0) * light_diff * my_color; + vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; + vec4 ret_color = vec4((my_color*light_amb).xyz + diffuse.xyz + specular.xyz,1); + if(is_selected) + out_color = vec4(ret_color.r+70.0/255.0, ret_color.g+70.0/255.0, ret_color.b+70.0/255.0, alpha); + else + out_color = vec4(ret_color.xyz, alpha); + } + else + discard; + } +} + +