8

I've a `W x H x D' volumetric data that is zero everywhere except for little spherical volumes containing 1.

I have written the shader to extract the "intersection" of that 3D volume with a generic object made of vertices.

Vertex shader

varying vec3 textureCoordinates;
uniform float objectSize;
uniform vec3 objectTranslation;

void main()
{
        vec4 v=gl_Vertex;
        textureCoordinates= vec3(   ((v.xz-objectTranslation.xz)/objectSize+1.0)*0.5,    ((v.y-objectTranslation.y)/objectSize+1.0)*0.5);
        gl_Position = gl_ModelViewProjectionMatrix*v;
}

Fragment shader

varying vec3 textureCoordinates;
uniform sampler3D volumeSampler;
void main()
{
    vec4 uniformColor = vec4(1.0,1.0,0.0,1.0); //it's white
    if ( textureCoordinates.x <=0.0 || textureCoordinates.x >= 1.0 || textureCoordinates.z <= 0.0 || textureCoordinates.z >= 1.0)
        gl_FragColor =vec4(0.0,0.0,0.0,1.0); //Can be uniformColor to color again the thing
    else
        gl_FragColor = uniformColor*texture3D(volumeSampler, textureCoordinates);
}

In the OpenGL program, I'm looking the centered object with those almost-spherical patches of white on it from (0,100,0) eye coordinates, but I want that for another viewer (0,0,0) the spheres that lie on the same line-of-sight are correctly occluded, so that only the parts that I underlined in red in the picture are emitted.

Ideal occlusion for (0,0,0) viewer as view from up

Is this an application of raycasting or similar?

4

2 回答 2

3

看来你想要的是遮挡剔除,你有两个主要的选择来实现遮挡剔除

使用 GPU 遮挡查询

这本质上是关于询问硬件是否会绘制某个片段,如果没有,您可以剔除对象。

遮挡查询计算通过深度测试的片段(或样本)的数量,这对于确定对象的可见性很有用。

这个算法比这里解释的要复杂,这里是一篇关于这个主题的优秀 Nvidia 文章。

使用 CPU 光线投射

这只是检查每个对象(或者可能是包围体),如果光线击中对象,那么它可能会隐藏它后面的其他对象。对象需要使用八叉树或 BSP 树进行空间排序,因此您最终不会检查每个对象,而只检查相机附近的对象。

有关剔除技术的更多信息,请在此处查看我的答案。

于 2013-12-09T12:17:17.823 回答
2

这是光线投射或类似的应用吗?

这本质上是光线跟踪阴影算法:一旦你用你的视野光线击中了一个(可见的)表面,你把那个点作为追踪到另一个点(光源或其他东西)的原点,如果你可以到达那个点(没有)“碰撞”到其他东西中,使用该信息作为渲染计算的进一步输入。

于 2013-10-04T14:53:23.067 回答