4

正しい値に達するまで、3Dテクスチャでレイキャスティングを行っています。私は立方体でレイキャスティングを行っていますが、立方体の角はすでにワールド座標にあるため、正しい位置を取得するために頂点にmodelviewmatrixを掛ける必要はありません。

バーテックスシェーダー

world_coordinate_ = gl_Vertex;

フラグメントシェーダー

vec3 direction = (world_coordinate_.xyz - cameraPosition_);
direction = normalize(direction);

for (float k = 0.0; k < steps; k += 1.0) {
....
pos += direction*delta_step;
float thisLum = texture3D(texture3_, pos).r;
if(thisLum > surface_)
...
}

すべてが期待どおりに機能します。私が今欲しいのは、デプスバッファに正しい値をサンプリングすることです。デプスバッファに書き込まれる値は、キューブ座標です。posしかし、私は3Dテクスチャの値を記述したいと思います。

したがって、立方体が10原点から離れて配置され-z、サイズがであるとし10*10*10ます。正しく機能しない私の解決策はこれです:

pos *= 10;
pos.z += 10;
pos.z *= -1;

vec4 depth_vec = gl_ProjectionMatrix * vec4(pos.xyz, 1.0);
float depth = ((depth_vec.z / depth_vec.w) + 1.0) * 0.5; 
gl_FragDepth = depth;
4

2 に答える 2

2

The solution was:

vec4 depth_vec = ViewMatrix * gl_ProjectionMatrix * vec4(pos.xyz, 1.0);
float depth = ((depth_vec.z / depth_vec.w) + 1.0) * 0.5; 
gl_FragDepth = depth;
于 2011-07-08T09:47:53.120 に答える
1

One solution you might try is to draw a cube that is directly on top of the cube you're trying to raytrace. Send the cube's position in the same space as you get from your ray-tracing algorithm, and perform the same transforms to compute your "depth_vec", only do it in the vertex shader.

This way, you can see where your problems are coming from. Once you get this part of the transform to work, then you can back-port this transformation sequence into your raytracer. If that doesn't fix everything, then it would only be because your ray-tracing algorithm isn't outputting positions in the space that you think it is in.

于 2011-06-23T09:42:15.257 に答える