交集著色器
著色器,用來實作與相關聯周框磁片區交集 (周框方塊) 的光線自訂交集基本類型。
交集著色器無法存取光線承載,但會透過對 ReportHit的呼叫來定義每個點擊的交集屬性。 如果設定了 ray 旗標RAY_FLAG_ACCEPT_FIRST_HIT_\AND_\END_SEARCH,或從任何點擊著色器呼叫AcceptHitAndEndSearch,則 ReportHit的處理可能會提早停止交集著色器。 否則,如果已接受點擊,則傳回 true;如果點擊遭到拒絕,則會傳回 false。 這表示如果存在,任何點擊著色器都必須執行,才能有條件地將控制項傳回交集著色器。
著色器類型屬性
[shader("intersection")]
範例
struct CustomPrimitiveDef { ... };
struct MyAttributes { ... };
struct CustomIntersectionIterator {...};
void InitCustomIntersectionIterator(CustomIntersectionIterator it) {...}
bool IntersectCustomPrimitiveFrontToBack(
CustomPrimitiveDef prim,
inout CustomIntersectionIterator it,
float3 origin, float3 dir,
float rayTMin, inout float curT,
out MyAttributes attr);
[shader("intersection")]
void intersection_main()
{
float THit = RayTCurrent();
MyAttributes attr;
CustomIntersectionIterator it;
InitCustomIntersectionIterator(it);
while(IntersectCustomPrimitiveFrontToBack(
CustomPrimitiveDefinitions[LocalConstants.PrimitiveIndex],
it, ObjectRayOrigin(), ObjectRayDirection(),
RayTMin(), THit, attr))
{
// Exit on the first hit. Note that if the ray has
// RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH or an
// anyhit shader is used and calls AcceptHitAndEndSearch(),
// that would also fully exit this intersection shader (making
// the “break” below moot in that case).
if (ReportHit(THit, /*hitKind*/ 0, attr) && (RayFlags() & RAY_FLAG_FORCE_OPAQUE))
break;
}
}