简体   繁体   English

3D体积渲染和多视角遮挡

[英]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. 我有一个“ W xH x D”体积数据,除包含1的小球形体积外,其他所有地方均为零。

I have written the shader to extract the "intersection" of that 3D volume with a generic object made of vertices. 我已经编写了着色器,以提取由顶点构成的通用对象的3D体的“相交”。

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. 在OpenGL程序中,我正在从(0,100,0)眼坐标上看带有白色的近似球形补丁的居中对象,但我想让其他查看者(0,0,0)躺在该对象上正确地遮挡了相同的视线,因此只发射了我在图片中用红色下划线表示的部分。

从上方观看(0,0,0)观看者的理想遮挡

Is this an application of raycasting or similar? 这是光线投射还是类似的应用?

It seems what you want is occlusion culling, you have two main options to implement occlusion culling 似乎您想要的是遮挡剔除,您有两个主要的选项可以实施遮挡剔除

Using GPU occlusion queries 使用GPU遮挡查询

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. 该算法比此处可以解释的要复杂,这是有关该主题的Nvidia优秀文章。

Using CPU ray casting 使用CPU射线投射

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. 需要使用八叉树或BSP树在空间上对对象进行排序,因此您不必最终检查每个对象,而只需要检查摄像头附近的对象。

For more on culling techniques check my answer here . 有关淘汰技术的更多信息,请在此处查看我的答案。

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. 从本质上讲,这是光线跟踪阴影算法:用视线照射(可见)表面后,就可以将该点作为起点,向另一点(光源或其他任何点)走线,如果可以达到该点(没有)“碰撞”到其他东西,则将该信息用作渲染计算的进一步输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM