Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3D Volume rendering and multiple point of view occlusion

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?

like image 692
linello Avatar asked Oct 04 '13 14:10

linello


1 Answers

It seems what you want is occlusion culling, you have two main options to implement occlusion culling

Using GPU occlusion queries

This is essentially about asking the hardware if a certain fragment will be draw or not if not you can cull the object.

Occlusion queries count the number of fragments (or samples) that pass the depth test, which is useful to determine visibility of objects.

This algorithm is more complex than can be explained here, here is an excellent Nvidia article on the topic.

Using CPU ray casting

This is simply check each object (or possibly it's bounding volume), if a ray hits the object then it possibly hides other objects behind it. The objects need to be Spatially sorted using Octree or BSP Tree, so you don't end up checking every object and you only check objects near the camera.

For more on culling techniques check my answer here.

like image 193
concept3d Avatar answered Sep 27 '22 19:09

concept3d