12 if(numberOfUploadedTextures != 0)
17 "//CX: adding input and output variables for texture coordinates\n" 18 "const int number_of_textures = %4;\n" 19 "in vec3 %2[number_of_textures];\n" 20 "out vec3 %3[number_of_textures];\n" 23 .arg(VS_In_Vec3_TextureCoordinate.c_str())
24 .arg(VS_Out_Vec3_TextureCoordinate.c_str())
25 .arg(numberOfUploadedTextures);
30 temp = vtk_dec.c_str();
33 const std::string retval = temp.toStdString();
42 if(numberOfUploadedTextures != 0)
49 .arg(vtk_impl.c_str())
50 .arg(VS_Out_Vec3_TextureCoordinate.c_str())
51 .arg(VS_In_Vec3_TextureCoordinate.c_str());
56 temp = vtk_impl.c_str();
59 const std::string retval = temp.toStdString();
86 std::string lut_sampler_code;
88 for(
int i=0; i<numberOfUploadedTextures; ++i)
90 std::string j = QString::number(i).toStdString();
91 std::string code =
" if(texture_index == "+j+
")\n" 92 " rgba_lut_values["+j+
"] = texture("+FS_Uniform_1DTexture_LUT+
"["+j+
"], red_value);\n";
93 lut_sampler_code += code;
96 return lut_sampler_code;
99 const std::string
getFS(
int numberOfUploadedTextures)
101 std::string fs_shader_text;
103 if(numberOfUploadedTextures != 0)
105 std::string number_of_textures = QString::number(numberOfUploadedTextures).toStdString();
107 "//VTK::System::Dec\n" 108 "//VTK::Output::Dec\n\n" 110 "in vec3 normalVCVSOutput;" 111 "in vec4 vertexVCVSOutput;" 113 "//CX: adding custom fragment shader\n" 114 "const int number_of_textures = "+number_of_textures+
";\n" 115 "in vec3 "+VS_Out_Vec3_TextureCoordinate+
"[number_of_textures];\n" 116 "uniform sampler3D "+FS_Uniform_3DTexture_Volume+
"[number_of_textures];\n" 117 "uniform sampler1D "+FS_Uniform_1DTexture_LUT+
"[number_of_textures];\n" 118 "uniform float "+FS_Uniform_Window+
"[number_of_textures];\n" 119 "uniform float "+FS_Uniform_Level+
"[number_of_textures];\n" 120 "uniform float "+FS_Uniform_LLR+
"[number_of_textures];\n" 121 "uniform float "+FS_Uniform_Alpha+
"[number_of_textures];\n" 122 "out vec4 "+FS_Out_Vec4_Color+
";\n" 124 "const vec3 bounds_lo = vec3(0.0,0.0,0.0);" 125 "const vec3 bounds_hi = vec3(1.0,1.0,1.0);" 127 "bool textureCoordinateIsOutsideTexture(in int texture_index)\n" 129 " vec3 texture_coordinate = "+VS_Out_Vec3_TextureCoordinate+
"[texture_index];\n" 130 " return any(lessThan(texture_coordinate, bounds_lo)) || any(greaterThan(texture_coordinate, bounds_hi));\n" 133 "float windowLevel(in float x, in float window_, in float level_)\n" 135 " return (x-level_)/window_ + 0.5;\n" 138 "vec4 sampleLut(in int texture_index, in float red_value)\n" 140 " vec4 rgba_lut_values[number_of_textures];\n" 142 " return rgba_lut_values[texture_index];\n" 145 "vec4 mergeTexture_GL_RED(in vec4 base_color,in int texture_index)\n" 147 " //Ignore drawing outside texture\n" 148 " bool outside = textureCoordinateIsOutsideTexture(texture_index);\n" 151 " return base_color;\n" 154 " //Sampling from GL_RED 3D texture \n" 155 " vec4 rgba_texture_value = texture("+FS_Uniform_3DTexture_Volume+
"[texture_index], "+VS_Out_Vec3_TextureCoordinate+
"[texture_index]);\n" 156 " float red_value = rgba_texture_value.r;\n" 158 " float llr = "+FS_Uniform_LLR+
"[texture_index];\n" 159 " if(red_value < llr)\n" 161 " return base_color;\n" 164 " red_value = windowLevel(red_value, "+FS_Uniform_Window+
"[texture_index], "+FS_Uniform_Level+
"[texture_index]);\n" 165 " red_value = clamp(red_value, 0.0, 1.0);\n" 167 " vec4 color_rbga = sampleLut(texture_index, red_value);\n" 168 " color_rbga.a = "+FS_Uniform_Alpha+
"[texture_index];\n" 169 " color_rbga = mix(base_color, color_rbga, "+FS_Uniform_Alpha+
"[texture_index]);\n" 171 " return color_rbga;\n" 174 "vec4 mergeTexture(in vec4 base_color, in int texture_index)\n" 176 " return mergeTexture_GL_RED(base_color, texture_index);\n" 182 " vec4 color = vec4(0.0, 0.0, 0.0, 1.0);\n" 183 " for(int i=0; i<number_of_textures; i++)\n" 185 " color = mergeTexture(color, i);\n" 188 " // if input variable (in VS or FS) does not affect any used results it will be optimized out by some glsl compilers" 189 " // hack to make sure normalMC (used to calculate normalVCVSOutput in VS) is not optimized out\n" 190 " color += vec4(normalVCVSOutput, 0.0);\n " 191 " color -= vec4(normalVCVSOutput, 0.0);\n" 193 " "+FS_Out_Vec4_Color+
" = color;\n" 203 return fs_shader_text;
const std::string getVSReplacement_impl(std::string vtk_impl, int numberOfUploadedTextures)
const std::string getFS(int numberOfUploadedTextures)
const std::string getSampleLutImplementation(int numberOfUploadedTextures)
getSampleLutImplementation generates code which will sample the LUT WITHOUT using a for loop...
const std::string getVSReplacement_dec(std::string vtk_dec, int numberOfUploadedTextures)
Namespace for all CustusX production code.