- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在进行视锥体剔除的方式上遇到了一些问题。当前的方法确实解决了剔除问题,但效果确实很奇怪。当我离我的主要父对象太近时,我正在使用场景图来渲染所有内容,对象开始非常快速地闪烁。当我离开时,它就消失了。我尝试了很多东西,但再也没有想法了。你们有什么想法吗?非常感谢任何帮助。
我首先在我的模型周围创建一个由八个点组成的边界框。据我所知,经过大量测试,这些都是正确的。
这是我计算截锥平面点的方法。相机位置是世界空间中的位置,方向是它正在看的方向。此外,每次旋转相机时都会计算 cameraUp 和 cameraRight。
Vector3 pos = Camera.staticPosition;
Vector3 view = Camera.staticOrientation;
Vector3 upVector3 = Camera.cameraUp;
Vector3 rightVector3 = Camera.cameraRight;
float toRadians = (float)Math.PI / 180.0f;
float nearDis = .1f;
float farDistance = 1000f;
float fov = Game.FOV;
float aspectRatio = 1.3f;
//Get with and height of near and far plane
float tanDiv = 2 * (float) Math.Tan(fov*toRadians / 2);
float heightNear = tanDiv * nearDis;
float widthNear = heightNear * aspectRatio;
float heightFar = tanDiv * farDistance;
float widthFar = heightFar * aspectRatio;
// get the centre points of the planes so they can be used to calculate the edge points
Vector3 centreNear = pos + view * nearDis;
Vector3 centreFar = pos + view * farDistance;
// get the halfht values of the width and hegiht to make sure you can get the points
float hNearHalf = heightNear / 2;
float wNearHalf = widthNear / 2;
float hFarHalf = heightFar / 2;
float wFarHalf = widthFar / 2;
Vector3 nearTopLeft = centreNear + (upVector3 * hNearHalf) - (rightVector3 * wNearHalf);
Vector3 nearTopRight = centreNear + (upVector3 * hNearHalf) + (rightVector3 * wNearHalf);
Vector3 nearBottomLeft = centreNear - (upVector3 * hNearHalf) - (rightVector3 * wNearHalf);
Vector3 nearBottomRight = centreNear - (upVector3 * hNearHalf) + (rightVector3 * wNearHalf);
Vector3 farTopLeft = centreFar + (upVector3 * hFarHalf) - (rightVector3 * wFarHalf);
Vector3 farTopRight = centreFar + (upVector3 * hFarHalf) + (rightVector3 * wFarHalf);
Vector3 farBotomLeft = centreFar - (upVector3 * hFarHalf) - (rightVector3 * wFarHalf);
Vector3 farBottomRight = centreFar - (upVector3 * hFarHalf) + (rightVector3 * wFarHalf);
我将平截头体点存储在一个数组中。首先是近平面点,然后是远平面、顶平面、底平面、左平面,最后是右平面。然后我遍历所有六个平面和 boundinbox 的 8 个点,如果该点位于平面的右侧,则增加字典中该键的值。
Vector3[] frustumPoints = new Vector3[18]
{
nearTopLeft, nearTopRight, nearBottomLeft, farTopLeft, farTopRight, farBotomLeft, nearTopLeft, farTopLeft,
nearTopRight, nearBottomLeft, farBotomLeft, nearBottomRight, nearTopLeft, nearBottomLeft, farTopLeft,
nearTopRight, nearBottomRight, farTopRight
};
Dictionary<Vector3, int> count = new Dictionary<Vector3, int>(8);
for (int value = 0; value < 8; value++)
{
count.Add(cubePositions[value], 0);
}
for (int x = 0; x < 18; x += 3)
{
Vector3 normal = NormalPlane(frustumPoints[x], frustumPoints[x + 1], frustumPoints[x + 2]);
for (int y = 0; y < 8; y++)
{
Vector3 pointPlane = frustumPoints[x] - cubePositions[y];
float dot = Vector3.Dot(pointPlane, normal);
if (dot <= 0 && x % 6 == 0)
{
count[cubePositions[y]]++;
}
else if (dot >= 0 && x % 3 == 0)
{
count[cubePositions[y]]++;
}
}
}
这是我获取平面法线的方法
Vector3 NormalPlane(Vector3 pointOne, Vector3 pointTwo, Vector3 pointThree)
{
Vector3 normal;
Vector3 edgeOne = pointTwo - pointOne; // calculate vector from point one to point two
Vector3 edgeTwo = pointThree - pointOne; // calculate vector from point one to point three
normal = Vector3.Normalize(Vector3.Cross(edgeOne, edgeTwo)); // calculate the cross product of the two given vectors. Then normalize it so you have normal of plane
return normal; // return the normal
}
如果对于立方体上的这些点之一,计数为 6,则这些点位于所有平面内,因此平截头体和我绘制对象。如果所有点都不等于 6,则不会绘制对象。
问题是我不知道我在哪里犯了错误所以你们有什么想法吗?
提前致谢
杰罗默
最佳答案
If for one of these points on the cube the count is six, the points is within all planes and thus the frustum and I draw the object. If none of the points is equal to 6 the objects don't get drawn.
你这里的逻辑好像是
但是。这是错误的。即使立方体的所有 8 个顶点都位于平截头体之外,立方体仍然可以与平截头体相交,如这个 2D 草图所示:
*----------*
| |
+-----------------+--+ |
\ | / |
\ |/ |
\ / |
\ /| |
\ / *----------*
\ /
\ /
+----+
因此,您剔除了可能可见的内容。
截头体剔除的通常逻辑是只有当所有顶点都被同一平面拒绝时才剔除该框。 (这会导致一些奇怪的情况,即盒子完全在外面并且没有被剔除,但这些情况不太可能发生,通常也没什么大不了的。)
关于c# - 当前的截锥体剔除效果导致 openTk 中的对象闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44735084/
这是顶点着色器: uniform mat4 projection; uniform mat4 view; uniform mat4 model; void main(void) { gl_Po
我有一个问题,我是需要二次幂 (POT) 纹理并且似乎无法使用 NPOT 的幸运者之一。 通常,这不会让我太烦恼,因为我只会确保我需要使用的任何纹理都是 POT。但是,我在尝试将光标 X 和 Y 位置
我最近在我的游戏中实现了视锥体剔除,并且为了从渲染周期中挤出最后一滴,我还决定实现遮挡剔除。它工作得很好,但是,我很痛苦地发现,如果我不看游戏中的任何东西(如果我向虚空看,远离我的游戏对象),我的显卡
我正在寻找一种用颜色“填充”三维几何体的方法,并且很可能在稍后的某个时间填充纹理。 假设你可以将头撞到混凝土墙上,从逻辑上讲你只会看到黑暗。然而,在 OpenGL 中,当您执行此操作时,由于剔除以及几
警告:总的 OpenGL/TK 新手,请善待。我可能咬得太多了。 规范: 2017 年 Visual Studio 社区 C# .Net 4.6.1(使用 WPF、WindowsFormsHost 控
我正在寻找一种跨平台(Win 和 MacOS)方法来检测 C# 中 OpenGL 应用程序的按键。 以下有效,但仅适用于字母数字字符。 protected override void OnKeyPre
我在 http://viewport3d.com/trackball.htm 上使用教程编程轨迹球。我计算了轴和角度,但因为我只是 OpenTK 和 OpenGL 的初学者,所以我不知道如何将旋转应用
我有两张图片。我必须找到第一张图像中强度大于 0.8 的点。同时,我必须在相同点上找到第二张图像的强度,并且需要使用阈值/ slider 值(范围从 0 到 1)调整相同点上第二张图像上的光线。我做了
有没有人知道如何使用 OpenTK 框架滚动(动画化)2D 文本,或者在哪里可以找到一些好的示例。我需要新闻电视 channel 底部(顶部)滚动代码之类的东西。 谢谢。 最佳答案 有许多可能的文本渲
尝试制作游戏,但纹理从未出现在屏幕上。 只为四边形使用颜色是可行的,但是当我尝试为四边形添加纹理时,它只是显示为黑色方 block 。 基本片段着色器: #version 300 es precisi
有没有办法在另一个线程中使用 OpenTK/OpenGL 绘制到屏幕上?我尝试使用的代码是 GL.Clear(ClearBufferMask.ColorBufferBit); GL.ClearColo
它是 tao 框架中已弃用的 OpenTK.Graphics.Glu 的替代品吗?尤其是对几何渲染的需求。 最佳答案 OpenTK 是 Tao 的演变。而且,老实说,我没有听说过 glut 被贬低了。
我是 opengl 的新手,我正在努力让 stencilbuffer 为一个简单的案例工作;我有两种纹理,一种是位图,另一种是“ mask ”,我试图用它来隐藏位图中的某些部分。 我似乎无法让它工作,
我正在尝试在我的 OpenTK 项目中旋转 2D 对象。 发生的事情是旋转对象之后的对象正在旋转,我不希望它们这样做。 我已经旋转了一个对象后如何重置旋转? protected overr
我正在为 OpenGL 和 C# 使用 OpenTK。 我需要使用模板缓冲区,目前想知道如何设置 StencilBuffer 深度。 我之前知道的是 TaoFramework,它的控件具有可以设置此深
我在进行视锥体剔除的方式上遇到了一些问题。当前的方法确实解决了剔除问题,但效果确实很奇怪。当我离我的主要父对象太近时,我正在使用场景图来渲染所有内容,对象开始非常快速地闪烁。当我离开时,它就消失了。我
我正在使用 OpenTK 和 C#,我在 3D 空间中定义了一个平面,如下所示: GL.Begin(BeginMode.Quads); GL.Color3(Color.Magenta); GL.Ver
我不确定为什么这段代码不是简单地在屏幕上绘制一个三角形(正交)。我正在使用与 OpenGL 1.1 相同的 OpenTK 1.1。 List simpleVertices = new List();
我正在尝试找到一种方法来使窗口始终位于顶部。 (必须是窗口模式)我目前正在使用 OpenTk.NetCore 库在 .net 核心中制作一个窗口。是否可以使用 OpenTk 将此窗口保持在顶部或是否有
我目前正在开发一款使用 OpenTK 进行渲染的游戏; C#、.Net 4.0、OpenGL 2。 在 1280x1024 分辨率下最大化运行(不是全屏,而是占用所有可用的屏幕空间),我看到平均帧率为
我是一名优秀的程序员,十分优秀!