0

I am trying to render 3D volume,raw data is successfully uploaded from main memory to graphics memory but still there is nothing on screen.here is my shader code can someone help me to locate the issue.

const char vShaderStr[] =
      "#version 300 es                              \n"
      "in vec3 av4position;                         \n"
      "uniform mat4 u_mvpMatrix;                    \n"
      "smooth out vec3 uVU;                         \n"
      "void main()                                  \n"
      "{                                            \n"
      "gl_Position=u_mvpMatrix*vec4(av4position.xyz,1);\n"
      "uVU=av4position+vec3(0.5);                   \n"
      "}                                            \n";

   const char fShaderStr[] =
      "#version 300 es                              \n"
      "precision mediump float;                     \n"
      "layout(location=0) out vec4 vFragColor;      \n"
      "smooth in vec3 uVU;  

                    \n"

  "uniform sampler3D    volume;                 \n"
  "uniform vec3         camPos;                 \n"
  "uniform vec3         step_size;              \n"

  "const int MAX_SAMPLES=300;                   \n"
  "const vec3 texMin=vec3(0);                   \n"
  "const vec3 texMax=vec3(1);                   \n" 

    "void main()                                \n"

  "{                                           \n"
      "vec3 dataPos=uVU;                                    \n"
      "vec3 geomDir=normalize((uVU-vec3(0.5))-camPos);      \n"
      "vec3 dirStep=geomDir*step_size;                      \n"
      "bool stop=false;                                     \n"
      "for(int i=0;i<MAX_SAMPLES;i++)                       \n"
      "{                                                    \n"
          "dataPos=dataPos+dirStep;                                     \n"
          "stop = dot(sign(dataPos-texMin),sign(texMax-dataPos)) < 3.0; \n"
          "if (stop)                                                    \n"
          "break;                                                       \n"
          "float sample = texture(volume, dataPos).r;                   \n"
          "float prev_alpha = sample - (sample * vFragColor.a);         \n"
          "vFragColor.rgb = prev_alpha * vec3(sample) + vFragColor.rgb;\n"
          "vFragColor.a += prev_alpha;                                  \n"
          "if( vFragColor.a>0.99)                                       \n"
          "break;                                                       \n"
      " }                                                               \n"
    //  "vFragColor = vec4(1, 0, 0, 1);                                 \n"
  "}                        
Kirtan
  • 1,782
  • 1
  • 13
  • 35
user3492894
  • 43
  • 1
  • 6
  • What makes you think the problem is in the shaders? Did you get any compiler error/warning in the info logs? – glampert Apr 30 '14 at 04:12
  • because i successfully uploaded the file from main memory to the graphics hardware and also i found no error in my overall code so i thought may be there is something wrong in my shader code. – user3492894 Apr 30 '14 at 05:56
  • @user3492894: You know that shaders don't act upon itself. You still must have some kind of drawing code in your program, so that the shaders actually get to work. – datenwolf Apr 30 '14 at 08:56
  • im a beginner and im stuck with this code there is no error in code but still its not working what should i do? – user3492894 Apr 30 '14 at 09:54

0 Answers0