计算对象在 3D 场景中的可见程度以用于游戏逻辑/AI

发布于 2024-07-22 05:19:29 字数 664 浏览 14 评论 0原文

我正在启动一个游戏项目,该项目将允许角色隐藏在黑暗区域。 躲在黑暗的角落应该会让其他角色更难看到你。

我需要的是一种计算角色所在位置的光照条件的方法。

理想的情况是有一个,

double getLightFactor(GameCharacter observer, GameCharacter target)

因为我认为可能存在光线照射的照明条件,以便目标的不同侧面受到不同数量的光线照射。 但我很乐意满足于

double getLightFactor(GameCharacter target)

为特定角色获取光线,无论您从哪里观看,甚至只是

double getLightFactor(int x, int z)

在地形中的特定地图点获取光线。

该方法需要考虑到光照条件在游戏过程中可能会发生变化,但由于它是回合制的,因此可以允许进行一些繁重的计算。 我打算使使用手电筒成为可能,因此也需要考虑它们(但它们可以单独建模和处理)。

我将使用 Ogre3d 来处理我的场景,但我会很乐意接受通用解决方案,甚至其他引擎的解决方案(我选择的引擎不是一成不变的)。

非常欢迎想法、论文或任何相关的东西!

I am starting a game project which will allow characters to hide in dark areas. Hiding in a dark corner should make it harder for other characters to see you.

What I need is a way to calculate how the lighting conditions are where the character is located.

The ideal would be to have a

double getLightFactor(GameCharacter observer, GameCharacter target)

since I suppose there could be lighting conditions where light falls so that different sides of the target is hit by different amounts of lights.
But I would gladly settle for

double getLightFactor(GameCharacter target)

to get the light for a specific character regardless of where you are watching from or even

double getLightFactor(int x, int z)

to just get the light at a specific map point in the terrain.

The method need to take into account that lighting conditions may change during gameplay, but since it is turn based some heavy calculations could be allowed. I intend to make it possible to use flashlights so they need to be taken into account as well (but they could be modeled and handled separately).

I will be using Ogre3d to handle my scene, but I will happily accept generic solutions or even solutions for other engines (my choice of engine is not carved in stone).

Ideas, papers or really anything relevant is very welcome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叹倦 2024-07-29 05:19:29

您可以考虑当前的灯光设置,从观察者的角度将场景渲染到屏幕外缓冲区(即使在相当低的分辨率下)。 然后您可以计算目标字符中间周围的平均亮度值。

我不了解 Ogre3d 引擎,但这应该是处理问题的一种相当通用的方法(毕竟它只是从不同的角度渲染场景......)

You could just render the scene from the viewpoint of the observer to an offscreen buffer (even in a rather low resolution) taking into account the current light settings. Then you could calculate a mean luminosity value around the middle of the target character.

I do not know about the Ogre3d engine, but this should be a rather generic way to handle your problem (it's just rendering the scene from a different viewpoint after all...)

夏尔 2024-07-29 05:19:29

好家伙。 这在很大程度上取决于发动机。 我现在可以告诉你,你想要第二种选择。

照明是如何工作的? 是动态的还是静态的? 让我们假设它是两者的组合。

对于静态照明,请检查附近的光照贴图。 它要么是基于顶点的,要么是纹理的,无论哪种方式,您都可以在附近的几个点对其进行采样并对其进行平均。 查看引擎如何计算模型的照明,深入研究图形代码并查看数据实际来自哪里,您可以使用相同的源。 有些游戏具有体积光照信息,Quake 2 在 BSP 树中以每叶为基础执行此操作(易于检查),而 Quake 3 具有体积纹理(也易于检查)。

然后您需要添加动态灯光。 实现此目的的一种方法是从玩家发出光线(当然可能是来自玩家不同部分的一些不同光线)向光源发射光线。 计算有多少个被击中,并根据光的距离为每个击中的数字添加一点。 所有像样的游戏引擎都有一个“发射射线并看看它击中什么”的程序,这就是人工智能如何进行视线以及如何计算出子弹击中了什么以及当你撞到墙上时会发生什么。 不要将太多光线射得太远,因为它可能会很慢。

您不必太频繁地重新计算该值,您可以在创建新光源时执行一次,然后每隔一秒左右执行一次。

Oh boy. This depends a lot on the engine. I can tell you now that you want the second option.

How does lighting work? Is it dynamic or static? Let's assume it's a combination of both.

For static lighting, check the lightmap nearby. It's either vertex based or a texture, either way, you can sample it at a few points nearby and average them. Look at how the engine computes the lighting for models, dig into the graphics code and see where the data actually comes from, you can use the same source. Some games have volumetric lighting information, Quake 2 does this on a per-leaf basis in the BSP tree (easy to check) and Quake 3 has volumetric textures (also easy to check).

Then you'll need to add the dynamic lights. One way you can do this is by shooting rays from the player (probably a few different rays to be sure, from different parts of the player) towards the light source. Count how many are hit and add a little bit to your number for each one, depending on how far the light is. All decent game engines have a procedure for "shoot ray and see what it hits", it's how AIs do line of sight and how you figure out what bullets hit and what happens when you run into the wall. Don't shoot too many rays too far because it could be slow.

You wouldn't have to recompute this value too often, you could do it whenever a new light source is created and then every second or so.

梦中楼上月下 2024-07-29 05:19:29

根据环境的复杂性,您可以作弊并使用覆盖在地形上的 2D 光照贴图。 每个单元格都会有一个基于附近光源的光强度值。 即使对于移动物体,计算也很快,并且可以快速访问以确定位置的“黑暗度”。

您可能需要根据您拥有的灯光类型,使用简单的方框或圆形算法在其上“标记”形状。

Depending the complexity of the environment, you could cheat and use a 2D lightmap overlayed on the terrain. Each cell would have a light intensity value based on the nearby light sources. It would be fast to calculate even for moving objects, and fast to access to determine the "darkness" of a location.

You may have to "stamp" shapes onto it using simple box or circle algorithms depending on the type of lights you have.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文