XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFE.SpaceEngineers.AgentBridge

【SpaceEngineer】AI调试插件

公开
关注 0 Fork 0 Star 0
返回提交历史

SpaceEngineersModDev/XFE.SpaceEngineers.AgentBridge

Fix view-dependent reflection ghosts and stale glass illumination

f0ceaa7
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

7 个文件 +1013 -51
Modified docs/RAYTRACING.md +6 -4
@@ -8,15 +8,15 @@
8 8
9 9 - 刚性舰体、功能方块及子部件的局部反射、环境遮蔽、太阳接触阴影;GGX 金属/粗糙度反射,最多八次路径反弹。近场路径模式每帧 1–8 个样本,首表面使用 G-buffer 法线/光滑度和真实几何材质,采用直接光采样、BSDF 采样和俄罗斯轮盘终止;覆盖校验失败保留原版,不用黑色填补未知几何。
10 10 - 路径模式直接读取原生 G-buffer 的基色、金属度、光滑度和发光量;粗糙度按 `1 - gloss` 转换,只在 GGX 内平方一次。采用可见法线 GGX 采样,环境光与 BSDF 使用多重重要性采样。引擎实时 `FarCubemapOriginal` 在 GPU 上转换为 256×128 HDR 经纬图,每帧按亮度与立体角生成分布,不回读 CPU。未命中的路径读取实际环境辐射;环境源不可用时保留原生光照,不能用黑色代替。此环境是有界引擎探针,不是无限远全场景几何。
11 - `MESH` 材质的自发光贴图参与次级光路;扩展贴图按线性数据读取,缺失时使用无发光回退。第一人称驾驶舱采集实际内部模型,LCD 从引擎当前纹理直接在 GPU 上复制到共享纹理,屏幕内容、颜色、发光强度及可见性用于玻璃和其他表面的反射。最多 32 块屏幕、64 米范围、10 Hz 更新;当前驾驶舱优先。单块纹理不超过 2048×2048,总共享纹理预算 128 MiB。屏幕空间 HUD 不进入几何反射。
11 - `MESH` 材质的自发光贴图参与次级光路;扩展贴图按线性数据读取,缺失时使用无发光回退。第一人称驾驶舱采集实际内部模型,LCD 从引擎当前纹理直接在 GPU 上复制到共享纹理,屏幕内容、颜色、发光强度及可见性用于玻璃和其他表面的反射。最多 32 块屏幕、64 米范围;绑定与元数据约 10 Hz 刷新,已绑定纹理的像素每个渲染帧复制;当前驾驶舱优先。单块纹理不超过 2048×2048,总共享纹理预算 128 MiB。屏幕空间 HUD 不进入几何反射。
12 12 - 实际 `GLASS` 材质进入加速结构,窗框仍按不透明材质处理,不再根据模型文件名把整扇窗跳过。按顺序追踪玻璃层,计算菲涅耳反射、透射颜色和斜入射吸收;阴影能穿过玻璃。次级路径使用薄平行板折射,主视图通过折射后的真实命中位置、深度校验及原生 HDR 取样实现近场折射偏移。原有玻璃污渍和背景着色保留,不重复乘透射颜色。
13 13 - 相机周围 320 米内的小行星/星球体素等值面参与射线。使用本机引擎的线程独立等值面生成器和 storage pin,默认 LOD 0(1 米体素采样),后台最多四个生成任务,按距离顺序发布结果。材质取实际体素索引,以三个方向投影贴图并混合顶点材质。分块有边界采样及唯一三角形归属;体素内容/材质事件会作废旧快照并重新生成,未改写任何体素。主射线最远 256 米;不再用光栅深度加 10 厘米截断体素查询。接近光栅表面的体素命中提供次级射线起点和几何法线,避免独立 LOD 深度失配;前景遮挡的玻璃仍被拒绝。
14 14 - 最多 64 个附近灯具的点光源/聚光灯进入次级命中着色。复制实际位置、方向、颜色、开关、强度及范围,再以贡献权重做一次 RIS 重要性重采样,每个命中只对选中的灯计算遮挡。这是初始采样储备,不含 ReSTIR 的时空储备复用。
15 15 - 不透明表面记录辐射的一、二阶矩,按方差指导三轮 à-trous 空间过滤;半分辨率模式再做双边上采样,原生模式直接使用对应像素。路径模式先分离首表面材质因子和发光量,过滤后恢复,减少纹理被抹平;确定性的首表面太阳直射光独立计算,不经过随机光照的模糊过滤,保留法线贴图和硬阴影细节。重投影使用相机矩阵及匹配实例的上一变换/三角形重心点;四个历史邻点分别经过平面距离、位置、法线、光滑度和材质校验,阈值考虑 FP16 位置量化。长渲染帧或截图不再仅因超过 250 ms 就清空历史,场景重建/大幅切镜等仍明确重置。新像素用局部统计补充方差;空间滤波结果不反馈进历史。玻璃另有虚像命中历史与薄板模型。这是有限去噪实现,刚性变换来自约 10 Hz 快照,不是完整逐帧运动矢量或 NRD。
16 16
17 路径模式的随机光照现另有当前帧邻域约束:几何历史有效但阴影/间接光已改变时,限制旧辐射并缩短积累。追踪和历史处理通过独立计算调度及 UAV 屏障分开,邻域读取不会与历史写入竞争。原生射线分辨率不再重复执行 25 点双边上采样,半分辨率仍保留该步骤。
17 路径模式和混合模式的随机光照均有当前帧同表面邻域约束:几何历史有效但阴影/间接光已改变时,限制旧辐射,明显不一致时首帧弃用旧值。光滑表面的历史长度还由观察方向变化与粗糙度决定,避免相机平移时把已经移走的高光留在接收面上;粗糙表面仍可积累降噪。追踪和历史处理通过独立计算调度及 UAV 屏障分开,邻域读取不会与历史写入竞争。原生射线分辨率不再重复执行 25 点双边上采样,半分辨率仍保留该步骤。
18 18
19 清玻璃反射中的自发光纹理和确定性太阳直射光使用当前帧独立缓冲,不参加时间积累及空间模糊;随机次级照明单独过滤。历史跟踪反射命中的虚像位置,并使用玻璃和命中物体的上一刚性变换校验,替代仅跟踪玻璃面深度的旧方法。历史混合上限缩短为约 8 帧;虚像位置也约束空间过滤,减少跨反射表面混色。粗糙/多层玻璃仍有近似,不能保证所有反射无噪声或拖尾。
19 清玻璃反射中的自发光纹理和确定性太阳直射光使用当前帧独立缓冲,不参加时间积累及空间模糊;随机次级照明单独过滤。历史跟踪反射命中的虚像位置,并使用玻璃和命中物体的上一刚性变换校验,替代仅跟踪玻璃面深度的旧方法。历史混合上限约 8 帧;另以不可变的当前帧随机反射缓冲、5×5 几何匹配邻域及颜色统计校验旧光照,灯光或反射内容明显变化时立即拒绝旧值。虚像位置也约束空间过滤,减少跨反射表面混色。新增原生 4K RGBA16F 缓冲占用约 63.3 MiB。粗糙/多层玻璃仍有近似。
20 20
21 21 透明材质优先按实际 MWM 材质名称解析,再尝试旧 `GlassCCW`/`GlassCW` 字段。当前战斗机驾驶舱的两个旧字段均为空,忽略名称会错误使用粗糙度回退并让本应清晰的玻璃反射随机抖动。`inspect.glassMaterials` 可核查实际名称、粗糙度、IOR 和假定厚度;清玻璃不再随机扰动首反射方向,粗糙玻璃仍采样。
22 22
@@ -72,7 +72,7 @@ DX11/DX12 同适配器共享纹理,以 GPU fence 同步,临时隔离并恢
72 72
73 73 `graphics.rayTracing.status` 返回实际 DXR 层级、几何/纹理/玻璃/体素/灯具数量、缓存年龄和错误。`render.environmentProbe` 表示实际环境源是否绑定,`render.lightingStage` 表示执行阶段。`render.gpuTraceDenoiseMs` 由 D3D12 timestamp query 测量上一帧环境分布生成、射线、历史复制和去噪,**不包含**几何构建、DX11 pack/合成及整个游戏 GPU 开销;`cpuSubmitMs` 还可能包含同步等待,不能冒充 GPU 时间。
74 74
75 `screens` 区分成功复制的纹理、不可用纹理与隐藏屏幕,逐项列出材质、渲染对象和源纹理名称。`graphics.rayTracing.inspect` 的 `interiorCockpit` 可核对当前第一人称内部模型及屏幕网格。超出屏幕数量/纹理预算时保留原材质回退,不宣称已覆盖全部 LCD。
75 `screens` 区分成功复制的纹理、不可用纹理与隐藏屏幕,逐项列出材质、渲染对象和源纹理名称。`refreshHz:10` 表示绑定发现/元数据更新;`textureRefresh:"per-render-frame"` 表示原生端每帧读取已绑定纹理的新像素,即使引擎在原 SRV 上就地更新内容也不会等下一次发现。`graphics.rayTracing.inspect` 的 `interiorCockpit` 可核对当前第一人称内部模型及屏幕网格。超出屏幕数量/纹理预算时保留原材质回退,不宣称已覆盖全部 LCD。
76 76
77 77 `graphics.rayTracing.inspect` 可按 `model` 子串查看最多 32 个玻璃放置对象、实际三角形表面中心/法线,以及最近 64 个体素根实体的范围。它是读接口,信息取自当前快照,场景未准备好时可能为空。`debug.camera` 可在授权副本中设置并恢复固定观察镜头,便于同场景对照,不移动舰船或角色,详见 [API](API.md)。
78 78
@@ -111,3 +111,5 @@ GPU 回读测试覆盖不透明遮挡、天空/远景保留、纹理和 GGX
111 111 不透明光照阶段接入、HDR 环境、稳定实例历史、运动去噪及寰宇号原生 4K 实测见 [运动修复记录](path-tracing-motion-2026-11-17.md)。实例范围筛选造成序号变化时,按稳定标识匹配上一变换,只有新实例拒绝历史,不清空其他表面。
112 112
113 113 玻璃虚像历史、清玻璃材质绑定、反射文字、原生分辨率合成及渲染 CPU 等待修复见 [后续画质与 CPU 实测](glass-history-cpu-2026-11-17.md)。
114
115 镜面横移的旧高光、玻璃光照突变及同一 LCD 纹理内容滞留的复现、修复和持续运动验收见 [残影修复实测](reflection-ghosting-2026-11-18.md)。
Added docs/reflection-ghosting-2026-11-18.md +59 -0
@@ -0,0 +1,59 @@
1 # 反射残影修复与原生 4K 复测(2026-11-18)
2
3 修复三个已在真实 DXR GPU 回读中复现的错误:镜面相机平移后滞留旧亮斑、玻璃光照变化后混入旧颜色,以及 LCD 在原纹理中更新时反射仍显示旧像素。新版本已经安装到游戏,使用存档副本进行寰宇号和驾驶舱运动检查;没有降低分辨率、关闭反射或用全局清空历史掩盖问题。
4
5 ## 根因及修改
6
7 - 接收面的几何历史有效,不代表镜面反射仍有效。旧路径模式允许最多 32 帧积累,邻域约束后仍给失配历史约 4 帧权重。现在结合观察方向的角变化和表面粗糙度缩短光滑反射历史;明显的辐射变化直接使用当前帧。混合模式也加入独立历史处理及当前帧邻域约束。
8 - 玻璃的虚像位置校验只能发现几何变化,不能发现同一物体的照明变色。新增不可变的当前帧随机反射缓冲,在追踪完成及 UAV 屏障后,使用 5×5 几何匹配邻域的范围和方差检验历史。显著变化首帧拒绝旧值;稳定照明继续积累。LCD/自发光及确定性太阳光仍走当前帧清晰分量,不参加此模糊。
9 - LCD 内容经常在同一 SRV 内更新。旧原生代码只有在约 10 Hz 的绑定发现将纹理标为 dirty 时才复制;现在每个渲染帧复制已绑定纹理的当前像素。绑定、可见性、颜色等元数据发现仍约 10 Hz,新增 `screens.textureRefresh` 区分两者。复制留在 GPU 队列,没有新增 CPU 图像回读。
10
11 玻璃新增一个 RGBA16F 缓冲,在 3840×2160 下约 63.3 MiB。追踪与历史处理分开调度,避免跨线程读写同一当前帧邻域。已有 DX11/DX12 fence、资源复用等待和状态恢复保留。
12
13 思路参考 [NVIDIA NRD 的镜面虚像运动和历史置信度说明](https://github.com/NVIDIA-RTX/NRD/blob/master/README.md):几何运动与高光运动需要区分,照明变化需要快速响应。这里是项目自己的有限实现,没有接入 NRD、DLSS Ray Reconstruction 或《赛博朋克 2077》的私有代码。
14
15 ## 先复现,再回归
16
17 测试直接在 RTX 5090 上运行 DXR、跨 API 合成并回读像素。旧代码使用相同断言复现失败,再运行修复后的代码;没有放宽断言阈值。
18
19 | 用例 | 旧代码 | 修复后 |
20 | --- | ---: | ---: |
21 | 光滑镜面相机横移,第一帧暗区旧亮斑最大超额,路径模式 | 0.051381 | 0.001328 |
22 | 同一横移用例,混合模式 | 未单独记录旧值 | 0 |
23 | 玻璃灯从红色变绿色,第一帧旧红色超额 | 0.008107 | 0 |
24 | 同一 LCD SRV 蓝色改红色,第一帧红/蓝通道 | 0/0.042572 | 0.042572/0 |
25 | 静止随机玻璃反射标准差,去噪前 → 后 | 0.003050 → 0.000497 | 0.003050 → 0.000499 |
26
27 数值是测试场景的线性颜色,不是显示器像素误差或整幅游戏画质评分。镜面用例修复后残留超额约为该用例亮斑信号的 0.26%,低于固定 0.015 阈值;不是所有像素误差严格为零。两像素 LCD 条纹、运动/反向、体素遮挡、透明状态恢复等既有 GPU 回归继续通过。生产插件 Release 构建通过。
28
29 ## 实机画面及环境
30
31 Space Engineers 1.211.017、Ryzen 9 9950X3D、RTX 5090。正式测试使用 `XFE Performance Huanyu 20261116`,动态寰宇号实体 `119633262453238412`、33,566 方块;原存档没有覆盖。部署前已创建完整离线备份 `20261118T011123979-e2078ba8df86422c90108de7f6e857a9`。
32
33 后缓冲、视口、渲染及射线缓冲均为 3840×2160,DRS 关闭,HIGH/FXAA、路径模式 2 样本/4 次反弹。实际加载原生模块 SHA-256 为 `E9D9391BA3C8AFA52B6800A6DBF3A904DA45F4287EB3796D14EFF5E62E6A4FAE`。进程 183080,已绑定的 17 张舱内纹理报告每帧复制。
34
35 先进行两组 33 次机位更新、各 17 张运动采样及同机位开关对照,再补连续驱动相机:
36
37 - 寰宇号:模拟保持运行,横移范围 16 米,视角 ±16° 往返;约 38.63 秒、699 次相机更新、17 张采样。
38 - 驾驶舱:世界暂停但相机和渲染继续,视角 ±12° 往返;约 36.95 秒、575 次相机更新、17 张采样。用于玻璃的隔离检查,不能冒充正常游玩 FPS。
39
40 相机驱动与截图等待使用独立连接,截图期间继续更新机位。检查完整画面的原比例分块、反向附近的原比例连续区域及开关差异,所采样的舰体轮廓和反射未见明显旧亮斑拖尾或突然整片变黑;玻璃的蓝色仪表图案及文字随视角变化,未见滞留的第二套文字。关闭对照确认这些是实际新增玻璃反射。记录来自游戏自身截图,未作锐化、降噪或生成式处理;WebP 仅无损转存以便查看。
41
42 暗部和反射边框仍有颗粒,斜视小字清晰度受薄板模型、纹理取样及有限样本约束,本轮不把它们写成全部消除。运动证据是采样序列,不是逐渲染帧录像,不能证明任意场景都零伪影。相机只改变观察视角,未移动角色或舰体;舱内为可恢复调试镜头,不冒充原生第一人称控制器。LCD 首帧内容变化与灯光变色有 GPU 回归,游戏序列没有主动改写用户 LCD 文本。
43
44 ## 帧率与收尾
45
46 相同画质和相对寰宇号机位,场景准备完成后各独立采样 60 秒;模拟保持运行,计时期间不抓图、不运行 GPU 回归或阶段探针。
47
48 | 版本 | 平均 FPS | 1% low | P95 帧时间 | 最差帧 |
49 | --- | ---: | ---: | ---: | ---: |
50 | 修改前 | 24.93 | 17.82 | 47.71 ms | 65.07 ms |
51 | 修复后 | 24.72 | 18.56 | 47.81 ms | 60.38 ms |
52
53 两轮均无采样丢失,也没有超过各自 `max(50 ms, 2×P50)` 阈值(约 79 ms)的长帧。平均 FPS 约下降 0.87%,没有明显提升;最差帧较短也不能据此宣称所有卡顿消失。前后跨过重启,原进程已长时间运行,NPC/其他网格和舰体姿态仍在变化,因此不是严格确定性重放。新增玻璃检验及每帧屏幕复制有成本:光追通道 timestamp 采样均值为 16.49 → 20.20 ms,范围不含 DX11 pack/合成及几何构建,不能当作总 GPU 帧时间或精确的代码成本差。
54
55 修复后的模拟更新约 24.02 Hz,模拟速度约 0.410,大型舰船 CPU 瓶颈仍存在。保持现有自动渲染工作线程、8 个 Havok 工作线程,实体批次实验关闭。Windows GPU Engine 记录中未见《三角洲行动》;其他桌面/播放器仍有少量 GPU 使用。
56
57 两轮测量前后均为 33,566 个方块,检查到的当前完整度均为 216,536,724.888,未新增损坏。结束时已恢复原 `MyCockpit` 相机、取消暂停,保留 4K 路径模式;原生模块 active、`failure:null`、`hresult:0`。实际加载的插件及原生 DLL 哈希均已记录,不以编译成功代替部署验证。
58
59 原始测量、部署、备份、逐项视觉检查及图像哈希见 [机器可读证据](evidence/reflection-ghosting-2026-11-18.json)。本轮只修改渲染历史及屏幕更新,没有改脚本、物理、子网格或 CPU 调度策略;不把残影修复宣称为大型舰船 CPU 瓶颈已经解决。
Modified src/XFE.SeAgent.Plugin/Graphics/RayTracing.Screens.cs +1 -1
@@ -139,7 +139,7 @@ namespace XFE.SeAgent.Plugin.Graphics
139 139 }
140 140 int code=RtSurfaceMaterials(native,surfaceUpload,(uint)surfaceUpload.Length);
141 141 if(code<0)throw new InvalidOperationException("Screen material upload: 0x"+code.ToString("X8"));
142 screenStatus=new JObject {["liveTextures"]=copied,["unavailableTextures"]=missing,["hiddenScreens"]=hidden,["refreshHz"]=10,["limit"]=32,["captureRadiusMeters"]=64,["bindings"]=details};
142 screenStatus=new JObject {["liveTextures"]=copied,["unavailableTextures"]=missing,["hiddenScreens"]=hidden,["refreshHz"]=10,["textureRefresh"]="per-render-frame",["limit"]=32,["captureRadiusMeters"]=64,["bindings"]=details};
143 143 }
144 144 }
145 145 }
Modified src/XFE.SeRayTracing.Native/Native.cpp +20 -17
@@ -45,7 +45,7 @@ struct SharedTexture {
45 45 ComPtr<ID3D11ShaderResourceView> srv;
46 46 ComPtr<ID3D11UnorderedAccessView> uav;
47 47 };
48 struct DynamicTexture { SharedTexture shared; ComPtr<ID3D11ShaderResourceView> source; UINT width=0,height=0; bool dirty=false; };
48 struct DynamicTexture { SharedTexture shared; ComPtr<ID3D11ShaderResourceView> source; UINT width=0,height=0; };
49 49 class Context {
50 50 public:
51 51 std::mutex mutex;
@@ -73,7 +73,7 @@ public:
73 73 ComPtr<ID3D12DescriptorHeap> descriptors;
74 74 ComPtr<ID3D12Resource> tlas, scratch, instances, constants;
75 75 SharedTexture positions, normals, result, reflection, indirect,glassReflection,glassData,filtered,glassRefraction,moments,filteredReflection;
76 SharedTexture environmentMap,surfaceGuide,glassSharp,glassGuide;
76 SharedTexture environmentMap,surfaceGuide,glassSharp,glassGuide,glassRaw;
77 77 ComPtr<ID3D12Resource> environmentCdf;
78 78 ComPtr<ID3D12Resource> glassBuffer,lightBuffer;
79 79 ComPtr<ID3D12Resource> surfaceBuffer;
@@ -162,7 +162,7 @@ public:
162 162 ranges[3].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; ranges[3].NumDescriptors = 4; ranges[3].BaseShaderRegister=6;
163 163 ranges[4].RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; ranges[4].NumDescriptors = 3; ranges[4].BaseShaderRegister=1036;
164 164 ranges[5].RangeType=D3D12_DESCRIPTOR_RANGE_TYPE_SRV;ranges[5].NumDescriptors=4;ranges[5].BaseShaderRegister=1040;
165 ranges[6].RangeType=D3D12_DESCRIPTOR_RANGE_TYPE_UAV;ranges[6].NumDescriptors=2;ranges[6].BaseShaderRegister=10;
165 ranges[6].RangeType=D3D12_DESCRIPTOR_RANGE_TYPE_UAV;ranges[6].NumDescriptors=3;ranges[6].BaseShaderRegister=10;
166 166 D3D12_ROOT_PARAMETER parameters[17]{};
167 167 parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
168 168 parameters[1].ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
@@ -186,7 +186,7 @@ public:
186 186 D3D12_COMPUTE_PIPELINE_STATE_DESC ps{}; ps.pRootSignature = root.Get(); ps.CS = { RaysBytes, sizeof(RaysBytes) };
187 187 Check(device->CreateComputePipelineState(&ps, IID_PPV_ARGS(&pipeline)), "DXR inline ray query pipeline");
188 188 ps.CS={DenoiseBytes,sizeof(DenoiseBytes)}; Check(device->CreateComputePipelineState(&ps,IID_PPV_ARGS(&denoisePipeline)),"Edge-aware atrous denoiser");
189 D3D12_DESCRIPTOR_HEAP_DESC heap{}; heap.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; heap.NumDescriptors = 1048; heap.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
189 D3D12_DESCRIPTOR_HEAP_DESC heap{}; heap.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; heap.NumDescriptors = 1049; heap.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
190 190 Check(device->CreateDescriptorHeap(&heap, IID_PPV_ARGS(&descriptors)), "Descriptors");
191 191 constants = Buffer(Align(sizeof(RtParameters)), D3D12_HEAP_TYPE_UPLOAD, D3D12_RESOURCE_STATE_GENERIC_READ);
192 192 glassBuffer=Buffer(1024*sizeof(RtGlassMaterial),D3D12_HEAP_TYPE_UPLOAD,D3D12_RESOURCE_STATE_GENERIC_READ);
@@ -248,6 +248,7 @@ public:
248 248 positions = Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
249 249 surfaceGuide=Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
250 250 glassSharp=Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);glassGuide=Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
251 glassRaw=Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
251 252 normals = Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
252 253 result = Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
253 254 reflection = Texture(DXGI_FORMAT_R16G16B16A16_FLOAT);
@@ -287,7 +288,8 @@ public:
287 288 historyTextures[8].Reset();Check(device->CreateCommittedResource(&props,D3D12_HEAP_FLAG_NONE,&desc,D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE,nullptr,IID_PPV_ARGS(&historyTextures[8])),"Virtual glass hit history");
288 289 device->CreateShaderResourceView(historyTextures[8].Get(),&srv,handle);handle.ptr+=step;
289 290 device->CreateUnorderedAccessView(glassSharp.resource.Get(),nullptr,&uav,handle);handle.ptr+=step;
290 device->CreateUnorderedAccessView(glassGuide.resource.Get(),nullptr,&uav,handle);
291 device->CreateUnorderedAccessView(glassGuide.resource.Get(),nullptr,&uav,handle);handle.ptr+=step;
292 device->CreateUnorderedAccessView(glassRaw.resource.Get(),nullptr,&uav,handle);
291 293 }
292 294 bool BuildMeshes() {
293 295 uint32_t built = 0;
@@ -477,11 +479,14 @@ public:
477 479 context11->ClearState(); context11->UpdateSubresource(constants11.Get(), 0, nullptr, &params, 0, 0);
478 480 for(auto& entry:dynamicTextures) {
479 481 auto& d=entry.second;if(!d.source || !d.shared.resource)continue;
480 if(d.dirty) {
482 // LCD content changes in-place without changing its SRV. Copy
483 // the current pixels on the render queue each frame; the 10 Hz
484 // binding discovery cadence must not become a display delay.
485 {
481 486 ID3D11ShaderResourceView* src=d.source.Get();ID3D11UnorderedAccessView* dst=d.shared.uav.Get();
482 487 context11->CSSetShaderResources(0,1,&src);context11->CSSetUnorderedAccessViews(0,1,&dst,nullptr);
483 488 context11->CSSetShader(copyScreen.Get(),nullptr,0);context11->Dispatch((d.width+7)/8,(d.height+7)/8,1);
484 context11->ClearState();d.dirty=false;
489 context11->ClearState();
485 490 }
486 491 auto handle=descriptors->GetCPUDescriptorHandleForHeapStart();
487 492 handle.ptr+=(18+entry.first)*device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
@@ -535,18 +540,16 @@ public:
535 540 Barrier(moments.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
536 541 Barrier(glassSharp.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
537 542 Barrier(glassGuide.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
538 if(params.pathSettings[0]>0){
539 Barrier(filtered.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
540 Barrier(filteredReflection.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
541 }
543 Barrier(glassRaw.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
544 Barrier(filtered.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
545 Barrier(filteredReflection.resource.Get(),D3D12_RESOURCE_STATE_COMMON,D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
542 546 list->Dispatch((width+7)/8, (height+7)/8, 1);
543 if(params.pathSettings[0]>0){
544 UavBarrier(nullptr);list->SetPipelineState(temporalPipeline.Get());list->Dispatch((width+7)/8,(height+7)/8,1);
545 Barrier(filtered.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
546 Barrier(filteredReflection.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
547 }
547 UavBarrier(nullptr);list->SetPipelineState(temporalPipeline.Get());list->Dispatch((width+7)/8,(height+7)/8,1);
548 Barrier(filtered.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
549 Barrier(filteredReflection.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
548 550 Barrier(glassSharp.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
549 551 Barrier(glassGuide.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
552 Barrier(glassRaw.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
550 553 Barrier(result.resource.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COMMON);
551 554 Barrier(reflection.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
552 555 Barrier(indirect.resource.Get(),D3D12_RESOURCE_STATE_UNORDERED_ACCESS,D3D12_RESOURCE_STATE_COMMON);
@@ -764,7 +767,7 @@ RT_API int RtDynamicMaterial(void* context,uint32_t id,void* textureSrv) {
764 767 auto shared=c->Texture(DXGI_FORMAT_R16G16B16A16_FLOAT,desc.Width,desc.Height);
765 768 d.shared=std::move(shared);d.width=desc.Width;d.height=desc.Height;c->dynamicPixels=pixels;
766 769 }
767 d.source=source;d.dirty=true;return 0;
770 d.source=source;return 0;
768 771 }catch(const Failure& e){c->Fail(e);return e.code;}catch(...){return E_FAIL;}
769 772 }
770 773 RT_API int RtRetainMeshes(void* context,const uint32_t* ids,uint32_t count) {
Modified src/XFE.SeRayTracing.Native/Rays.hlsl +76 -29
@@ -13,6 +13,7 @@ RWTexture2D<float4> moments : register(u7);
13 13 RWTexture2D<float4> filteredReflection : register(u8);
14 14 RWTexture2D<float4> glassSharp : register(u10);
15 15 RWTexture2D<float4> glassGuide : register(u11);
16 RWTexture2D<float4> glassRaw : register(u12);
16 17 struct Vertex { float3 position; float2 uv; float3 tint; };
17 18 struct InstanceMaterial { uint triangleOffset; float3 tint; row_major float3x4 previousTransform; uint previousValid; uint3 reserved; };
18 19 struct GlassMaterial { float4 transmission, optics; };
@@ -316,9 +317,12 @@ void TraceSurfacePaths(uint2 pixel,float4 p,inout uint rng) {
316 317 // Scratch buffers become the spatial filter outputs only after this pass.
317 318 filteredReflection[pixel]=float4(primary.previousP,primary.previousValid);
318 319 }
319 [numthreads(8,8,1)]
320 void Temporal(uint3 id:SV_DispatchThreadID) {
321 if(any(id.xy>=sizes.zw))return;uint2 pixel=id.xy;
320 float ReflectionHistoryLimit(float3 position,float3 previousPoint,float rough) {
321 float viewChange=length(normalize(position-originDelta.xyz)-normalize(previousPoint-originChange.xyz-previousCamera.xyz));
322 float reactive=(1-smoothstep(.25,.5,rough))*saturate(viewChange/max(.0005,rough*rough*.25));
323 return lerp(32,1,reactive);
324 }
325 void TemporalPaths(uint2 pixel) {
322 326 if(result[pixel].w<=0)return;
323 327 float4 p=positions[pixel],guide=surfaceGuide[pixel],motion=filteredReflection[pixel];
324 328 float3 radiance=filtered[pixel].rgb;
@@ -359,7 +363,12 @@ void Temporal(uint3 id:SV_DispatchThreadID) {
359 363 float3 old=oldRadiance/total;
360 364 float3 clipped=clamp(old,max(lo-.01,mean-3*sigma-.01),min(hi+.01,mean+3*sigma+.01));
361 365 float correction=length(old-clipped)/max(length(old),.02);
362 count=min(oldCount/total+1,correction>.2?4:32);
366 // Receiver motion is insufficient for view-dependent reflection:
367 // a polished lobe moves across a stationary surface as the eye
368 // translates. Keep diffuse/rough history, shorten a tight lobe
369 // according to its angular footprint instead of dragging it.
370 float rough=max(.04,1-normals[pixel].w);
371 count=min(oldCount/total+1,correction>.2?1:ReflectionHistoryLimit(p.xyz,previousPoint,rough));
363 372 radiance=lerp(radiance,clipped,1-1/count);
364 373 float oldLuma=Luma(clipped);float2 oldMoment=oldStats/total;
365 374 if(correction>.2)oldMoment=float2(oldLuma,oldLuma*oldLuma);
@@ -369,6 +378,64 @@ void Temporal(uint3 id:SV_DispatchThreadID) {
369 378 }
370 379 indirect[pixel]=float4(radiance,count);moments[pixel]=float4(stats,0,0);
371 380 }
381 void TemporalHybrid(uint2 pixel) {
382 float4 p=positions[pixel],bounce=filtered[pixel],spec=filteredReflection[pixel];
383 if(p.w<=0)return;
384 float4 stats=float4(Luma(bounce.rgb),0,Luma(spec.rgb),0);stats.y=stats.x*stats.x;stats.w=stats.z*stats.z;
385 if(history.x>0) {
386 float3 previousPoint=p.xyz+originChange.xyz;
387 float4 clip=mul(float4(p.xyz-previousCamera.xyz,1),previousViewProjection);
388 float2 uv=float2(clip.x/clip.w*.5+.5,.5-clip.y/clip.w*.5);
389 if(clip.w>0 && all(uv>=0) && all(uv<1)) {
390 uint2 q=min(uint2(uv*sizes.zw),sizes.zw-1);
391 float4 oldPosition=previousPositions[q],oldNormal=previousNormals[q];
392 if(oldPosition.w>0 && length(oldPosition.xyz-previousPoint)<.12 && dot(normals[pixel].xyz,oldNormal.xyz)>.98 && abs(normals[pixel].w-oldNormal.w)<.05) {
393 float3 lo=bounce.rgb,hi=bounce.rgb,specLo=spec.rgb,specHi=spec.rgb;
394 [unroll] for(int y=-1;y<=1;y++)[unroll] for(int x=-1;x<=1;x++) {
395 int2 at=clamp(int2(pixel)+int2(x,y),0,int2(sizes.zw)-1);
396 if(positions[at].w<=0 || dot(normals[pixel].xyz,normals[at].xyz)<.98 || abs(dot(positions[at].xyz-p.xyz,normals[pixel].xyz))>.025)continue;
397 lo=min(lo,filtered[at].rgb);hi=max(hi,filtered[at].rgb);
398 specLo=min(specLo,filteredReflection[at].rgb);specHi=max(specHi,filteredReflection[at].rgb);
399 }
400 float4 oldBounce=previousIndirect[q],oldSpec=previousReflections[q];
401 float3 clipped=clamp(oldBounce.rgb,lo-.0001,hi+.0001),specClipped=clamp(oldSpec.rgb,specLo-.0001,specHi+.0001);
402 float correction=max(length(oldBounce.rgb-clipped)/max(length(oldBounce.rgb),.001),length(oldSpec.rgb-specClipped)/max(length(oldSpec.rgb),.001));
403 bounce.a=min(oldBounce.a+1,correction>.2?1:ReflectionHistoryLimit(p.xyz,previousPoint,max(.04,1-normals[pixel].w)));
404 float weight=1-1/bounce.a;
405 bounce.rgb=lerp(bounce.rgb,clipped,weight);spec=lerp(spec,float4(specClipped,oldSpec.a),weight);
406 stats=lerp(stats,previousMoments[q],weight);
407 }
408 }
409 }
410 reflected[pixel]=spec;indirect[pixel]=bounce;moments[pixel]=stats;
411 }
412 void TemporalGlass(uint2 pixel) {
413 float4 raw=glassRaw[pixel],old=glassReflected[pixel];
414 if(raw.a<=0 || old.a<=0){glassReflected[pixel]=raw;return;}
415 float4 guide=glassGuide[pixel],pane=glassData[pixel];
416 float3 lo=raw.rgb,hi=raw.rgb,mean=0,square=0;float count=0;
417 float footprint=max(.025,guide.w*8/sizes.w);
418 [unroll] for(int y=-2;y<=2;y++)[unroll] for(int x=-2;x<=2;x++) {
419 int2 q=clamp(int2(pixel)+int2(x,y),0,int2(sizes.zw)-1);
420 float4 other=glassGuide[q],value=glassRaw[q];
421 if(value.a<=0 || other.w<=0 || length(other.xyz-guide.xyz)>footprint*2 || length(glassData[q].rgb-pane.rgb)>.05)continue;
422 lo=min(lo,value.rgb);hi=max(hi,value.rgb);mean+=value.rgb;square+=value.rgb*value.rgb;count++;
423 }
424 mean/=max(count,1);float3 sigma=sqrt(max(square/max(count,1)-mean*mean,0));
425 float3 clipped=clamp(old.rgb,max(lo-.0001,mean-3*sigma-.0001),min(hi+.0001,mean+3*sigma+.0001));
426 // Geometry can still match while a lamp, shadow or indirect image changes.
427 // Reject a materially changed signal immediately, rather than fading it for
428 // eight frames. The immutable raw buffer avoids cross-thread UAV feedback.
429 float correction=length(old.rgb-clipped)/max(length(old.rgb),.001);
430 glassReflected[pixel]=float4(lerp(raw.rgb,clipped,correction>.2?0:old.a),raw.a);
431 }
432 [numthreads(8,8,1)]
433 void Temporal(uint3 id:SV_DispatchThreadID) {
434 if(any(id.xy>=sizes.zw))return;
435 if(pathSettings.x>0)TemporalPaths(id.xy);
436 else TemporalHybrid(id.xy);
437 TemporalGlass(id.xy);
438 }
372 439 // Clear glass carries deterministic texture/emission and sunlight separately.
373 440 // Only stochastic secondary lighting needs temporal/spatial denoising.
374 441 float4 GlassLighting(Hit pane,float3 viewRay,inout uint rng,out Hit anchor,out float3 sharp) {
@@ -395,8 +462,8 @@ void Trace(uint3 id:SV_DispatchThreadID) {
395 462 if(any(id.xy>=sizes.zw)) return;
396 463 float4 p=positions[id.xy];
397 464 uint rng=id.x*1973+id.y*9277+(uint)history.y*26699+89173;
398 result[id.xy]=1;reflected[id.xy]=0;indirect[id.xy]=0;glassReflected[id.xy]=0;glassData[id.xy]=0;glassRefracted[id.xy]=0;moments[id.xy]=0;glassSharp[id.xy]=0;glassGuide[id.xy]=0;
399 if(pathSettings.x>0){filtered[id.xy]=0;filteredReflection[id.xy]=0;}
465 result[id.xy]=1;reflected[id.xy]=0;indirect[id.xy]=0;glassReflected[id.xy]=0;glassData[id.xy]=0;glassRefracted[id.xy]=0;moments[id.xy]=0;glassSharp[id.xy]=0;glassGuide[id.xy]=0;glassRaw[id.xy]=0;
466 filtered[id.xy]=0;filteredReflection[id.xy]=0;
400 467 float3 surface=p.xyz, surfaceNormal=normalize(normals[id.xy].xyz);
401 468 // Transparent surfaces have no opaque G-buffer entry. Trace camera rays
402 469 // independently, including windows backed by sky or distant terrain.
@@ -447,11 +514,11 @@ void Trace(uint3 id:SV_DispatchThreadID) {
447 514 float w=(xx?fraction.x:1-fraction.x)*(yy?fraction.y:1-fraction.y);old+=previousGlassReflections[q]*w;total+=w;
448 515 }
449 516 }
450 if(total>.1)reflectionSample.rgb=lerp(reflectionSample.rgb,old.rgb/total,.875);
517 if(total>.1)glassReflected[id.xy]=float4(old.rgb/total,.875);
451 518 }
452 519 }
453 520 }
454 glassReflected[id.xy]=reflectionSample;
521 glassRaw[id.xy]=reflectionSample;
455 522 glassData[id.xy]=float4(PaneTransmission(front,viewRay),front.t);
456 523 float3 inside=refract(viewRay,front.n,1/g.optics.x);
457 524 float3 exitPoint=front.p+inside*(g.optics.y/max(abs(dot(inside,front.n)),.1))+viewRay*.012;
@@ -491,27 +558,7 @@ void Trace(uint3 id:SV_DispatchThreadID) {
491 558 [unroll] for(uint j=0;j<2;j++) bounce.rgb+=PathRadiance(surface+n*.04,Cosine(n,rng),max(transport.y,12),rng).rgb*.5;
492 559 }
493 560 bounce.a=1;
494 float giLuma=Luma(bounce.rgb),specLuma=Luma(reflection.rgb);
495 float4 sampleMoments=float4(giLuma,giLuma*giLuma,specLuma,specLuma*specLuma);
496 if(history.x>0) {
497 float4 clip=mul(float4(p.xyz-previousCamera.xyz,1),previousViewProjection);
498 float2 uv=float2(clip.x/clip.w*.5+.5,.5-clip.y/clip.w*.5);
499 if(clip.w>0 && all(uv>=0) && all(uv<1)) {
500 uint2 q=min(uint2(uv*sizes.zw),sizes.zw-1);
501 float4 oldPosition=previousPositions[q];float error=length(oldPosition.xyz-(p.xyz+originChange.xyz));
502 if(oldPosition.w>0 && error<.12 && dot(normals[id.xy].xyz,previousNormals[q].xyz)>.98 && abs(normals[id.xy].w-previousNormals[q].w)<.05) {
503 float4 oldBounce=previousIndirect[q];
504 // A different Monte Carlo hit is not a disocclusion. Validate
505 // receiver geometry, then accumulate radiance and its moments.
506 bounce.a=min(oldBounce.a+1,32);
507 bounce.rgb=lerp(bounce.rgb,oldBounce.rgb,1-1/bounce.a);
508 float4 oldReflection=previousReflections[q];
509 reflection=lerp(reflection,oldReflection,1-1/bounce.a);
510 sampleMoments=lerp(sampleMoments,previousMoments[q],1-1/bounce.a);
511 }
512 }
513 }
514 reflected[id.xy]=reflection;indirect[id.xy]=bounce;moments[id.xy]=sampleMoments;
561 filtered[id.xy]=bounce;filteredReflection[id.xy]=reflection;
515 562 }
516 563 [numthreads(8,8,1)]
517 564 void Denoise(uint3 id:SV_DispatchThreadID) {
Modified tests/XFE.SeRayTracing.Tests/GpuTest.cpp +62 -0
@@ -229,6 +229,21 @@ int main() {
229 229 means[mode]=sum/32;deviations[mode]=sqrt(fmax(0,squares/32-means[mode]*means[mode]));
230 230 }
231 231 printf("glass temporal green mean %.6f -> %.6f; standard deviation %.6f -> %.6f\n",means[0],means[1],deviations[0],deviations[1]);
232 // Changing the illumination is not a pane/hit disocclusion. Converged red
233 // energy must disappear on the first green-only frame, including in hybrid mode.
234 lamps[0].colorIntensity[0]=0;lamps[0].colorIntensity[1]=1;
235 Check(RtLights(ray,lamps,2),"Reflected illumination changes to green");
236 context->UpdateSubresource(l.texture.Get(),0,nullptr,white.data(),64*16,0);
237 Check(RtFrame(ray,d.srv.Get(),n.srv.Get(),l.srv.Get(),m.srv.Get(),m.srv.Get(),l.rtv.Get(),room,2,&p),"First changed glass illumination");
238 context->CopyResource(readback.Get(),l.texture.Get());Check(context->Map(readback.Get(),0,D3D11_MAP_READ,0,&mapped),"Glass illumination response");
239 color=(float*)((char*)mapped.pData+32*mapped.RowPitch)+32*4;
240 float changedGlassRed=color[0];context->Unmap(readback.Get(),0);
241 p.history[0]=0;context->UpdateSubresource(l.texture.Get(),0,nullptr,white.data(),64*16,0);
242 Check(RtFrame(ray,d.srv.Get(),n.srv.Get(),l.srv.Get(),m.srv.Get(),m.srv.Get(),l.rtv.Get(),room,2,&p),"Fresh glass illumination reference");
243 context->CopyResource(readback.Get(),l.texture.Get());Check(context->Map(readback.Get(),0,D3D11_MAP_READ,0,&mapped),"Fresh glass illumination readback");
244 color=(float*)((char*)mapped.pData+32*mapped.RowPitch)+32*4;
245 printf("changed glass old-red excess=%.6f green=%.6f\n",changedGlassRed-color[0],color[1]);
246 valid=valid && color[1]>.002 && std::abs(changedGlassRed-color[0])<.0001;context->Unmap(readback.Get(),0);
232 247 valid=valid && means[0]>.001 && means[1]>means[0]*.6 && means[1]<means[0]*1.4 && deviations[0]>.00001 && deviations[1]<deviations[0]*.5;
233 248 for(int i=0;i<16;i++) p.previousViewProjection[i]=(i%5==0)?1.0f:0.0f;
234 249 // The same noisy lighting on an opaque receiver must accumulate too. A
@@ -374,6 +389,16 @@ int main() {
374 389 color=(float*)((char*)mapped.pData+32*mapped.RowPitch)+32*4;
375 390 printf("first changed LCD RGB=%.6f,%.6f,%.6f\n",color[0],color[1],color[2]);valid=valid && color[0]<.0001 && color[2]>.04;
376 391 context->Unmap(readback.Get(),0);
392 // Real LCDs render new pixels into the same SRV; they do not re-register
393 // that resource with the bridge on every content update.
394 std::fill(screen.begin(),screen.end(),0.0f);for(size_t i=0;i<screen.size();i+=4)screen[i]=1;
395 context->UpdateSubresource(live.texture.Get(),0,nullptr,screen.data(),64*16,0);
396 context->UpdateSubresource(l.texture.Get(),0,nullptr,white.data(),64*16,0);
397 Check(RtFrame(ray,d.srv.Get(),n.srv.Get(),l.srv.Get(),m.srv.Get(),m.srv.Get(),l.rtv.Get(),room,2,&p),"Same-SRV LCD content update");
398 context->CopyResource(readback.Get(),l.texture.Get());Check(context->Map(readback.Get(),0,D3D11_MAP_READ,0,&mapped),"Same-SRV LCD response");
399 color=(float*)((char*)mapped.pData+32*mapped.RowPitch)+32*4;
400 printf("same-SRV changed LCD RGB=%.6f,%.6f,%.6f\n",color[0],color[1],color[2]);valid=valid && color[0]>.04 && color[2]<.0001;
401 context->Unmap(readback.Get(),0);
377 402
378 403 // PT must replace raster lighting using the primary surface, preserve a
379 404 // missing primary surface, and work at native resolution as well as half.
@@ -560,6 +585,43 @@ int main() {
560 585 p.environment[1]=0;context->UpdateSubresource(l.texture.Get(),0,nullptr,white.data(),64*16,0);
561 586 Check(RtFrame(ray,d.srv.Get(),n.srv.Get(),l.srv.Get(),m.srv.Get(),base.srv.Get(),l.rtv.Get(),&instance,1,&p),"First extinguished illumination frame");statistics(1,darkMean,darkNoise);
562 587 printf("lighting discontinuity green=%.6f -> %.6f in one frame\n",litMean,darkMean);valid=valid && litMean>.2 && darkMean<.015 && darkMean<litMean*.05;
588 // A polished receiver remains in place while the camera translates. Its
589 // reflection has different motion from the receiver itself. Compare first
590 // moving-frame dark pixels against a fresh estimate at the identical pose.
591 uint32_t motionKeep[]={18,23};Check(RtRetainMeshes(ray,motionKeep,2),"Moving mirror scene");
592 auto strip=background;for(int v=0;v<4;v++){strip[v*8]=v==0||v==3?-.5f:.5f;strip[v*8+2]=-2;}
593 Check(RtMesh(ray,23,strip.data(),4,indices,6,emissiveIds),"Reflected emissive strip");
594 room[0]=instance;room[0].mesh=18;room[0].key=231;room[0].transform[3]=0;
595 room[1]=room[0];room[1].mesh=23;room[1].key=232;
596 p={};p.sizes[0]=p.sizes[1]=p.sizes[2]=p.sizes[3]=64;
597 for(int i=0;i<4;i++){p.inverseViewProjection[i*4+i]=1;p.inverseView[i*4+i]=1;}
598 p.previousViewProjection[0]=p.previousViewProjection[5]=1;p.previousViewProjection[11]=1;
599 memcpy(p.viewProjection,p.previousViewProjection,64);
600 p.pathSettings[0]=1;p.pathSettings[1]=8;p.pathSettings[3]=1;p.environment[2]=p.environment[3]=1;p.transport[0]=2;
601 std::fill(material.begin(),material.end(),0.0f);std::fill(baseColors.begin(),baseColors.end(),1.0f);std::fill(depth.begin(),depth.end(),1.0f);std::fill(white.begin(),white.end(),0.0f);
602 for(int i=0;i<64*64;i++){material[i*4]=1;material[i*4+1]=.98f;normal[i*4]=1;normal[i*4+1]=.5f;}
603 context->UpdateSubresource(m.texture.Get(),0,nullptr,material.data(),64*16,0);context->UpdateSubresource(n.texture.Get(),0,nullptr,normal.data(),64*16,0);
604 context->UpdateSubresource(base.texture.Get(),0,nullptr,baseColors.data(),64*16,0);context->UpdateSubresource(d.texture.Get(),0,nullptr,depth.data(),64*4,0);
605 for(int pathMode=0;pathMode<2;pathMode++) {
606 p.pathSettings[0]=(float)pathMode;p.settings[3]=pathMode?0.0f:3.0f;p.effects[0]=1;p.originDelta[0]=0;
607 for(int frame=0;frame<48;frame++){
608 p.history[0]=frame?1.0f:0;context->UpdateSubresource(l.texture.Get(),0,nullptr,white.data(),64*16,0);
609 Check(RtFrame(ray,d.srv.Get(),n.srv.Get(),l.srv.Get(),m.srv.Get(),base.srv.Get(),l.rtv.Get(),room,2,&p),"Converge mirror strip");
610 }
611 p.originDelta[0]=.08f;std::vector<float> movingMirror;double mirrorGhost=0,mirrorSignal=0;int darkPixels=0;
612 for(int fresh=0;fresh<2;fresh++){
613 p.history[0]=fresh?0.0f:1.0f;context->UpdateSubresource(l.texture.Get(),0,nullptr,white.data(),64*16,0);
614 Check(RtFrame(ray,d.srv.Get(),n.srv.Get(),l.srv.Get(),m.srv.Get(),base.srv.Get(),l.rtv.Get(),room,2,&p),"Translated mirror comparison");
615 context->CopyResource(readback.Get(),l.texture.Get());Check(context->Map(readback.Get(),0,D3D11_MAP_READ,0,&mapped),"Mirror afterimage readback");
616 int i=0;for(int y=16;y<48;y++)for(int x=16;x<48;x++,i++){
617 float value=((float*)((char*)mapped.pData+y*mapped.RowPitch))[x*4+1];
618 if(!fresh)movingMirror.push_back(value);else {mirrorSignal=(std::max)(mirrorSignal,double(value));if(value<.005){darkPixels++;mirrorGhost=(std::max)(mirrorGhost,double(movingMirror[i]-value));}}
619 }
620 context->Unmap(readback.Get(),0);
621 }
622 printf("translated polished reflection mode=%d old-light excess=%.6f signal=%.6f darkPixels=%d\n",pathMode,mirrorGhost,mirrorSignal,darkPixels);
623 valid=valid && mirrorSignal>.2 && darkPixels>100 && mirrorGhost<.015;
624 }
563 625 Check(RtEnvironment(ray,nullptr),"Unset environment");
564 626 RtDestroy(ray); puts(valid?"PASS GPU occlusion, textured offscreen reflection, indirect bounce, live emissive LCD, primary path tracing, native resolution, interop, state restoration, validation":"FAIL ray output"); return valid?0:1;
565 627 }