You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
84 lines
2.4 KiB
Plaintext
84 lines
2.4 KiB
Plaintext
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "Common.ush"
|
|
|
|
#if !EYE_ADAPTATION_DISABLED
|
|
|
|
Texture2D EyeAdaptationTexture;
|
|
Buffer<float4> EyeAdaptationBuffer;
|
|
|
|
#if SHADING_PATH_DEFERRED
|
|
float EyeAdaptationLookupTexture2D(Texture2D InEyeAdaptation)
|
|
{
|
|
return InEyeAdaptation.Load(int3(0, 0, 0)).x;
|
|
}
|
|
#elif SHADING_PATH_MOBILE
|
|
float EyeAdaptationLookupBuffer(Buffer<float4> InEyeAdaptation)
|
|
{
|
|
return InEyeAdaptation[0].x;
|
|
}
|
|
#else
|
|
#error Unknown shading path.
|
|
#endif
|
|
|
|
#endif // !EYE_ADAPTATION_DISABLED
|
|
|
|
#if defined (EyeAdaptationStruct)
|
|
#if EYE_ADAPTATION_LOOSE_PARAMETERS
|
|
#error EyeAdaptationStruct and EYE_ADAPTATION_LOOSE_PARAMETERS cannot both be defined.
|
|
#endif
|
|
#endif
|
|
|
|
// This eye adaptation lookup function is used by the material template. However, post process materials also require
|
|
// it, but are themselves global shaders which can utilize loose parameters instead. Rules for the implementation:
|
|
// - Defining EYE_ADAPTATION_DISABLED will cause it to always return 0.
|
|
// - Defining EyeAdaptationStruct will cause it to pull from that uniform buffer struct.
|
|
// - Defining EYE_ADAPTATION_LOOSE_PARAMETERS will cause it to pull from the loose texture / buffer.
|
|
// - Doing none of the above will fall back to disabled.
|
|
|
|
float EyeAdaptationLookup()
|
|
{
|
|
#if EYE_ADAPTATION_DISABLED
|
|
return 0.0f;
|
|
#elif defined (EyeAdaptationStruct)
|
|
#if SHADING_PATH_DEFERRED
|
|
return EyeAdaptationLookupTexture2D(EyeAdaptationStruct.EyeAdaptationTexture);
|
|
#elif SHADING_PATH_MOBILE
|
|
return EyeAdaptationLookupBuffer(EyeAdaptationStruct.EyeAdaptationBuffer);
|
|
#else
|
|
#error Unknown shading path.
|
|
#endif
|
|
#elif EYE_ADAPTATION_LOOSE_PARAMETERS
|
|
#if SHADING_PATH_DEFERRED
|
|
return EyeAdaptationLookupTexture2D(EyeAdaptationTexture);
|
|
#elif SHADING_PATH_MOBILE
|
|
return EyeAdaptationLookupBuffer(EyeAdaptationBuffer);
|
|
#else
|
|
#error Unknown shading path.
|
|
#endif
|
|
#else
|
|
return 0.0f;
|
|
#endif
|
|
}
|
|
|
|
float3 EyeAdaptationInverseLookup(float3 LightValue, float Alpha)
|
|
{
|
|
float Adaptation = EyeAdaptationLookup();
|
|
|
|
// When Alpha=0.0, we want to multiply by 1.0. when Alpha = 1.0, we want to multiply by 1/Adaptation.
|
|
// So the lerped value is:
|
|
// LerpLogScale = Lerp(log(1),log(1/Adaptaiton),T)
|
|
// Which is simplified as:
|
|
// LerpLogScale = Lerp(0,-log(Adaptation),T)
|
|
// LerpLogScale = -T * logAdaptation;
|
|
|
|
float LerpLogScale = -Alpha * log(Adaptation);
|
|
float Scale = exp(LerpLogScale);
|
|
return LightValue * Scale;
|
|
}
|
|
|
|
|
|
|