Share via


가장 가까운 적중 셰이더

셰이더가 활성화되고 가장 가까운 적중이 결정되거나 광선 교차 검색이 종료될 때 호출되는 셰이더입니다. 이 셰이더는 표면 음영 및 추가 광선 생성이 일반적으로 발생하는 곳입니다. 가장 가까운 적중 셰이더는 페이로드 매개 변수와 특성 매개 변수를 선언해야 합니다. 각각은 TraceRayReportHit 에 각각 사용되는 사용자 정의 구조체 형식 일치 형식이거나 고정 함수 삼각형 교차를 사용할 때 교집합 특성 구조 체여야 합니다.

셰이더 유형 특성

[shader("closesthit")]

예제

[shader("closesthit")]
void closesthit_main(inout MyPayload payload, in MyAttributes attr)
{
    CallShader( ... );	// maybe
    // update payload for surface
    // trace reflection
    float3 worldRayOrigin = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();
    float3 worldNormal = mul(attr.normal, (float3x3)ObjectToWorld3x4());
    RayDesc reflectedRay = { worldRayOrigin, SceneConstants.Epsilon,
                             ReflectRay(WorldRayDirection(), worldNormal),
                             SceneConstants.TMax };
    TraceRay(MyAccelerationStructure,
             SceneConstants.RayFlags,
             SceneConstants.InstanceInclusionMask,
             SceneConstants.RayContributionToHitGroupIndex,
             SceneConstants.MultiplierForGeometryContributionToHitGroupIndex,
             SceneConstants.MissShaderIndex,
             reflectedRay,
             payload);
    // Combine final contributions into ray payload
    // this ray query is now complete.
    // Alternately, could look at data in payload result based on that make other TraceRay
    // calls.  No constraints on the code structure.
}