You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#jira UE-167927 #preflight 63c17db970575f89003af7a6 #rb charles.derousiers #preflight 63c189f42e714f64ad1a98a0 [CL 23679918 by Tiantian Xie in ue5-main branch]
46 lines
1.3 KiB
Plaintext
46 lines
1.3 KiB
Plaintext
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "../LightShaderParameters.ush"
|
|
#include "../PathTracing/Utilities/PathTracingRandomSequence.ush"
|
|
#include "../RectLight.ush"
|
|
|
|
bool GenerateRectLightOcclusionRay(
|
|
FLightShaderParameters LightParameters,
|
|
float3 TranslatedWorldPosition,
|
|
float3 WorldNormal,
|
|
float2 RandSample,
|
|
out float3 RayOrigin,
|
|
out float3 RayDirection,
|
|
out float RayTMin,
|
|
out float RayTMax,
|
|
out float RayPdf
|
|
)
|
|
{
|
|
RayOrigin = TranslatedWorldPosition;
|
|
RayDirection = float3(0,0,0);
|
|
RayTMin = 0.0;
|
|
RayTMax = 0.0;
|
|
RayPdf = 0.0;
|
|
|
|
// Define rectangle
|
|
FRect Rect = GetRect(LightParameters, TranslatedWorldPosition);
|
|
|
|
// 1. Derive the pdf when uniformly sampling from the spherical rectangle
|
|
FSphericalRect SphericalRect = BuildSphericalRect(Rect);
|
|
RayPdf = 1.0 / SphericalRect.SolidAngle;
|
|
|
|
// 2. Uniformly sample from the spherical rectangle
|
|
float3 LightDirection = UniformSampleSphericalRect(RandSample, SphericalRect);
|
|
|
|
// Light-normal culling
|
|
bool bIsValidRay = dot(-LightDirection, -LightParameters.Direction) >= 0.0;
|
|
|
|
// Apply normal perturbation when defining ray. normalize() resolves several banding artifacts
|
|
// at the cost of creating some bias under idea lighting condition but is neglectable.
|
|
RayDirection = normalize(LightDirection);
|
|
RayTMax = length(LightDirection);
|
|
|
|
return bIsValidRay;
|
|
} |