我正在尝试渲染3D体积,原始数据已成功从主内存上传到图形内存,但屏幕上仍然没有任何内容。我的着色器代码可以帮助我找到问题。
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"
"}