You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.7 KiB
88 lines
3.7 KiB
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingFragInputs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/EvaluateRayTracingIndirect.hlsl"
|
|
|
|
// Generic function that handles the reflection code
|
|
[shader("closesthit")]
|
|
void ClosestHitMain(inout RayIntersection rayIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes)
|
|
{
|
|
UNITY_XR_ASSIGN_VIEW_INDEX(DispatchRaysIndex().z);
|
|
|
|
IntersectionVertex currentVertex;
|
|
FragInputs fragInput;
|
|
GetCurrentVertexAndBuildFragInputs(attributeData, currentVertex, fragInput);
|
|
|
|
// Compute the view vector
|
|
float3 viewWS = -WorldRayDirection();
|
|
float3 pointWSPos = fragInput.positionRWS;
|
|
|
|
// Make sure to add the additional travel distance
|
|
rayIntersection.t = RayTCurrent();
|
|
rayIntersection.cone.width += rayIntersection.t * rayIntersection.cone.spreadAngle;
|
|
|
|
PositionInputs posInput = GetPositionInput(rayIntersection.pixelCoord, _ScreenSize.zw, fragInput.positionRWS);
|
|
|
|
// Build the surfacedata and builtindata
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
bool isVisible;
|
|
GetSurfaceAndBuiltinData(fragInput, viewWS, posInput, surfaceData, builtinData, currentVertex, rayIntersection.cone, isVisible);
|
|
|
|
// Compute the bsdf data
|
|
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(posInput.positionSS, surfaceData);
|
|
|
|
// No need for SurfaceData after this line
|
|
#ifdef HAS_LIGHTLOOP
|
|
// Compute the prelight data
|
|
PreLightData preLightData = GetPreLightData(viewWS, posInput, bsdfData);
|
|
|
|
// Evaluate the lighting
|
|
EvaluateIndirectRayTracingLighting(preLightData, posInput, bsdfData, builtinData, viewWS, pointWSPos, rayIntersection);
|
|
#else
|
|
// Given that we will be multiplying the final color by the current exposure multiplier outside of this function, we need to make sure that
|
|
// the unlit color is not impacted by that. Thus, we multiply it by the inverse of the current exposure multiplier.
|
|
rayIntersection.color = bsdfData.color * GetInverseCurrentExposureMultiplier() + builtinData.emissiveColor;
|
|
#endif
|
|
|
|
// Apply fog attenuation
|
|
ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), rayIntersection.t, rayIntersection.color, true);
|
|
}
|
|
|
|
// Generic function that handles the reflection code
|
|
[shader("anyhit")]
|
|
void AnyHitMain(inout RayIntersection rayIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes)
|
|
{
|
|
#ifdef _SURFACE_TYPE_TRANSPARENT
|
|
IgnoreHit();
|
|
#else
|
|
|
|
UNITY_XR_ASSIGN_VIEW_INDEX(DispatchRaysIndex().z);
|
|
|
|
IntersectionVertex currentVertex;
|
|
FragInputs fragInput;
|
|
GetCurrentVertexAndBuildFragInputs(attributeData, currentVertex, fragInput);
|
|
|
|
// Compute the view vector
|
|
float3 viewWS = -WorldRayDirection();
|
|
|
|
// Compute the distance of the ray
|
|
rayIntersection.t = RayTCurrent();
|
|
|
|
PositionInputs posInput;
|
|
posInput.positionWS = fragInput.positionRWS;
|
|
posInput.positionSS = rayIntersection.pixelCoord;
|
|
|
|
// Build the surfacedata and builtindata
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
bool isVisible;
|
|
GetSurfaceAndBuiltinData(fragInput, viewWS, posInput, surfaceData, builtinData, currentVertex, rayIntersection.cone, isVisible);
|
|
|
|
// If this fella should be culled, then we cull it
|
|
if(!isVisible)
|
|
{
|
|
IgnoreHit();
|
|
}
|
|
#endif
|
|
}
|