private void addMainFunction(StringBuilder code){
        
        // variables names:
        final String luminance = "luminance";
        final String feature = "feature";
        final String heightColor = "h";
        
        // function code:
        String func = "void main(void){\n";
        
        
                
        if (renderTraces){

            func +=
                // access the seismic texture sampler, as a base color:
                FLOAT_TYPE + " " + luminance + " = float(texture3D(" + TRACES_SAMPLER + ", gl_TexCoord[0].stp));\n"

                // normalize data:
                + luminance + " = ((" + luminance + " - " + MIN_AMPLITUDE + ") /  (" + MAX_AMPLITUDE + " - " + MIN_AMPLITUDE + "));\n"

                ;

        }//if
                
                
        if (renderFeatures){

            func += 
                // access the features texture sampler:
                FLOAT_TYPE + " " + feature + " = float(texture3D(" + FEATURES_SAMPLER + ", gl_TexCoord[1].stp));\n"

                // Height-Based Color
                + FLOAT_TYPE + " " + heightColor + ";\n"

                ;

            // go through the features:
            String loop = "";
            for (int i=0; i < featuresIDs.length; i++){
                
                // get a new color
                float [] c = new float[3];
                c = COLOR_DB[i].getRGBColorComponents(c);
                System.out.println("(" + c[0] + "," + c[1] + "," + c[2] + ")");

                if (i != 0)
                    loop += "else ";

                loop += 
                    "if (" + feature + " == " + FEATURE_NO_ + i + "[0]){\n"
                    + heightColor + " = (gl_TexCoord[1].s - " + FEATURE_NO_ + i + "[1])"
                        + " / ("  + FEATURE_NO_ + i + "[2] - " + FEATURE_NO_ + i + "[1]);\n"
                        
                    + "gl_FragColor = vec4("
                        + PALETTE_REV_FUNC + "(" + heightColor + "), 1.0);\n}\n" //vec4(1.0, 0.0, 0.0, 1.0);
//                        + c[0] + "," + c[1] + "," + c[2] + ",1.0);\n}\n"

                    ;

            }

            // add the loop to the function:
            func += loop;

        }//if
        
        
        if (renderTraces){
            String ifStatement = "";
            
            // add "else" if features to be rendered to continue the loop:
            if (renderFeatures){
                ifStatement += "else ";
            }
            
            ifStatement += "if((1 - gl_TexCoord[0].p) < " + SEISMIC_TEX_DEPTH + "){\n"
                        + "gl_FragColor = vec4(" + luminance + ", " + luminance + ", " + luminance + ", " + ALPHA + ");\n}\n";
            
            // add it to func:
            func += ifStatement;
        }//if
        
        // [20/11/2012] add a clear color in case nothing to be rendered:
        // this is required after the updated on the graphics card in Nov. 2012
        func += "else{\n"
              + "gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n}\n";
        
        
        // end func and add it to the code:
        code.append(func + "}\n");
    
    }//addMainFunction