Files
UnrealEngineUWP/Engine/Shaders/Private/LightShaderParameters.ush
tiago costa 1722da7465 Raytracing in translated world space
- Raytracing shadows/reflections/AO/GI/etc and path tracer now work in large worlds.
- Updated parts of Lumen using raytracing to work in large worlds.
- This change doesn't not address (all) GPU Lightmass issues in large worlds.

Changes:
- Build TLAS with instances in translated world space.
- Move ray origin to translated world space.
- Updated raytracing shaders to use translated world space (most LWCHackToFloat in these shaders are now gone).
- Store gather points positions in translated world space.
- Removed unused RayTracingDynamicMeshVS(...)

#rb Yuriy.ODonnell, Patrick.Kelly, chris.kulla, rob.krajcarski
#jira UE-140558
#preflight 620bb3ff4353dc61c7f51e64

[CL 18995354 by tiago costa in ue5-main branch]
2022-02-15 09:20:03 -05:00

87 lines
2.8 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#if RAYCALLABLESHADER || RAYGENSHADER || RAYHITGROUPSHADER || RAYMISSSHADER
# define SHADER_PARAMETERS_HAS_SOURCETEXTURE 1
#else
# define SHADER_PARAMETERS_HAS_SOURCETEXTURE 0
#endif
// Mirrors FLightShaderParameters on C++ side.
struct FLightShaderParameters
{
float3 TranslatedWorldPosition;
float InvRadius;
float3 Color;
float FalloffExponent;
float3 Direction;
float3 Tangent;
float2 SpotAngles;
float SpecularScale;
float SourceRadius;
float SoftSourceRadius;
float SourceLength;
float RectLightBarnCosAngle;
float RectLightBarnLength;
#if SHADER_PARAMETERS_HAS_SOURCETEXTURE
Texture2D SourceTexture;
#endif
};
/** Returns the full width and height of the rect light */
float2 GetRectLightDimensions(FLightShaderParameters LightParameters)
{
return 2.0 * float2(LightParameters.SourceRadius, LightParameters.SourceLength);
}
/** Returns the tangents to use respectively for GetRectLightDimensions() X and Y. */
void GetRectLightTangents(FLightShaderParameters LightParameters, out float3 Tangent, out float3 BiTangent)
{
Tangent = cross(LightParameters.Tangent, LightParameters.Direction);
BiTangent = LightParameters.Tangent;
}
// Parameters feed through FLightShaderParameters used directly as SHADER_PARAMETER_STRUCT() in a shader's root parameter structure.
float3 Light_TranslatedWorldPosition;
float Light_InvRadius;
float3 Light_Color;
float Light_FalloffExponent;
float3 Light_Direction;
float3 Light_Tangent;
float2 Light_SpotAngles;
float Light_SpecularScale;
float Light_SourceRadius;
float Light_SoftSourceRadius;
float Light_SourceLength;
float Light_RectLightBarnCosAngle;
float Light_RectLightBarnLength;
Texture2D Light_SourceTexture;
/** Returns the FLightShaderParameters from the root shader parameters. */
FLightShaderParameters GetRootLightShaderParameters()
{
// Hopefully one day the shader compiler will be so nice we would no longer have to do this.
FLightShaderParameters LightParameters;
LightParameters.TranslatedWorldPosition = Light_TranslatedWorldPosition;
LightParameters.InvRadius = Light_InvRadius;
LightParameters.Color = Light_Color;
LightParameters.FalloffExponent = Light_FalloffExponent;
LightParameters.Direction = Light_Direction;
LightParameters.Tangent = Light_Tangent;
LightParameters.SpotAngles = Light_SpotAngles;
LightParameters.SpecularScale = Light_SpecularScale;
LightParameters.SourceRadius = Light_SourceRadius;
LightParameters.SoftSourceRadius = Light_SoftSourceRadius;
LightParameters.SourceLength = Light_SourceLength;
LightParameters.RectLightBarnCosAngle = Light_RectLightBarnCosAngle;
LightParameters.RectLightBarnLength = Light_RectLightBarnLength;
#if SHADER_PARAMETERS_HAS_SOURCETEXTURE
LightParameters.SourceTexture = Light_SourceTexture;
#endif
return LightParameters;
}