47 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
		
		
			
		
	
	
			47 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| 
								 | 
							
								---
							 | 
						|||
| 
								 | 
							
								title: RayTracingGEM学习笔记——(1)
							 | 
						|||
| 
								 | 
							
								date: 2022-08-09 13:55:15
							 | 
						|||
| 
								 | 
							
								tags: RayTracing
							 | 
						|||
| 
								 | 
							
								rating: ⭐️⭐️ 
							 | 
						|||
| 
								 | 
							
								---
							 | 
						|||
| 
								 | 
							
								# RayTracingGEM
							 | 
						|||
| 
								 | 
							
								## Shader
							 | 
						|||
| 
								 | 
							
								- RayGeneration Shader,是整个DXR可编程管线的入口,负责投射光线,将光照计算结果返回RenderTarget;
							 | 
						|||
| 
								 | 
							
								- Closest Hit Shader,光线与场景最近的有效交点,主要用于着色计算;
							 | 
						|||
| 
								 | 
							
								- Miss Shader,光线与场景没有交点,常用的操作是会去采样天空盒等;
							 | 
						|||
| 
								 | 
							
								- Any Hit Shader,可选的,任意一次相交都会触发,而且不保证触发顺序,通常用来做Alpha Test
							 | 
						|||
| 
								 | 
							
								- Intersection Shader,可选的,非三角面片的程序化自定义的几何图形与光线的相交判断;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								使用CS生成样本集。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								## Ray
							 | 
						|||
| 
								 | 
							
								DirectX Raytracing的光线定义如下:
							 | 
						|||
| 
								 | 
							
								```c++
							 | 
						|||
| 
								 | 
							
								struct RayDesc
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
									float3 Origin;
							 | 
						|||
| 
								 | 
							
									float  TMin;
							 | 
						|||
| 
								 | 
							
									float3 Direction;
							 | 
						|||
| 
								 | 
							
									float  TMax;
							 | 
						|||
| 
								 | 
							
								};
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								- WorldRayOrigin() WorldRayDirection() RayTMin() RayFlags()
							 | 
						|||
| 
								 | 
							
								- DispatchRaysIndex()查询光线index。
							 | 
						|||
| 
								 | 
							
								- DispatchRaysDimensions()查询光线维度。
							 | 
						|||
| 
								 | 
							
								- RayTCurrent()返回对应状态(Hit、Intersection、Miss)的Distance
							 | 
						|||
| 
								 | 
							
								- InstanceID()用户定义的ID
							 | 
						|||
| 
								 | 
							
								- InstanceIndex() and PrimitiveIndex()系统定义的ID
							 | 
						|||
| 
								 | 
							
								- ObjectRayDirection() and ObjectRayOrigin()实例空间坐标的Ray数据。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								使用TraceRay()进行光线追踪计算。其工作流程如下:
							 | 
						|||
| 
								 | 
							
								.png)
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								DXR还提供了3个额外功能来控制光线与图元相交以及命中Shader的行为。
							 | 
						|||
| 
								 | 
							
								- ReportHit():设定若干属性,返回Ray Hit结果。
							 | 
						|||
| 
								 | 
							
								- IgnoreHit():在any-hit shader中停止处理当前当前Hit点。
							 | 
						|||
| 
								 | 
							
								- AcceptHitAndEndSearch():在any-hit shader中接受当前Hit,跳过任何未搜索到的加速结构节点。并立即传入closest hit点到closest-hit shader来使用。一般用于简化着色或者光照计算。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								### 
							 | 
						|||
| 
								 | 
							
								- 3.8 BASIC DXR INITIALIZATION AND SETUP
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								76页
							 |