예제 #1
0
 std::string NodeOverlay::Shader::fragment_shader_source (const Displayable& object)
 {
   assert (object.colourmap == 5);
   std::string source = object.declare_shader_variables () +
     "uniform sampler3D tex;\n"
     "in vec3 texcoord;\n"
     "out vec4 color;\n"
     "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"
     "  color.a = color.a * alpha;\n";
   source += "  " + std::string (ColourMap::maps[object.colourmap].glsl_mapping);
   source += "}\n";
   return source;
 }
예제 #2
0
        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;
        }