다음을 통해 공유


교차 셰이더

연결된 경계 볼륨(경계 상자)과 교차하는 광선에 대한 사용자 지정 교차 기본 형식을 구현하는 데 사용되는 셰이더입니다.

교차 셰이더는 광선 페이로드에 액세스할 수 없지만 ReportHit 호출을 통해 적중할 때마다 교차 특성을 정의합니다. ReportHit의 처리는 광선 플래그 RAY_FLAG_ACCEPT_FIRST_HIT_\AND_\END_SEARCH 설정되거나 적중 셰이더에서 AcceptHitAndEndSearch가 호출되는 경우 교차 셰이더를 일찍 중지할 수 있습니다. 그렇지 않으면 적중이 수락되면 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;
    }
}