// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "../Barycentrics.ush" struct FRaytracingDerivatives { TDual< float3 > WorldPosition; TDual< float3 > WorldGeoNormals; TDual< float4 > ScreenPosition; #if NUM_TEX_COORD_INTERPOLATORS TDual< float2 > TexCoords[NUM_TEX_COORD_INTERPOLATORS]; #endif }; void CalcInterpolants( in float4 SvPosition, in FRayCone RayCone, in FRayTracingIntersectionAttributes Attributes, inout FVertexFactoryInterpolantsVSToPS OutInterpolants, inout FRaytracingDerivatives OutDerivateData, inout float3 OutFaceNormal) { FVertexFactoryRayTracingInterpolants Interpolated = (FVertexFactoryRayTracingInterpolants)0; float4 ClipPositions[3]; float3 WorldPositions[3]; float3 WorldGeoNormals[3]; float2 TexCoords[3]; #if NUM_TEX_COORD_INTERPOLATORS float2 TexCoords_Custom[NUM_TEX_COORD_INTERPOLATORS][3]; #endif const float2 VW = Attributes.GetBarycentrics(); const float3 UVW = float3(1 - VW.x - VW.y, VW.x, VW.y); for (int i = 0; i < 3; i++) { FVertexFactoryInput Input = LoadVertexFactoryInputForHGS(PrimitiveIndex(), i); FVertexFactoryIntermediates VFIntermediates = GetVertexFactoryIntermediates(Input); float3x3 TangentToLocal = VertexFactoryGetTangentToLocal(Input, VFIntermediates); float4 WorldPositionExcludingWPO = VertexFactoryGetWorldPosition(Input, VFIntermediates); FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPositionExcludingWPO.xyz, TangentToLocal); FVertexFactoryRayTracingInterpolants PerVertexInterpolants = VertexFactoryGetRayTracingInterpolants(Input, VFIntermediates, VertexParameters); Interpolated = VertexFactoryInterpolate(PerVertexInterpolants, UVW[i], Interpolated, 1.0); WorldPositions[i] = WorldPositionExcludingWPO.xyz; WorldGeoNormals[i] = VertexFactoryGetWorldNormal(Input, VFIntermediates); TexCoords[i] = VertexFactoryGetRayTracingTextureCoordinate(PerVertexInterpolants); #if (NUM_TEX_COORD_INTERPOLATORS) UNROLL for (uint TexCoordIndex=0;TexCoordIndex 0 UNROLL for (uint TexCoordIndex = 0; TexCoordIndex < NUM_TEX_COORD_INTERPOLATORS; TexCoordIndex++) { OutDerivateData.TexCoords[TexCoordIndex] = Lerp( TexCoords_Custom[TexCoordIndex][0], TexCoords_Custom[TexCoordIndex][1], TexCoords_Custom[TexCoordIndex][2], Barycentrics ); } #endif } void CalcInterpolants(in FRayCone RayCone, in FRayTracingIntersectionAttributes Attributes, inout FVertexFactoryInterpolantsVSToPS OutInterpolants, inout float3 OutFaceNormal) { FRaytracingDerivatives OutDerivatives; // unused CalcInterpolants(0, RayCone, Attributes, OutInterpolants, OutDerivatives, OutFaceNormal); } // simplified call when Geometric Normal is not needed void CalcInterpolants(in FRayCone RayCone, in FRayTracingIntersectionAttributes Attributes, inout FVertexFactoryInterpolantsVSToPS OutInterpolants) { float3 OutGeoNormal = 0; // unused FRaytracingDerivatives OutDerivatives; // unused CalcInterpolants(0, RayCone, Attributes, OutInterpolants, OutDerivatives, OutGeoNormal); } void ApplyRaytracingDerivatives(inout FMaterialPixelParameters Out, in FRaytracingDerivatives In) { Out.WorldPosition_DDX = In.WorldPosition.Value_dx; Out.WorldPosition_DDY = In.WorldPosition.Value_dy; Out.ScreenPosition_DDX = In.ScreenPosition.Value_dx; Out.ScreenPosition_DDY = In.ScreenPosition.Value_dy; Out.WorldGeoNormal_DDX = In.WorldGeoNormals.Value_dx; Out.WorldGeoNormal_DDY = In.WorldGeoNormals.Value_dy; #if NUM_TEX_COORD_INTERPOLATORS UNROLL for (uint TexCoordIndex = 0; TexCoordIndex < NUM_TEX_COORD_INTERPOLATORS; TexCoordIndex++) { Out.TexCoords_DDX[TexCoordIndex] = In.TexCoords[TexCoordIndex].Value_dx; Out.TexCoords_DDY[TexCoordIndex] = In.TexCoords[TexCoordIndex].Value_dy; } #endif }