以下のように、3D テクスチャのアーティファクトをレンダリングする際に問題が発生しました。

この問題の解決策を見つけるためにネットで検索しましたが、ほとんどの回答は深度バッファビットに関する問題を指摘しています。深度バッファ ビットを から に 24 ビットに変更しようとしましたがGL_DEPTH、GL_STENCIL in GLUT結果は同じままで、特定の角度から見たときにテクスチャ (またはジオメトリ-よくわかりません) が非表示になります..
では、この種のアーティファクトをもたらす問題が正確に何であるかを知ることができますか??
以下はフラグメント シェーダーのコード スニペットです (OpenGL 開発クックブック)
void main()
{
//get the 3D texture coordinates for lookup into the volume dataset
vec3 dataPos = vUV;
vec3 geomDir = normalize((vec3(0.556,0.614,0.201)*vUV-vec3(0.278,0.307,0.1005)) - camPos);
vec3 dirStep = geomDir * step_size;
//flag to indicate if the raymarch loop should terminate
bool stop = false;
//for all samples along the ray
for (int i = 0; i < MAX_SAMPLES; i++) {
// advance ray by dirstep
dataPos = dataPos + dirStep;
stop = dot(sign(dataPos-texMin),sign(texMax-dataPos)) < 3.0f;
//if the stopping condition is true we brek out of the ray marching loop
if (stop)
break;
// data fetching from the red channel of volume texture
float sample = texture(volume, dataPos).r;
float prev_alpha = sample - (sample * vFragColor.a);
vFragColor.rgb = (prev_alpha) * vec3(sample) + vFragColor.rgb;
vFragColor.a += prev_alpha;
if( vFragColor.a>0.99)
break;
}
参考までに、以下は頂点シェーダーのスニペットです。
#version 330 core
layout(location = 0) in vec3 vVertex; //object space vertex position
//uniform
uniform mat4 MVP; //combined modelview projection matrix
smooth out vec3 vUV; //3D texture coordinates for texture lookup in the fragment shader
void main()
{
//get the clipspace position
gl_Position = MVP*vec4(vVertex.xyz,1);
//get the 3D texture coordinates by adding (0.5,0.5,0.5) to the object space
//vertex position. Since the unit cube is at origin (min: (-0.5,-0.5,-0.5) and max: (0.5,0.5,0.5))
//adding (0.5,0.5,0.5) to the unit cube object space position gives us values from (0,0,0) to
//(1,1,1)
//vUV = (vVertex + vec3(0.278,0.307,0.1005))/vec3(0.556,0.614,0.201);
vUV = vVertex/vec3(0.556,0.614,0.201);//after moving the cube to coordinates range of 0-1
}
編集済み: 表示が比較的端で行われる場合に特に存在するアーティファクト。
ご参考までに、glm::perspective(45.0f,(float)w/h, 1.0f,10.0f);