简体   繁体   English

远裁剪平面之外的对象在透视图中渲染

[英]Objects beyond the far clipping plane are rendered in perspective view

I see objects beyond the far clipping plane in perspective projection and I don't think this is how it's suppose to work, so can someone give me an explanation why do I see objects beyond the far clipping plane such as a grid in this example.我在透视投影中看到远裁剪平面之外的对象,我认为这不是它应该如何工作的,所以有人可以解释一下为什么我在这个例子中看到远裁剪平面之外的对象,例如网格。

The orthogonal projections works fine btw顺便说一句,正交投影效果很好

I cleared all shapes from this demo and added two grids by changing the following code in Luna Frank Shapes Demo我从这个演示中清除了所有形状,并通过更改Luna Frank Shapes Demo中的以下代码添加了两个网格

void ShapesApp::BuildRenderItems()
{
auto gridRitem = std::make_unique<RenderItem>();
gridRitem->World = MathHelper::Identity4x4();
gridRitem->ObjCBIndex = 0;
gridRitem->Geo = mGeometries["shapeGeo"].get();
gridRitem->PrimitiveType = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
gridRitem->IndexCount = gridRitem->Geo->DrawArgs["grid"].IndexCount;
gridRitem->StartIndexLocation = gridRitem->Geo->DrawArgs["grid"].StartIndexLocation;
gridRitem->BaseVertexLocation = gridRitem->Geo->DrawArgs["grid"].BaseVertexLocation;
mAllRitems.push_back(std::move(gridRitem));

 gridRitem = std::make_unique<RenderItem>();
XMStoreFloat4x4(&gridRitem->World, XMMatrixTranslation(0,-1002,0)* XMMatrixRotationRollPitchYaw(1.5708, 0, 0));;
gridRitem->ObjCBIndex = 1;
gridRitem->Geo = mGeometries["shapeGeo"].get();
gridRitem->PrimitiveType = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
gridRitem->IndexCount = gridRitem->Geo->DrawArgs["grid"].IndexCount;
gridRitem->StartIndexLocation = gridRitem->Geo->DrawArgs["grid"].StartIndexLocation;
gridRitem->BaseVertexLocation = gridRitem->Geo->DrawArgs["grid"].BaseVertexLocation;
mAllRitems.push_back(std::move(gridRitem));

gridRitem = std::make_unique<RenderItem>();
XMStoreFloat4x4(&gridRitem->World, XMMatrixTranslation(0, -1002, 0) * XMMatrixRotationRollPitchYaw(1.5708, 1.5708, 0));
gridRitem->ObjCBIndex = 2;
gridRitem->Geo = mGeometries["shapeGeo"].get();
gridRitem->PrimitiveType = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
gridRitem->IndexCount = gridRitem->Geo->DrawArgs["grid"].IndexCount;
gridRitem->StartIndexLocation = gridRitem->Geo->DrawArgs["grid"].StartIndexLocation;
gridRitem->BaseVertexLocation = gridRitem->Geo->DrawArgs["grid"].BaseVertexLocation;
mAllRitems.push_back(std::move(gridRitem));

and change the grid size并更改网格大小

GeometryGenerator::MeshData grid = geoGen.CreateGrid(200.0f, 200.0f, 60, 40);

and the projection matrix from on resize以及从调整大小开始的投影矩阵

 XMMATRIX P = XMMatrixPerspectiveFovLH(0.25f * MathHelper::Pi, AspectRatio(), .1f, 1000.f);
XMStoreFloat4x4(&mProj, P);

Now I can still see the grid even though its beyond the far plane and even if the far plane is 900 the still appears on rotation at the edge of the screen.现在我仍然可以看到网格,即使它超出了远平面,即使远平面是 900,它仍然会出现在屏幕边缘的旋转中。 so I need to reduce the far plane or move the grid further, and as I keep changing the value of the far plane I can see a shape works as a brush, it hides everything beyond it but as camera rotate and the grid is no longer behind it the grid re-appear所以我需要减少远平面或进一步移动网格,当我不断改变远平面的值时,我可以看到一个形状就像画笔一样,它隐藏了它之外的所有东西,但是随着相机旋转并且网格不再在它的后面,网格重新出现

and here's what I meant by the brush这就是我所说的刷子的意思

远剪裁平面之外的网格

I think you're thinking of the maximum view distance as being consistently 900 units away from the camera/eye position.我认为您将最大视距视为始终远离相机/眼睛 position 900 单位。 If that was the case, it wouldn't be a clipping plane at all, it would be a curve - a sector of a sphere.如果是这样的话,它根本就不是一个剪裁平面,而是一条曲线——球体的一个扇区。

In reality the view frustum is a truncated pyramid made up of 6 planes.实际上,视锥体是由 6 个平面组成的截头金字塔。 When the far plane is set to 900, then the view distance for the pixel in the centre of the view is 900, but the view distance at the corners is much higher (how much higher depends on the FOVs - you could work it out with a bit of trig).当远平面设置为 900 时,视图中心像素的视距为 900,但角落处的视距要高得多(高多少取决于 FOV - 你可以用一点触发)。

So as you turn your camera left and right, an object approx 900 units away from the camera will come in and out of view as it intersects the far plane.因此,当您左右转动相机时,距离相机约 900 个单位的 object 会在与远平面相交时进出视野。

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

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