diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp index e903ab64bea..9069e592943 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp @@ -51,24 +51,24 @@ void Viewer::compile_shaders() "varying highp vec4 fP; \n" "varying highp vec3 fN; \n" "uniform highp vec4 color; \n" - "uniform vec4 light_pos; \n" - "uniform vec4 light_diff; \n" - "uniform vec4 light_spec; \n" - "uniform vec4 light_amb; \n" + "uniform highp vec4 light_pos; \n" + "uniform highp vec4 light_diff; \n" + "uniform highp vec4 light_spec; \n" + "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" "void main(void) { \n" - " vec3 L = light_pos.xyz - fP.xyz; \n" - " vec3 V = -fP.xyz; \n" + " highp vec3 L = light_pos.xyz - fP.xyz; \n" + " highp vec3 V = -fP.xyz; \n" - " vec3 N = normalize(fN); \n" + " highp vec3 N = normalize(fN); \n" " L = normalize(L); \n" " V = normalize(V); \n" - " vec3 R = reflect(-L, N); \n" - " vec4 diffuse = abs(dot(N,L)) * light_diff * color; \n" - " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + " highp vec3 R = reflect(-L, N); \n" + " highp vec4 diffuse = abs(dot(N,L)) * light_diff * color; \n" + " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" "gl_FragColor = light_amb*color + diffuse + specular ; \n" "} \n" diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp index 2e53e260c8a..6cb777920fc 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp +++ b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp @@ -56,24 +56,24 @@ void Viewer::compile_shaders() "varying highp vec4 fP; \n" "varying highp vec3 fN; \n" "uniform highp vec4 color; \n" - "uniform vec4 light_pos; \n" - "uniform vec4 light_diff; \n" - "uniform vec4 light_spec; \n" - "uniform vec4 light_amb; \n" + "uniform highp vec4 light_pos; \n" + "uniform highp vec4 light_diff; \n" + "uniform highp vec4 light_spec; \n" + "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" "void main(void) { \n" - " vec3 L = light_pos.xyz - fP.xyz; \n" - " vec3 V = -fP.xyz; \n" + " highp vec3 L = light_pos.xyz - fP.xyz; \n" + " highp vec3 V = -fP.xyz; \n" - " vec3 N = normalize(fN); \n" + " highp vec3 N = normalize(fN); \n" " L = normalize(L); \n" " V = normalize(V); \n" - " vec3 R = reflect(-L, N); \n" - " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * color; \n" - " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + " highp vec3 R = reflect(-L, N); \n" + " highp vec4 diffuse = max(dot(N,L), 0.0) * light_diff * color; \n" + " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" "gl_FragColor = light_amb*color + diffuse ; \n" "} \n" diff --git a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h index 1d2fbd751e9..8b23594cd7c 100644 --- a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h +++ b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h @@ -93,24 +93,24 @@ const char fragment_source_color[] = "varying highp vec4 fP; \n" "varying highp vec3 fN; \n" "varying highp vec4 fColor; \n" - "uniform vec4 light_pos; \n" - "uniform vec4 light_diff; \n" - "uniform vec4 light_spec; \n" - "uniform vec4 light_amb; \n" + "uniform highp vec4 light_pos; \n" + "uniform highp vec4 light_diff; \n" + "uniform highp vec4 light_spec; \n" + "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" "void main(void) { \n" - " vec3 L = light_pos.xyz - fP.xyz; \n" - " vec3 V = -fP.xyz; \n" + " highp vec3 L = light_pos.xyz - fP.xyz; \n" + " highp vec3 V = -fP.xyz; \n" - " vec3 N = normalize(fN); \n" + " highp vec3 N = normalize(fN); \n" " L = normalize(L); \n" " V = normalize(V); \n" - " vec3 R = reflect(-L, N); \n" - " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" - " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + " highp vec3 R = reflect(-L, N); \n" + " highp vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" + " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" "gl_FragColor = light_amb*fColor + diffuse ; \n" "} \n" @@ -142,6 +142,93 @@ const char fragment_source_p_l[] = "} \n" "\n" }; + +//------------------------------------------------------------------------------ +// compatibility shaders + +const char vertex_source_color_comp[] = + { + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec3 color;\n" + + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 mv_matrix; \n" + + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" + + "uniform highp float point_size; \n" + "void main(void)\n" + "{\n" + " fP = mv_matrix * vertex; \n" + " highp mat3 mv_matrix_3; \n" + " mv_matrix_3[0] = mv_matrix[0].xyz; \n" + " mv_matrix_3[1] = mv_matrix[1].xyz; \n" + " mv_matrix_3[2] = mv_matrix[2].xyz; \n" + " fN = mv_matrix_3* normal; \n" + " fColor = vec4(color, 1.0); \n" + " gl_PointSize = point_size;\n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; + +const char fragment_source_color_comp[] = + { + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" + "uniform highp vec4 light_pos; \n" + "uniform highp vec4 light_diff; \n" + "uniform highp vec4 light_spec; \n" + "uniform highp vec4 light_amb; \n" + "uniform highp float spec_power ; \n" + + "void main(void) { \n" + + " highp vec3 L = light_pos.xyz - fP.xyz; \n" + " highp vec3 V = -fP.xyz; \n" + + " highp vec3 N = normalize(fN); \n" + " L = normalize(L); \n" + " V = normalize(V); \n" + + " highp vec3 R = reflect(-L, N); \n" + " highp vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" + " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + + "gl_FragColor = light_amb*fColor + diffuse ; \n" + "} \n" + "\n" + }; + +const char vertex_source_p_l_comp[] = + { + "attribute highp vec4 vertex;\n" + "attribute highp vec3 color;\n" + "uniform highp mat4 mvp_matrix;\n" + "varying highp vec4 fColor; \n" + "uniform highp float point_size; \n" + "void main(void)\n" + "{\n" + " gl_PointSize = point_size;\n" + " fColor = vec4(color, 1.0); \n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; + +const char fragment_source_p_l_comp[] = + { + "varying highp vec4 fColor; \n" + "void main(void) { \n" + "gl_FragColor = fColor; \n" + "} \n" + "\n" + }; + + + //------------------------------------------------------------------------------ inline CGAL::Color get_random_color(CGAL::Random& random) { @@ -378,12 +465,21 @@ protected: } // Vertices and segments shader + + const char* source_ = isOpenGL_4_3() + ? vertex_source_p_l + : vertex_source_p_l_comp; + QOpenGLShader *vertex_shader_p_l = new QOpenGLShader(QOpenGLShader::Vertex); - if(!vertex_shader_p_l->compileSourceCode(vertex_source_p_l)) + if(!vertex_shader_p_l->compileSourceCode(source_)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_p_l)) + if(!fragment_shader_p_l->compileSourceCode(source_)) { std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_color)) + if(!vertex_shader_face->compileSourceCode(source_)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_color)) + if(!fragment_shader_face->compileSourceCode(source_)) { std::cerr<<"Compiling fragmentsource FAILED"<0.0 || dist[5]>0.0) discard; - gl_FragColor = highp vec4(color.xyz, alpha); + gl_FragColor = vec4(color.xyz, alpha); } diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_old_flat.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_old_flat.frag index 3326e4225af..bcb5d361280 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_old_flat.frag +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_old_flat.frag @@ -1,4 +1,4 @@ -#version 120 + varying highp vec4 color; varying highp vec4 fP; uniform highp vec4 light_pos; @@ -12,24 +12,24 @@ void main(void) { highp vec3 L = light_pos.xyz - fP.xyz; highp vec3 V = -fP.xyz; highp vec3 N; - vec3 X = dFdx(fP.xyz); - vec3 Y = dFdy(fP.xyz); - vec3 normal=normalize(cross(X,Y)); + highp vec3 X = dFdx(fP.xyz); + highp vec3 Y = dFdy(fP.xyz); + highp vec3 normal=normalize(cross(X,Y)); - if(normal == highp vec3(0.0,0.0,0.0)) - N = highp vec3(0.0,0.0,0.0); + if(normal == vec3(0.0,0.0,0.0)) + N = vec3(0.0,0.0,0.0); else N = normalize(normal); L = normalize(L); V = normalize(V); highp vec3 R = reflect(-L, N); - vec4 diffuse; + highp vec4 diffuse; if(is_two_side == 1) diffuse = abs(dot(N,L)) * light_diff * color; else diffuse = max(dot(N,L), 0.0) * light_diff * color; highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; - vec4 ret_color = vec4((color*light_amb).xyz + diffuse.xyz + specular.xyz,1); + highp vec4 ret_color = vec4((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, 1.0); else diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_plane_two_faces.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_plane_two_faces.frag index 8c6a9a38251..a5986527e8e 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_plane_two_faces.frag +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_plane_two_faces.frag @@ -1,4 +1,4 @@ -#version 120 + varying highp vec4 color; uniform highp vec3 dirView; uniform highp vec3 plane_normal; @@ -7,7 +7,7 @@ uniform bool is_selected; void main(void) { highp vec4 t_color = color; -highp vec3 dir = highp vec3(plane_pos.x - dirView.x, plane_pos.y - dirView.y, plane_pos.z - dirView.z); +highp vec3 dir = vec3(plane_pos.x - dirView.x, plane_pos.y - dirView.y, plane_pos.z - dirView.z); if(dot(dir, plane_normal)>0.0) t_color = vec4(1.0-color.r, 1.0-color.g, 1.0-color.b, color.a); if(is_selected) diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_light.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_light.frag index 43c775cbcdb..2c0b38aa039 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_light.frag +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_light.frag @@ -1,4 +1,4 @@ -#version 120 + varying highp vec4 color; varying highp vec4 fP; varying highp vec3 fN; @@ -44,18 +44,18 @@ void main(void) { gl_FragColor = vec4(d,d,d,1.0); else { - vec4 my_color = vec4(color.xyz, 1.0); + highp vec4 my_color = vec4(color.xyz, 1.0); highp vec3 L = light_pos.xyz - fP.xyz; highp vec3 V = -fP.xyz; highp vec3 N; - if(fN == highp vec3(0.0,0.0,0.0)) - N = highp vec3(0.0,0.0,0.0); + if(fN == vec3(0.0,0.0,0.0)) + N = vec3(0.0,0.0,0.0); else N = normalize(fN); L = normalize(L); V = normalize(V); highp vec3 R = reflect(-L, N); - vec4 diffuse; + highp vec4 diffuse; if(is_two_side == 1) diffuse = abs(dot(N,L)) * light_diff * color; else diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.frag index 79034e2fcd6..8d398d7c6ef 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.frag +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.frag @@ -1,4 +1,4 @@ -#version 120 + varying highp vec3 fColors; varying highp vec2 f_texCoord; uniform sampler2D s_texture; diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.vert b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.vert index 811ce461ffd..e73931212fa 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.vert +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_texture.vert @@ -19,21 +19,21 @@ uniform highp float point_size; void main(void) { gl_PointSize = point_size; - vec4 P = mv_matrix * vertex; - mat3 mv_matrix_3; - mv_matrix_3[0] = mv_matrix[0].xyz; - mv_matrix_3[1] = mv_matrix[1].xyz; - mv_matrix_3[2] = mv_matrix[2].xyz; - vec3 N = mv_matrix_3* normals; - vec3 L = light_pos.xyz - P.xyz; - N = normalize(N); - L = normalize(L); - vec3 diffuse; - if(is_two_side == 1) - diffuse = abs(dot(N,L)) * light_diff.xyz; - else - diffuse = max(dot(N,L), 0.0) * light_diff.xyz; - f_texCoord = v_texCoord; - fColors = vec3(1.0, 1.0, 1.0) * (light_amb.xyz + diffuse); - gl_Position = mvp_matrix * f_matrix * vertex; + highp vec4 P = mv_matrix * vertex; + mat3 mv_matrix_3; + mv_matrix_3[0] = mv_matrix[0].xyz; + mv_matrix_3[1] = mv_matrix[1].xyz; + mv_matrix_3[2] = mv_matrix[2].xyz; + highp vec3 N = mv_matrix_3* normals; + highp vec3 L = light_pos.xyz - P.xyz; + N = normalize(N); + L = normalize(L); + highp vec3 diffuse; + if(is_two_side == 1) + diffuse = abs(dot(N,L)) * light_diff.xyz; + else + diffuse = max(dot(N,L), 0.0) * light_diff.xyz; + f_texCoord = v_texCoord; + fColors = vec3(1.0, 1.0, 1.0) * (light_amb.xyz + diffuse); + gl_Position = mvp_matrix * f_matrix * vertex; } diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_textured_edges.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_textured_edges.frag index eb35fed7437..3d006822334 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_textured_edges.frag +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_with_textured_edges.frag @@ -1,4 +1,4 @@ -#version 120 + varying highp vec3 fColors; varying highp vec2 f_texCoord; uniform highp sampler2D s_texture; diff --git a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_without_light.frag b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_without_light.frag index 37a2143398c..57a1c4661a1 100644 --- a/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_without_light.frag +++ b/Polyhedron/demo/Polyhedron/resources/compatibility_shaders/shader_without_light.frag @@ -1,4 +1,4 @@ -#version 120 + varying highp vec4 color; varying highp float dist[6]; uniform bool is_selected; diff --git a/Polyhedron/demo/Polyhedron/resources/heat_intensity_shader.frag b/Polyhedron/demo/Polyhedron/resources/heat_intensity_shader.frag index 90f0bcc072b..b1b6da41e7c 100644 --- a/Polyhedron/demo/Polyhedron/resources/heat_intensity_shader.frag +++ b/Polyhedron/demo/Polyhedron/resources/heat_intensity_shader.frag @@ -55,8 +55,8 @@ void main(void) { vec3 L = light_pos.xyz - fP.xyz; vec3 V = -fP.xyz; vec3 N; - if(fN == highp vec3(0.0,0.0,0.0)) - N = highp vec3(0.0,0.0,0.0); + if(fN == vec3(0.0,0.0,0.0)) + N = vec3(0.0,0.0,0.0); else N = normalize(fN); L = normalize(L); diff --git a/Polyhedron/demo/Polyhedron/resources/shader_flat.frag b/Polyhedron/demo/Polyhedron/resources/shader_flat.frag index be9870bca01..f6b2484283d 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_flat.frag +++ b/Polyhedron/demo/Polyhedron/resources/shader_flat.frag @@ -32,8 +32,8 @@ void main(void) vec3 V = -fs_in.fP.xyz; vec3 N; - if(fs_in.normal == highp vec3(0.0,0.0,0.0)) - N = highp vec3(0.0,0.0,0.0); + if(fs_in.normal == vec3(0.0,0.0,0.0)) + N = vec3(0.0,0.0,0.0); else N = fs_in.normal; L = normalize(L); diff --git a/Triangulation_3/demo/Triangulation_3/Viewer.cpp b/Triangulation_3/demo/Triangulation_3/Viewer.cpp index ca1add3a016..6b2ae97a005 100644 --- a/Triangulation_3/demo/Triangulation_3/Viewer.cpp +++ b/Triangulation_3/demo/Triangulation_3/Viewer.cpp @@ -234,7 +234,7 @@ void Viewer::compile_shaders() "#version 120 \n" "varying highp vec4 fP; \n" "varying highp vec3 fN; \n" - "uniform vec4 color; \n" + "uniform highp vec4 color; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" @@ -243,16 +243,16 @@ void Viewer::compile_shaders() "void main(void) { \n" - " vec3 L = light_pos.xyz - fP.xyz; \n" - " vec3 V = -fP.xyz; \n" + " highp vec3 L = light_pos.xyz - fP.xyz; \n" + " highp vec3 V = -fP.xyz; \n" - " vec3 N = normalize(fN); \n" + " highp vec3 N = normalize(fN); \n" " L = normalize(L); \n" " V = normalize(V); \n" - " vec3 R = reflect(-L, N); \n" - " vec4 diffuse = abs(dot(N,L)) * light_diff*color; \n" - " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + " highp vec3 R = reflect(-L, N); \n" + " highp vec4 diffuse = abs(dot(N,L)) * light_diff*color; \n" + " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" "gl_FragColor = color*light_amb + diffuse + specular; \n" "} \n" @@ -304,7 +304,7 @@ void Viewer::compile_shaders() "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" - " vec4 TN = transfo*vec4(normal,1.0); \n" + " highp vec4 TN = transfo*vec4(normal,1.0); \n" " fN = mat3(mv_matrix)* TN.xyz; \n" " gl_Position = mvp_matrix * transfo* vertex; \n" "}"