Files
UnrealEngineUWP/Engine/Shaders/PostProcessHistogramCommon.usf
Gil Gribb 2e5b4cbbd1 Copying //UE4/Dev-Rendering to Dev-Main (//UE4/Dev-Main)
#lockdown nick.penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 2821445 on 2016/01/08 by Olaf.Piesche
	More vertex factory improvements, storing off particle vertex factories on the scene proxy instead of the dynamic data to avoid recreating all the time; saves up to 2ms render thread time according to QA's testing.

	#rb martin.mittring

Change 2821520 on 2016/01/08 by Olaf.Piesche

	Coloring subuv modules green for easier visual ID

	#rb martin.mittring

Change 2823479 on 2016/01/11 by Chris.Bunner

	Updated Lightmass HLOD logic to avoid HLODs shadowing non-related meshes. Duplicated CL#2823104 from Dev-General.

Change 2823570 on 2016/01/11 by Zabir.Hoque

	Introduce multiplier that controls decal fade speed.

	#CodeReview: Martin.Mittring
	#1777

Change 2823615 on 2016/01/11 by Uriel.Doyon

	Fixed stencil ref multithreading issue.
	Fixed state caching when depth range is enabled.
	#jira UE-24564
	#review marcus.wassmer

Change 2823652 on 2016/01/11 by Zabir.Hoque

	Rename FadeSpeedScale -> FadeDurationScale to be logically more consistent.

	#CodeReview: Martin.Mittring

Change 2824065 on 2016/01/11 by Brian.Karis

	Fixed last viewrect motion blur bug. Enabled new motion blur algorithm for default.

Change 2825432 on 2016/01/12 by Zabir.Hoque

	Store off view matrices at at time of freezing and base lod selection useing relevant matrices, thus allows lods to be frozen. #OR-10918

	#CodeReview: Marcus.Wassmer, Rolando.Caloca, Martin.Mittring

Change 2825971 on 2016/01/12 by Brian.Karis

	New motion blur enabled.

Change 2825974 on 2016/01/12 by Brian.Karis

	Fixed refraction check value. 1 does nothing not 0.

Change 2825975 on 2016/01/12 by Brian.Karis

	Cloth gets skylight for movable sky.

Change 2827519 on 2016/01/13 by Zabir.Hoque

	ALLOW_UAV_CONDITION did not have a safe fallback when not SM5.0 && COMPILER_SUPPORTS_ATTRIBUTES.

	#CodeReview Martin.Mittring, Rolando.Caloca

Change 2830172 on 2016/01/15 by Rolando.Caloca

	DR - Minor cleanup
	- Renamed Vertex Factories' struct Data to struct FData
	- Removed Data type on FVertexFactory

Change 2830242 on 2016/01/15 by Rolando.Caloca

	DR - Prep cleanup for gpu morph targets
	- Split common code for  GPU skin cache into a base class
	- Moved some local static arrays from UpdateMorphVertexBuffer() to static members
	#codereview Lina.Halper

Change 2830455 on 2016/01/15 by Rolando.Caloca

	DR - Compile fix from bad merge
	#jira UE-25557

Change 2832023 on 2016/01/18 by Rolando.Caloca

	DR - Removed TangentZDelta_DEPRECATED from FVertexAnimDelta
	#rb Marcus.Wassmer
	#codereview Lina.Halper

Change 2832067 on 2016/01/18 by Gil.Gribb

	UE4 - Changed PC to default to parallel rendering when not in editor. Fixed lack of a stall on texture locks and unlocks coming from texture streamer. Fixed a few cases where stuff was being added to rhicommandlists even when we were bypassed.

Change 2834379 on 2016/01/19 by Gil.Gribb

	UE4 - fix perf regression related to cvar

Change 2834864 on 2016/01/19 by Olaf.Piesche

	Fixing potential crash with auto-kill trail emitters, fixing use of the wrong flag to auto-deactivate

	#codereview gil.gribb

Change 2835777 on 2016/01/20 by David.Hill

	EyeAdaptation - using a screen center focus in the weights
	#rb Martin Mitring

	related to: UE-15509.  This is adding the ability to focus the basic eye-adaptation region in the center of the screen, and cvar functionality for paragon testing on ps4

Change 2835778 on 2016/01/20 by David.Hill

	EyeAdapation - DefaultFeature for method
	#rb Martin.Mitring
	Adding a default feature cvar for eye adaptation method

Change 2837410 on 2016/01/20 by David.Hill

	OR-13213   SetupPerObjectProjection()
	#test:PC
	#rb:Martin.Mitring
	#codereview:Daniel.Wright

[CL 2845257 by Gil Gribb in Main branch]
2016-01-27 07:18:43 -05:00

145 lines
4.7 KiB
Plaintext

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
PostProcessHistogramCommon.usf: PostProcessing histogram shared functions and structures.
=============================================================================*/
// [0] .x:ExposureLowPercent/100, .y:EyeAdaptationHighPercent/100, .z:EyeAdaptationMin, .w:EyeAdaptationMax
// [1] .x:exp2(ExposureOffset), .y:DeltaWorldTime, .zw: EyeAdaptionSpeedUp/Down
// [2] .x:Histogram multiply, .y:Histogram add, .z:HistogramMinIntensity w:unused
float4 EyeAdaptationParams[3];
// inverse of ComputeLuminanceFromHistogramPosition
// is executed more often than ComputeLuminanceFromHistogramPosition()
// @param Luminance
// @return HistogramPosition 0..1
float ComputeHistogramPositionFromLuminance(float Luminance)
{
return log2(Luminance) * EyeAdaptationParams[2].x + EyeAdaptationParams[2].y;
}
// inverse of ComputeHistogramPositionFromLuminance()
// is not as often executed as ComputeHistogramPositionFromLuminance()
// @param HistogramPosition 0..1
// @return Lumiance
float ComputeLuminanceFromHistogramPosition(float HistogramPosition)
{
return exp2( (HistogramPosition - EyeAdaptationParams[2].y) / EyeAdaptationParams[2].x );
}
#define HISTOGRAM_SIZE 64
#define HISTOGRAM_TEXEL_SIZE (HISTOGRAM_SIZE / 4)
float4 ComputeARGBStripeMaskInt(uint x)
{
#if ES2_PROFILE
// Integer modulo/remainder is not an allowed operation on ES 2
// todo: move function to central spot, here we assume unsigned
uint Temp = x - (x / 4) * 4;
return float4(
Temp == 0,
Temp == 1,
Temp == 2,
Temp == 3);
#else
return float4(
(x % 4) == 0,
(x % 4) == 1,
(x % 4) == 2,
(x % 4) == 3);
#endif
}
float GetHistogramBucket(Texture2D HistogramTexture, uint BucketIndex)
{
uint Texel = BucketIndex / 4;
float4 HistogramColor = HistogramTexture.Load(int3(Texel, 0, 0));
// WAR for a GLSL shader compiler bug in the driver
#if 0
float UnweightedValue = dot(HistogramColor, ComputeARGBStripeMaskInt(BucketIndex));
#else
#if ES2_PROFILE
// Integer modulo/remainder is not an allowed operation on ES 2
// todo: move function to central spot, here we assume unsigned
uint channel = BucketIndex - (BucketIndex / 4) * 4;
#else
uint channel = BucketIndex % 4;
#endif
float UnweightedValue = HistogramColor.r;
UnweightedValue = (channel == 1) ? HistogramColor.g : UnweightedValue;
UnweightedValue = (channel == 2) ? HistogramColor.b : UnweightedValue;
UnweightedValue = (channel == 3) ? HistogramColor.a : UnweightedValue;
#endif
// because of the logarithmic scale we need to weight the buckets ?
// return UnweightedValue * pow(2, BucketIndex);
// return UnweightedValue * pow(2, BucketIndex / HISTOGRAM_SIZE * (2 * HDRLogRadius));
return UnweightedValue;
}
float ComputeHistogramSum(Texture2D HistogramTexture)
{
float Sum = 0;
for(uint i = 0; i < HISTOGRAM_SIZE; ++i)
{
Sum += GetHistogramBucket(HistogramTexture, i);
}
return Sum;
}
// @param MinFractionSum e.g. ComputeHistogramSum() * 0.5f for 50% percentil
// @param MaxFractionSum e.g. ComputeHistogramSum() * 0.9f for 90% percentil
float ComputeAverageLuminaneWithoutOutlier(Texture2D HistogramTexture, float MinFractionSum, float MaxFractionSum)
{
float2 SumWithoutOutliers = 0;
UNROLL for(uint i = 0; i < HISTOGRAM_SIZE; ++i)
{
float LocalValue = GetHistogramBucket(HistogramTexture, i);
// remove outlier at lower end
float Sub = min(LocalValue, MinFractionSum);
LocalValue = LocalValue - Sub;
MinFractionSum -= Sub;
MaxFractionSum -= Sub;
// remove outlier at upper end
LocalValue = min(LocalValue, MaxFractionSum);
MaxFractionSum -= LocalValue;
float LuminanceAtBucket = ComputeLuminanceFromHistogramPosition(i / (float)HISTOGRAM_SIZE);
SumWithoutOutliers += float2(LuminanceAtBucket, 1) * LocalValue;
}
return SumWithoutOutliers.x / max(0.0001f, SumWithoutOutliers.y);
}
// used by bloom and tonemapper VS
// requires EyeAdaptationParams to be set
float ComputeEyeAdaptationExposure(Texture2D HistogramTexture)
{
float HistogramSum = ComputeHistogramSum(HistogramTexture);
float UnclampedAdaptedLuminance = ComputeAverageLuminaneWithoutOutlier(HistogramTexture, HistogramSum * EyeAdaptationParams[0].x, HistogramSum * EyeAdaptationParams[0].y);
float ClampedAdaptedLuminance = clamp(UnclampedAdaptedLuminance, EyeAdaptationParams[0].z, EyeAdaptationParams[0].w);
return ClampedAdaptedLuminance;
}
// Computation of triangle function on normalized space
// used in Basic EyeAdaptation in weighting the center of the screen
// @return range of 0..1 with 1 nx = 0.5
// @param nx in 0..1
// @param slope assumed possitive
float AdaptationWeight(float nx, float slope)
{
return max(1.f - 2. * slope * abs(nx - 0.5f), 0.0f);
}