Half-Life's In-Game Visibility Determination

简介:
Where would we be without visibility determination? I'm not sure. Actually, yes, I am sure; we'd be stuck at 5 fps on an empty server. And we certainly wouldn't want that.

"So, what is this visibility determination thing, anyway?" you say. Well, it's the process that every single 3D game under the sun (and over it) goes through. It's the process that determines what is visible, and what is not, and therefore whether to spend time sending all the polygonal data to the renderer. There's no point sending a 1,000 triangle object to the renderer if the object is off the screen, and won't be visible anyway, so why waste the time doing it?

This article will talk you through the processes Half-Life goes through every frame to determine what is visible, and what is not. Note that it will not tell you how the VIS process works; there have been hundreds of white papers published on efficient methods of BSP tree leaf visibility determination, and it would take ages to describe how Half-Life does it! I will, however, give a basic overview of what VIS actually does, for the purposes of understanding just what the heck I'm on about later on in this article.

When compiling a map, it is first split up into a Binary Space Partition tree, or BSP tree for short. This is basically a method of splitting the world up into manageable chunks which can then be dealt with individually, and are vital in speeding up collision detection, lighting calculations and doing visibility determination. Essentially, the map is first of all split into two parts (figure 1, stage 1) by placing a 3D plane to split the world in half. One side is called the positive side, or the front side, the other the negative side, or the back side. Then, the process happens again, except this time it is done on each of the two new segments treating each segment like a different map, rather than doing it across the entire map (figure 1, stage 2). This keeps happening until the world is split up enough (determined by the compiler) and you end up with your BSP tree. If you keep a track of what was split up from what, you can create a tree of what encloses what, and so do some major speed-ups (figure 2).

Figure 1

Figure 2

Game programmers will probably lynch me for this woefully inadequate description of a BSP tree, but it will suffice for this article. (If you want to learn more about BSP trees, you can try  the BSP tree FAQ .)

So what does this have to do with visibility determination? Well, when the world has been split into a BSP tree, it's in collections of polygons. Each collection of polygon is called a "BSP leaf", and it's with these that VIS does its work. For each leaf, it generates a list of every other leaf in the world, which simply contains whether that leaf could be seen if you were within the current leaf - this list is called the Potentially Visible Set, or PVS. As you can appreciate, this is a complex process, which is why VIS takes a long time in compilation with complicated maps.

So, after VIS, we've already got some very important visibility determination done, and we're not even into the per-frame loop yet. However, after this, we progress into the heart of the game, and see exactly what it does each frame.

Every frame, the game loops through the BSP leaves to find out which leaf the player is currently standing in. Once it's found it, it uses the PVS to find out what leaves might be seen from where the player currently is, and tosses out the leaves that can't be seen under any circumstance. This is a very crude, but very effective, form of visibility determination. Now that the game is only dealing with the leaves that could be seen from the current viewpoint, it moves onto the second type of visibility determination - frustum culling.

The view frustum is basically the volume in which the player can see. Anything outside of this volume cannot be seen by the player. In 3D, it looks like a pyramid with the top chopped off (with the new surface being the screen, and the base of the pyramid the far clipping plane). However, we don't have 3D monitors, so I'll take the 2D analogy - an isoceles triangle with the top corner chopped off. What the game does is to find out whether, out of the potentially visible leaves, any of them are outside of the view frustum; if they are, they get tossed out too. Figure 3 has an example of this in 2D.

Figure 3 - The black blob is the player. Objects 1 and 4 are within the view frustum and therefore visible, but objects 2 and 3 cannot be seen by the player.

After this simple but effective visibility determination method, there isn't very much left that isn't totally invisible to the player from his/her current position and orientation. However, one more, much finer, process is applied to the triangles making up each visible leaf - backface culling.

In 3D, every triangle has a 'normal' vector - this represents the direction that the triangle is facing. All that backface culling does is simply remove every triangle that is facing away from the viewer, as they probably wouldn't (and shouldn't) be visible anyway. This can sometimes chop the amount of triangles to draw by as much as 50%, which is a dramatic decrease.

After these 3 methods are applied - usage of the PVS, frustum culling, and backface culling - the remaining triangles can be rendered by the graphics API (OpenGL, Direct3D or software) with a minimal amount of polygons being drawn that are not visible. You can see what an effect not being able to do the first stage has when you have a large map with a leak - VIS cannot calculate its PVS, and so it is assumed that ALL leaves are visible before the 2nd and 3rd stages are applied.

This concludes our whizz tour of how Half-Life does visibility determination in-game. Hopefully this may give you some ideas as to how to improve your maps' frame-rate performance, or encourage you to read further about the above methods -  GameDev.net  has some great tutorials should you want to read more. If you have any questions, then feel free to contact me about them.
目录
相关文章
|
6月前
|
供应链 算法 BI
StarRocks 助力首汽约车精细化运营
本文由首汽约车大数据负责人任智红在StarRocks年度峰会上的演讲整理而成,分享了StarRocks在企业内部的应用实践。文章详细介绍了StarRocks如何助力首汽约车实现精细化运营,涵盖运效诊断、供需平衡联动及自助多维分析等核心业务场景。通过引入StarRocks,公司实现了秒级数据处理与查询性能提升,大幅降低了开发和维护成本,推动了数据驱动的业务发展。未来,首汽约车计划进一步整合系统、拓展应用场景,并优化存算分离与资源隔离策略,持续提升数据处理效率与业务稳定性。
|
6月前
|
自然语言处理 搜索推荐 机器人
合力亿捷云客服系统:2025年大模型如何重塑全渠道对话体验
2025年,以DeepSeek等大模型为核心的智能客服系统,突破传统效率瓶颈,通过全渠道整合、多模态交互、个性化服务与情感智能,重构企业客户互动模式。从机械应答到认知共情,从单一文本到多维交互,大模型赋能客服系统成为企业价值创造的战略资产,推动客户服务迈向智能化新纪元。
246 2
|
11月前
|
前端开发 JavaScript 算法
React 运行时的难点和挑战
【10月更文挑战第25天】深入研究React运行时需要开发者具备扎实的JavaScript基础、对React框架的深入理解以及丰富的实践经验。只有克服这些难点和挑战,才能更好地发挥React的优势,构建出高性能、高质量的用户界面和应用程序。
|
数据安全/隐私保护 Windows
支付系统08-----支付宝支付---接入准备----创建应用,如果你有营业执照,网站有备案,就可以进行接入,真实的企业用户在做的时候,也可以用沙箱进行隔离,设置独立环境,隔离线上模式进行调试
支付系统08-----支付宝支付---接入准备----创建应用,如果你有营业执照,网站有备案,就可以进行接入,真实的企业用户在做的时候,也可以用沙箱进行隔离,设置独立环境,隔离线上模式进行调试
|
JavaScript 前端开发 C++
CocosCreator3.8研究笔记(六)CocosCreator 脚本装饰器的理解
CocosCreator3.8研究笔记(六)CocosCreator 脚本装饰器的理解
386 0
|
安全 Java 微服务
一张图告诉你为什么是服务网关
网关服务是单一访问点,并充当多项服务的代理。服务网关启用了跨所有服务的路由转发、过滤和公共处理等。 在微服务实践中远不止这点功能,它可以做到统一接入、流量管控、安全防护、业务隔离等功能。
548 0
一张图告诉你为什么是服务网关
|
弹性计算 大数据 测试技术
2024年企业云服务器价格多少钱,1000-3000元预算阿里云服务器配置说明
2024年企业云服务器价格多少钱?租用阿里云服务器怎么收费?阿里云服务器配置不同一年价格也不同,来看看1000-3000元预算阿里云服务器配置说明。云服务器ECS经济型e实例2核2G、3M固定带宽99元一年、ECS u1实例2核4G、5M固定带宽、80G ESSD Entry盘优惠价格199元一年,轻量应用服务器2核2G3M带宽轻量服务器一年61元、2核4G4M带宽轻量服务器一年165元12个月、2核4G服务器30元3个月,幻兽帕鲁4核16G和8核32G服务器配置,云服务器ECS可以选择经济型e实例、通用算力u1实例、ECS计算型c7、通用型g7、c8i、g8i等企业级实例规格。
|
算法 Dubbo Java
进阶2:JVM 启动参数
Java进阶,突破能力瓶颈,到更好的公司拿更高的薪水
|
存储 运维 NoSQL
REDIS集群
Redis集群是指将多个Redis节点组成一个集群,通过节点间的数据分布和协调来提供高可用性和性能的数据库解决方案。每个节点可以存储数据,处理请求,并与其他节点进行通信,以实现数据的拷贝和复制。
252 0
|
机器学习/深度学习 文字识别 TensorFlow
脚把脚教你利用PAI训练出自己的CNN手写识别模型并部署为可用的服务
虽然已经 9102 年了,MNIST手写数据集也早已经被各路神仙玩出了各种花样,比如其中比较秀的有用MINST训练手写日语字体的。但是目前还是很少有整体的将训练完之后的结果部署为一个可使用的服务的。大多数还是停留在最终Print出一个Accuracy。
3526 57