2022-05-13-GAMES104现代游戏引擎-Lecture8-Animation System - Basics

Lecture08 Animation System - Basics 挑战: 不能预设玩家的行为,考虑动画与Gameplay的互动,与环境的交互 实时,计算和存储开销 真实感(表情、Ragdoll、Motion Matching …) 2D Animation Sprite Animation 逐帧绘制,循环播放 Sprite-like animation technique in pseudo-3D game 《Doom》 绘制各个视角的sprite,做伪3D Sprite Animation in Modern Game Live2D 把角色/主体的每个元素作为独立图元 eg.眼睛、鼻子、嘴巴 仿射变换 图元的前后遮挡由深度决定 每一个图元有控制网格 Key frame 2D Skinned Animation 2D蒙皮动画 3D Animation DoF, Degrees of Freedom 自由度 6DoF + Translation X Y Z + Rotation Pan/Yaw Tilt/Pitch Roll Rigid Hierarchical Animation 基于刚体的层次结构动画 “皮影戏” 直接连接Mesh,会导致Mesh互相产生穿插 Per-vertex Animation 旗帜、布料、流体等(从物理烘焙而来的顶点动画实现) VAT, Virtual Animation Texture:用贴图存储顶点 Morph Target Animation 顶点动画的变种 顶点带有权重,邻近顶点相互影响 3D Skinned Animation 2D蒙皮动画 (见下章) Physics-based Animation Ragdoll 布料和流体 IK, Inverse kinematics 反向动力学 Animation 创作方式 Key frame 动作捕捉 Skinned Animation Implementation 怎样将Mesh运动起来 创建一个绑定姿态的Mesh 创建绑定骨骼Skeleton 刷定点权重(蒙皮) 骨骼动画 顶点按骨骼动画和蒙皮权重运动 Different Spaces...

2022-05-03-GAMES104现代游戏引擎-Lecture7-Rendering Pipeline, Post-Process and Everything

Lecture07 Rendering Pipeline, Post-Process and Everything Ambient Occlusion 接触阴影,满足渲染方程,但在渲染过程中直接渲染很难做到,因为计算尺度小(称为中尺度)。 AO:单目视觉中形成3D感的重要元素 不考虑尺度差异,AO和BRDF中的Geometry项(Shadowing-Masking)非常相似。 Precomputed AO 使用Ray Tracing预计算成AO贴图。最为传统,但目前在角色等高精度需求中仍应用广泛。 效果好,计算复杂,且无法处理多物体之间的AO。 SSAO, Screen Space AO @GAMES202 SSAO HBAO, Horizon-based Ambient Occlusion 在法线方向半球空间内积分 \[ A=1-\dfrac{1}{2\pi}\int_{\theta=-\pi}^\pi\int_{\alpha=t(\theta)}^h(\theta)W(\vec\omega)\cos\alpha\,\mathrm d\alpha\mathrm d\theta \] 利用深度图做Ray Marching GTAO, Ground Truth - based AO SSAO和HBAO假定了各方向射入的光贡献相同,因此物理上错误。(法线方向照射来的光贡献更多。) \[ \hat A(x)=\dfrac{1}{\pi}\int_0^\pi\int_{\theta_1(\phi)}^{\theta_2(\phi)}\cos(\theta-\gamma)^+|\sin(\theta)|\,\mathrm d\theta\mathrm d\phi\\\gamma={\rm angle}(\vec n, \vec v) \] 根据大量的AO数据,拟合了一个三阶多项式,实现了有颜色的AO Ray-Tracing AO @GAMES202 RTRT Fog Depth Fog 随着深度透明度下降 Linear fog: factor = (end-z) / (end - start) Exp fog: factor = exp(- density * z) Exp Squared fog: factor = exp(- (density * z) ^ 2) Height Fog 设定某一高度阈值,阈值以下恒定Fog强度,阈值以上指数递减...

2022-04-30-GAMES104现代游戏引擎-Lecture6.2-Sky and Atmosphere

Lecture06-2 Sky and Atmosphere Atmosphere 大气 Analytic Atmosphere Appearance Modeling 不必按照物理模拟,根据观察找模型拟合 两个参数 观察向量与垂直向上向量的夹角 \(\theta\) 观察向量与太阳方向的夹角 \(\gamma\) \[ \mathbb{F}(\theta,\gamma)=(1+Ae^{\frac{B}{\cos\theta+0.01}})\cdot(C+De^{E\gamma}+F\cos^2\gamma+G\cdot\chi(H,\gamma)+I\cdot\cos^{\frac{1}{2}}\theta)\\ L_\lambda = \mathbb{F}(\theta,\gamma)\cdot L_{M\lambda} \] 优势:简单快捷,直接代入计算即可 劣势:只能在地表观察,无法完成空中观察视角;参数固定,无法完成各种天气 Participating Media 物理属性 大气中:空气、气溶胶,形成各种折射和反射 光在Participating Media中: Absorption 吸收 \[ \dfrac{\mathrm dL(\mathrm x,\omega)}{\mathrm d\mathrm x}=-\sigma_\alpha\cdot L(\mathrm x,\omega)\\ \sigma_\alpha:\text{Absorption Coeffcient} \] Out-scattering 对外散射 \[ -\sigma_sL(\mathrm x,\omega)\\ \sigma_s:\text{Scattering Coeffcient} \] Emission 自发光(火焰、辉光等) \[ \sigma_\alpha L_e(\mathrm x,\omega) \] In-Scattering 对内散射 接收周围分子的Out-Scattering \[ \sigma_s\int_{S^2}f_p(\mathrm x,\omega,\omega')L(\mathrm x,\omega')\,\mathrm d\omega'\\ f_p(\mathrm x,\omega,\omega'):\text{Phase Function} \]...

2022-04-28-GAMES104现代游戏引擎-Lecture6.1-Terrain Rendering

Lecture06 Rendering of Mother Nature Lecture06-1 Terrain Rendering 地形渲染 Simple Idea - Heightfield Height Map Contour Map 符合分形原则 渲染 均匀网格,依据Heightfield位移每一个顶点 问题:世界过大时过于复杂 解决方法:LoD -> 非均匀网格 -> 保证场景连续,保证LoD过渡均匀 Adaptive Mesh Tessellation 优化原则 依据Distance to Camera和FoV做LoD Error Bound:简化后的误差小于阈值(一般为呈现在屏幕上一个像素大小) Tessellation Triangle-Based Subdivision 在等腰直角三角形的长边切割 -> 得到两个新的等腰直角三角形 二叉树结构,因此又称Binary Triangle-Based Subdivision T-Junctions 解决方法:判断若邻边切分更密,则当前边也需同样进行切分 实际应用中不广泛 QuadTree-Based Subdivision 四叉树分割 优势 易于建构 易于管理几何分区数据,Objects Culling和Data Streaming 符合Texture存储规范 劣势 Mesh细分没有三角形细分灵活 叶子节点的网格层级锁定 符合直觉,应用主流 T-Junctions 与三角形分割类似的问题,细分层级边界处产生 解决方法:Stitching 吸附 吸附生成的三角形:退化三角形 Triangulated Irregular Network (TIN) 几何细节不丰富处,用较粗的三角形 优势 易于Runtime渲染 更少的三角形 劣势 需要预计算 不够通用 特殊的游戏会用 GPU-Based Tessellation DX11开始: Hull-Shader Stage:生成Subdivision用的Patch,告诉Control point数据和Tessellation数量 Tessellator Stage:做Tessellation Domain-Shader Stage:根据高度图移动顶点 Geometry Shader Stage:算Vertex Mesh Shader Pipeline (DX12) GPU-Based Tessellation -> Runtime Tessellation -> Real-Time Deformable Terrain 假定地面上每一个Texel是一个“弹簧”,逐Tick更新高度,并实时Tessellation...

2022-04-17-GAMES104现代游戏引擎-Lecture5-Lighting, Materials and Shaders

Lecture05 Lighting, Materials and Shaders The Rendering Equation \[ {\displaystyle L_{\text{o}}(\mathbf {x} ,\omega _{\text{o}},\lambda ,t)=L_{\text{e}}(\mathbf {x} ,\omega _{\text{o}},\lambda ,t)\ +\int _{\Omega }f_{\text{r}}(\mathbf {x} ,\omega _{\text{i}},\omega _{\text{o}},\lambda ,t)L_{\text{i}}(\mathbf {x} ,\omega _{\text{i}},\lambda ,t)(\omega _{\text{i}}\cdot \mathbf {n} )\operatorname {d} \omega _{\text{i}}} \] 多重挑战: 如何得到入射光 Visibility to Lights, Shadow Light Source Complexity, 尤其面光源 如何快速地积分 如何计算次级光源,全局光照,无限递归 从简单开始 Ambient + Simple Light == Result 环境光贴图反射 相当于Rendering Equation特例化 Blinn-Phong \[ \begin{aligned}L&=L_{\text{ambient}}+L_{\text{diffuse}}+L_{\text{specular}}\\ &=k_{\text{ambient}}I_{\text{ambient}}+k_{\text{diffuse}}(I/r^2)\max(0,\mathbf n\cdot\mathbf l)+k_{\text{specular}}(I/r^2)\max(0,\mathbf n\cdot\mathbf l)^p \end{aligned} \] 问题:...

2022-04-17-GAMES104现代游戏引擎-Lecture4-Rendering in Game Engine

Lecture04 Rendering in Game Engine 挑战 场景极其复杂 实时,帧率稳定 大纲 基础 硬件架构 渲染数据结构 可见性 材质、Shader、光照 PBR Shader Permutation 光照 点/方向光照 IBL / Simple GI 特殊的渲染 地形 天空 / 雾 后处理 Pipeline 前向渲染 Forward、延迟渲染 Deferred、Forward Plus Ring buffer and V-Sync Tiled-based Rendering @GAMES101 Vertex Data -> Triangle Data -> Material Parameters -> Textures 投影 -> 光栅化 eg. Computation - Texture Sampling Step 1 : 使用相邻两层MIPMAP Step 2 : 在两层MIPMAP之间双线性插值 Step 3 : 结果像素之间的线性插值 GPU SIMD and SIMT SIMD : Single Instruction Multiple Data eg....

2022-04-17-GAMES104现代游戏引擎-Lecture2-3-游戏引擎架构

Lecture02 游戏引擎分层结构 工具层 Tool Layer 编辑器 功能层 Function Layer 渲染/模拟/玩法/交互/… 资源层 Resource Layer 数据和文件 核心层 Core Layer 内存管理/资源分配/数学模块 平台层 Platform Layer 硬件设备的调用 PS:中间件/第三方库 情景:制作一个动画角色 Resource 怎么获取数据 Offline Importing resource -> assets 将resource转换为asset的文件格式 asset读取更快 建构所有资产的关联关系(reference) GUID 实时/运行时(Runtime)资产管理器 基于路径加载/卸载asset 通过Handle系统管理asset的生命周期和参考 Function 怎么使世界动起来 tick() tickLogic() tickRender() 有大量系统组成 必定属于引擎功能层的:渲染/模拟等 引擎功能层/游戏Gameplay有时有一定冲突 多线程 固定线程:不同线程作不同功能 主流用法,Job join:将模拟/动画等适合多线程的任务平均分配 原子化/任务系统:转换为一个个Job分配给所有线程 Core 数学库 线性代数 为什么要单独写数学库 - 效率 eg. 卡马克快速平方根(牛顿迭代) SIMD 一条指令完成四个数操作(非常适合齐次坐标运算) 数据结构 vector / map / tree / … 为什么要在STL外单独写 - 效率 STL中经常有浪费内存的操作 内存管理 - 追求最高效率...