Files
UnrealEngineUWP/Engine/Shaders/ReflectionEnvironmentShared.usf
Brian Karis 9871b021d7 Fixed dependency. Unbacked out change.
[CL 2060185 by Brian Karis in Main branch]
2014-04-30 14:14:19 -04:00

48 lines
2.0 KiB
Plaintext

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
ReflectionEnvironmentShared
=============================================================================*/
#define REFLECTION_CAPTURE_ROUGHEST_MIP 1
#define REFLECTION_CAPTURE_ROUGHNESS_MIP_SCALE 1.2
/**
* Compute absolute mip for a reflection capture cubemap given a roughness.
*/
half ComputeReflectionCaptureMipFromRoughness(half Roughness)
{
// Heuristic that maps roughness to mip level
// This is done in a way such that a certain mip level will always have the same roughness, regardless of how many mips are in the texture
// Using more mips in the cubemap just allows sharper reflections to be supported
// Note: this must match the logic in FilterReflectionEnvironment that generates the mip filter samples!
half LevelFrom1x1 = REFLECTION_CAPTURE_ROUGHEST_MIP - REFLECTION_CAPTURE_ROUGHNESS_MIP_SCALE * log2(Roughness);
// Note: must match GReflectionCaptureSize
half HardcodedNumCaptureArrayMips = 7;
return HardcodedNumCaptureArrayMips - 1 - LevelFrom1x1;
}
TextureCube SkyLightCubemap;
SamplerState SkyLightCubemapSampler;
/** X = max mip, Y = 1 if sky light should be rendered, 0 otherwise. */
float2 SkyLightParameters;
float3 GetSkyLightReflection(float3 ReflectionVector, float Roughness, bool Normalized)
{
float AbsoluteSpecularMip = ComputeReflectionCaptureMipFromRoughness(Roughness);
float3 Reflection = TextureCubeSampleLevel(SkyLightCubemap, SkyLightCubemapSampler, ReflectionVector, AbsoluteSpecularMip).rgb;
FLATTEN
if (Normalized)
{
// Sample the lowest resolution mip to get the average color
//@todo - can't normalize sky lighting and reflection capture lighting separately
float3 LowFrequencyReflection = TextureCubeSampleLevel(SkyLightCubemap, SkyLightCubemapSampler, ReflectionVector, SkyLightParameters.x).rgb;
float LowFrequencyBrightness = Luminance(LowFrequencyReflection);
Reflection /= max(LowFrequencyBrightness, .00001f);
}
return Reflection * View.SkyLightColor.rgb;
}