Reputation: 8704
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.
Is this an application of raycasting or similar?
Upvotes: 8
Views: 712
Reputation: 2278
It seems what you want is occlusion culling, you have two main options to implement occlusion culling
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.
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.
Upvotes: 3
Reputation: 162174
Is this an application of raycasting or similar?
This is in essence the raytracing shadow algorithm: Once you've hit a (visible) surface with your view-ray, you take that point as point of origin for a trace toward the other point (a light source or whatever) and if you can reach that point (without) "bumping" into something else use that information as further input into rendering calculations.
Upvotes: 2