Finishing up opengl 4.1 core profile things, it all works. CURA-3273

This commit is contained in:
Jack Ha 2017-02-02 17:08:20 +01:00
parent 4659d8616e
commit 0889722350
4 changed files with 157 additions and 16 deletions

View file

@ -14,6 +14,7 @@ from UM.View.GL.OpenGL import OpenGL
from cura.Settings.ExtruderManager import ExtruderManager
import os.path
## RenderPass used to display g-code paths.

View file

@ -4,7 +4,6 @@ vertex =
uniform lowp float u_active_extruder;
uniform lowp float u_shade_factor;
uniform highp int u_layer_view_type;
uniform highp int u_only_color_active_extruder;
attribute highp int a_extruder;
attribute highp int a_line_type;
@ -19,10 +18,7 @@ vertex =
{
gl_Position = u_modelViewProjectionMatrix * a_vertex;
v_color = a_color;
if ((u_only_color_active_extruder == 1) && (a_line_type != 8) && (a_line_type != 9)) {
v_color = (a_extruder == u_active_extruder) ? v_color : vec4(0.4, 0.4, 0.4, v_color.a);
}
if ((u_only_color_active_extruder == 0) && (a_line_type != 8) && (a_line_type != 9)) {
if ((a_line_type != 8) && (a_line_type != 9)) {
v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a);
}
@ -30,8 +26,10 @@ vertex =
}
fragment =
varying lowp vec4 v_color;
varying float v_line_type;
in lowp vec4 v_color;
in float v_line_type;
out vec4 frag_color;
uniform int u_show_travel_moves;
uniform int u_show_support;
@ -70,14 +68,86 @@ fragment =
discard;
}
gl_FragColor = v_color;
frag_color = v_color;
}
vertex41core =
#version 410
uniform highp mat4 u_modelViewProjectionMatrix;
uniform lowp float u_active_extruder;
uniform lowp float u_shade_factor;
uniform highp int u_layer_view_type;
in highp int a_extruder;
in highp int a_line_type;
in highp vec4 a_vertex;
in lowp vec4 a_color;
in lowp vec4 a_material_color;
out lowp vec4 v_color;
out float v_line_type;
void main()
{
gl_Position = u_modelViewProjectionMatrix * a_vertex;
v_color = a_color;
if ((a_line_type != 8) && (a_line_type != 9)) {
v_color = (a_extruder == u_active_extruder) ? v_color : vec4(u_shade_factor * v_color.rgb, v_color.a);
}
v_line_type = a_line_type;
}
fragment41core =
#version 410
in lowp vec4 v_color;
in float v_line_type;
out vec4 frag_color;
uniform int u_show_travel_moves;
uniform int u_show_support;
uniform int u_show_adhesion;
uniform int u_show_skin;
uniform int u_show_infill;
void main()
{
if ((u_show_travel_moves == 0) && (v_line_type >= 7.5) && (v_line_type <= 9.5)) { // actually, 8 and 9
// discard movements
discard;
}
// support: 4, 7, 10
if ((u_show_support == 0) && (
((v_line_type >= 3.5) && (v_line_type <= 4.5)) ||
((v_line_type >= 6.5) && (v_line_type <= 7.5)) ||
((v_line_type >= 9.5) && (v_line_type <= 10.5))
)) {
discard;
}
// skin: 1, 2, 3
if ((u_show_skin == 0) && (
(v_line_type >= 0.5) && (v_line_type <= 3.5)
)) {
discard;
}
// adhesion:
if ((u_show_adhesion == 0) && (v_line_type >= 4.5) && (v_line_type <= 5.5)) {
// discard movements
discard;
}
// infill:
if ((u_show_infill == 0) && (v_line_type >= 5.5) && (v_line_type <= 6.5)) {
// discard movements
discard;
}
frag_color = v_color;
}
[defaults]
u_active_extruder = 0.0
u_shade_factor = 0.60
u_layer_view_type = 0
u_only_color_active_extruder = 1
u_extruder_opacity = [1.0, 1.0, 1.0, 1.0]
u_show_travel_moves = 0

View file

@ -1,6 +1,8 @@
[shaders]
vertex41core =
#version 410
uniform highp mat4 u_modelViewProjectionMatrix;
uniform highp mat4 u_modelMatrix;
uniform highp mat4 u_viewProjectionMatrix;
uniform lowp float u_active_extruder;
@ -29,7 +31,6 @@ vertex41core =
out lowp vec4 f_color;
out highp vec3 f_vertex;
out highp vec3 f_normal;
out highp int f_extruder;
void main()
{
@ -37,6 +38,7 @@ vertex41core =
v1_vertex.y -= a_line_dim.y / 2; // half layer down
vec4 world_space_vert = u_modelMatrix * v1_vertex;
//gl_Position = u_modelViewProjectionMatrix * a_vertex; //world_space_vert;
gl_Position = world_space_vert;
// shade the color depending on the extruder index stored in the alpha component of the color
@ -56,10 +58,10 @@ vertex41core =
v_line_type = a_line_type;
v_extruder_opacity = u_extruder_opacity;
// for testing and backwards compatibility without geometry shader
/*f_color = v_color;
// for testing without geometry shader
f_color = v_color;
f_vertex = v_vertex;
f_normal = v_normal;*/
f_normal = v_normal;
}
geometry41core =
@ -86,7 +88,6 @@ geometry41core =
out vec4 f_color;
out vec3 f_normal;
out vec3 f_vertex;
out uint f_extruder;
void main()
{
@ -130,8 +131,6 @@ geometry41core =
size_y = v_line_dim[0].y / 2 + 0.01;
}
f_extruder = v_extruder[0];
g_vertex_delta = gl_in[1].gl_Position - gl_in[0].gl_Position;
g_vertex_normal_horz_head = normalize(vec3(-g_vertex_delta.x, -g_vertex_delta.y, -g_vertex_delta.z));
g_vertex_offset_horz_head = vec4(g_vertex_normal_horz_head * size_x, 0.0);

View file

@ -67,6 +67,77 @@ fragment =
}
}
vertex41core =
#version 410
uniform highp mat4 u_modelViewProjectionMatrix;
in highp vec4 a_vertex;
in highp vec2 a_uvs;
out highp vec2 v_uvs;
void main()
{
gl_Position = u_modelViewProjectionMatrix * a_vertex;
v_uvs = a_uvs;
}
fragment41core =
#version 410
uniform sampler2D u_layer0;
uniform sampler2D u_layer1;
uniform sampler2D u_layer2;
uniform vec2 u_offset[9];
uniform float u_outline_strength;
uniform vec4 u_outline_color;
uniform vec4 u_error_color;
uniform vec4 u_background_color;
const vec3 x_axis = vec3(1.0, 0.0, 0.0);
const vec3 y_axis = vec3(0.0, 1.0, 0.0);
const vec3 z_axis = vec3(0.0, 0.0, 1.0);
in vec2 v_uvs;
out vec4 frag_color;
float kernel[9];
void main()
{
kernel[0] = 0.0; kernel[1] = 1.0; kernel[2] = 0.0;
kernel[3] = 1.0; kernel[4] = -4.0; kernel[5] = 1.0;
kernel[6] = 0.0; kernel[7] = 1.0; kernel[8] = 0.0;
vec4 result = u_background_color;
vec4 layer0 = texture(u_layer0, v_uvs);
result = layer0 * layer0.a + result * (1.0 - layer0.a);
float intersection_count = (texture(u_layer2, v_uvs).r * 255.0) / 5.0;
if(mod(intersection_count, 2.0) == 1.0)
{
result = u_error_color;
}
vec4 sum = vec4(0.0);
for (int i = 0; i < 9; i++)
{
vec4 color = vec4(texture(u_layer1, v_uvs.xy + u_offset[i]).a);
sum += color * (kernel[i] / u_outline_strength);
}
vec4 layer1 = texture(u_layer1, v_uvs);
if((layer1.rgb == x_axis || layer1.rgb == y_axis || layer1.rgb == z_axis))
{
frag_color = result;
}
else
{
frag_color = mix(result, vec4(abs(sum.a)) * u_outline_color, abs(sum.a));
}
}
[defaults]
u_layer0 = 0
u_layer1 = 1