std::string Slice::Shader::fragment_shader_source (const Displayable& object) { std::string source = object.declare_shader_variables () + "uniform sampler3D tex;\n" "in vec3 texcoord;\n" "out vec4 color;\n"; source += "void main() {\n" " if (texcoord.s < 0.0 || texcoord.s > 1.0 ||\n" " texcoord.t < 0.0 || texcoord.t > 1.0 ||\n" " texcoord.p < 0.0 || texcoord.p > 1.0) discard;\n" " color = texture (tex, texcoord.stp);\n" " float amplitude = " + std::string (ColourMap::maps[object.colourmap].amplitude) + ";\n" " if (isnan(amplitude) || isinf(amplitude)) discard;\n"; if (object.use_discard_lower()) source += " if (amplitude < lower) discard;\n"; if (object.use_discard_upper()) source += " if (amplitude > upper) discard;\n"; if (object.use_transparency()) source += " if (amplitude < alpha_offset) discard;\n" " color.a = clamp ((amplitude - alpha_offset) * alpha_scale, 0, alpha);\n"; if (!ColourMap::maps[object.colourmap].special) { source += " amplitude = clamp ("; if (object.scale_inverted()) source += "1.0 -"; source += " scale * (amplitude - offset), 0.0, 1.0);\n "; } source += ColourMap::maps[object.colourmap].glsl_mapping; source += "}\n"; return source; }
std::string AbstractFixel::Shader::geometry_shader_source (const Displayable& fixel) { std::string source = "layout(points) in;\n" "layout(triangle_strip, max_vertices = 4) out;\n" "in vec3 v_dir[];\n" "in vec2 v_fixel_metrics[];\n" "uniform mat4 MVP;\n" "uniform float length_mult;\n" "uniform vec3 colourmap_colour;\n" "uniform float line_thickness;\n"; switch (color_type) { case Direction: break; case CValue: source += "uniform float offset, scale;\n"; break; } if (fixel.use_discard_lower()) source += "uniform float lower;\n"; if (fixel.use_discard_upper()) source += "uniform float upper;\n"; source += "flat out vec3 fColour;\n" "void main() {\n"; if (fixel.use_discard_lower()) source += " if (v_fixel_metrics[0].y < lower) return;\n"; if (fixel.use_discard_upper()) source += " if (v_fixel_metrics[0].y > upper) return;\n"; switch (length_type) { case Unity: source += " vec4 line_offset = length_mult * vec4 (v_dir[0], 0);\n"; break; case Amplitude: source += " vec4 line_offset = length_mult * v_fixel_metrics[0].x * vec4 (v_dir[0], 0);\n"; break; case LValue: source += " vec4 line_offset = length_mult * v_fixel_metrics[0].y * vec4 (v_dir[0], 0);\n"; break; } switch (color_type) { case CValue: if (!ColourMap::maps[colourmap].special) { source += " float amplitude = clamp ("; if (fixel.scale_inverted()) source += "1.0 -"; source += " scale * (v_fixel_metrics[0].y - offset), 0.0, 1.0);\n"; } source += std::string (" vec3 color;\n") + ColourMap::maps[colourmap].glsl_mapping + " fColour = color;\n"; break; case Direction: source += " fColour = normalize (abs (v_dir[0]));\n"; break; default: break; } source += " vec4 start = MVP * (gl_in[0].gl_Position - line_offset);\n" " vec4 end = MVP * (gl_in[0].gl_Position + line_offset);\n" " vec4 line = end - start;\n" " vec4 normal = normalize(vec4(-line.y, line.x, 0.0, 0.0));\n" " vec4 thick_vec = line_thickness * normal;\n" " gl_Position = start - thick_vec;\n" " EmitVertex();\n" " gl_Position = start + thick_vec;\n" " EmitVertex();\n" " gl_Position = end - thick_vec;\n" " EmitVertex();\n" " gl_Position = end + thick_vec;\n" " EmitVertex();\n" " EndPrimitive();\n" "}\n"; return source; }
std::string Fixel::Shader::vertex_shader_source (const Displayable& fixel) { std::string source = "layout (location = 0) in vec3 pos;\n" "layout (location = 1) in vec3 prev;\n" "layout (location = 2) in vec3 next;\n" "layout (location = 3) in float value;\n" "uniform mat4 MVP;\n" "uniform float line_length;\n" "uniform float max_value;\n" "uniform bool scale_line_length_by_value;\n" "flat out float value_out;\n" "out vec3 fragmentColour;\n"; switch (color_type) { case Direction: break; case Colour: source += "uniform vec3 const_colour;\n"; break; case Value: source += "uniform float offset, scale;\n"; break; } source += "void main() {\n" " vec3 centre = pos;\n" " vec3 dir = next;\n" " if ((gl_VertexID % 2) > 0) {\n" " centre = prev;\n" " dir = -pos;\n" " }\n" " value_out = value;\n" " if (scale_line_length_by_value)\n" " gl_Position = MVP * vec4 (centre + line_length * value * dir,1);\n" " else\n" " gl_Position = MVP * vec4 (centre + line_length * dir,1);\n"; switch (color_type) { case Colour: source += " fragmentColour = const_colour;\n"; break; case Value: if (!ColourMap::maps[colourmap].special) { source += " float amplitude = clamp ("; if (fixel.scale_inverted()) source += "1.0 -"; source += " scale * (value_out - offset), 0.0, 1.0);\n"; } source += std::string (" vec3 color;\n") + ColourMap::maps[colourmap].mapping + " fragmentColour = color;\n"; break; case Direction: source += " fragmentColour = normalize (abs (dir));\n"; break; default: break; } source += "}\n"; return source; }