Fix color grading lut to be refreshed when shader gets reloaded
This commit is contained in:
Binary file not shown.
@@ -47,6 +47,9 @@ public:
|
|||||||
Data CachedData;
|
Data CachedData;
|
||||||
ToneMappingMode Mode = ToneMappingMode::None;
|
ToneMappingMode Mode = ToneMappingMode::None;
|
||||||
Texture* LutTexture = nullptr;
|
Texture* LutTexture = nullptr;
|
||||||
|
#if COMPILE_WITH_DEV_ENV
|
||||||
|
uint64 FrameRendered = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
~ColorGradingCustomBuffer()
|
~ColorGradingCustomBuffer()
|
||||||
{
|
{
|
||||||
@@ -54,6 +57,17 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if COMPILE_WITH_DEV_ENV
|
||||||
|
|
||||||
|
void ColorGradingPass::OnShaderReloading(Asset* obj)
|
||||||
|
{
|
||||||
|
_psLut.Release();
|
||||||
|
invalidateResources();
|
||||||
|
_reloadedFrame = Engine::FrameCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
String ColorGradingPass::ToString() const
|
String ColorGradingPass::ToString() const
|
||||||
{
|
{
|
||||||
return TEXT("ColorGradingPass");
|
return TEXT("ColorGradingPass");
|
||||||
@@ -194,6 +208,9 @@ GPUTexture* ColorGradingPass::RenderLUT(RenderContext& renderContext)
|
|||||||
// Check if LUT parameter hasn't been changed since the last time
|
// Check if LUT parameter hasn't been changed since the last time
|
||||||
if (Platform::MemoryCompare(&colorGradingBuffer.CachedData , &data, sizeof(Data)) == 0 &&
|
if (Platform::MemoryCompare(&colorGradingBuffer.CachedData , &data, sizeof(Data)) == 0 &&
|
||||||
colorGradingBuffer.Mode == toneMapping.Mode &&
|
colorGradingBuffer.Mode == toneMapping.Mode &&
|
||||||
|
#if COMPILE_WITH_DEV_ENV
|
||||||
|
colorGradingBuffer.FrameRendered > _reloadedFrame &&
|
||||||
|
#endif
|
||||||
Engine::FrameCount > 30 && // Skip caching when engine is starting TODO: find why this hack is needed
|
Engine::FrameCount > 30 && // Skip caching when engine is starting TODO: find why this hack is needed
|
||||||
colorGradingBuffer.LutTexture == lutTexture)
|
colorGradingBuffer.LutTexture == lutTexture)
|
||||||
{
|
{
|
||||||
@@ -203,6 +220,9 @@ GPUTexture* ColorGradingPass::RenderLUT(RenderContext& renderContext)
|
|||||||
colorGradingBuffer.CachedData = data;
|
colorGradingBuffer.CachedData = data;
|
||||||
colorGradingBuffer.Mode = toneMapping.Mode;
|
colorGradingBuffer.Mode = toneMapping.Mode;
|
||||||
colorGradingBuffer.LutTexture = lutTexture;
|
colorGradingBuffer.LutTexture = lutTexture;
|
||||||
|
#if COMPILE_WITH_DEV_ENV
|
||||||
|
colorGradingBuffer.FrameRendered = Engine::FrameCount;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Render LUT
|
// Render LUT
|
||||||
PROFILE_GPU("Color Grading LUT");
|
PROFILE_GPU("Color Grading LUT");
|
||||||
|
|||||||
@@ -25,11 +25,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
#if COMPILE_WITH_DEV_ENV
|
#if COMPILE_WITH_DEV_ENV
|
||||||
void OnShaderReloading(Asset* obj)
|
uint64 _reloadedFrame = 0;
|
||||||
{
|
void OnShaderReloading(Asset* obj);
|
||||||
_psLut.Release();
|
|
||||||
invalidateResources();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -164,16 +164,14 @@ float3 TonemapACES(float3 linearColor)
|
|||||||
// The code was originally written by Stephen Hill (@self_shadow).
|
// The code was originally written by Stephen Hill (@self_shadow).
|
||||||
|
|
||||||
// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
|
// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT
|
||||||
static const float3x3 ACESInputMat =
|
static const float3x3 ACESInputMat = {
|
||||||
{
|
|
||||||
{0.59719, 0.35458, 0.04823},
|
{0.59719, 0.35458, 0.04823},
|
||||||
{0.07600, 0.90834, 0.01566},
|
{0.07600, 0.90834, 0.01566},
|
||||||
{0.02840, 0.13383, 0.83777}
|
{0.02840, 0.13383, 0.83777}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ODT_SAT => XYZ => D60_2_D65 => sRGB
|
// ODT_SAT => XYZ => D60_2_D65 => sRGB
|
||||||
static const float3x3 ACESOutputMat =
|
static const float3x3 ACESOutputMat = {
|
||||||
{
|
|
||||||
{ 1.60475, -0.53108, -0.07367},
|
{ 1.60475, -0.53108, -0.07367},
|
||||||
{-0.10208, 1.10813, -0.00605},
|
{-0.10208, 1.10813, -0.00605},
|
||||||
{-0.00327, -0.07276, 1.07602}
|
{-0.00327, -0.07276, 1.07602}
|
||||||
@@ -188,6 +186,7 @@ float3 TonemapACES(float3 linearColor)
|
|||||||
color = a / b;
|
color = a / b;
|
||||||
|
|
||||||
color = mul(ACESOutputMat, color);
|
color = mul(ACESOutputMat, color);
|
||||||
|
|
||||||
return saturate(color);
|
return saturate(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ float4 FastTonemapInvert(float4 c)
|
|||||||
return float4(FastTonemapInvert(c.rgb), c.a);
|
return float4(FastTonemapInvert(c.rgb), c.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
float LinearToSrgbChannel(float linearColor)
|
float LinearToSrgb(float linearColor)
|
||||||
{
|
{
|
||||||
if (linearColor < 0.00313067)
|
if (linearColor < 0.00313067)
|
||||||
return linearColor * 12.92;
|
return linearColor * 12.92;
|
||||||
@@ -46,10 +46,7 @@ float LinearToSrgbChannel(float linearColor)
|
|||||||
|
|
||||||
float3 LinearToSrgb(float3 linearColor)
|
float3 LinearToSrgb(float3 linearColor)
|
||||||
{
|
{
|
||||||
return float3(
|
return float3(LinearToSrgb(linearColor.r), LinearToSrgb(linearColor.g), LinearToSrgb(linearColor.b));
|
||||||
LinearToSrgbChannel(linearColor.r),
|
|
||||||
LinearToSrgbChannel(linearColor.g),
|
|
||||||
LinearToSrgbChannel(linearColor.b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 sRGBToLinear(float3 color)
|
float3 sRGBToLinear(float3 color)
|
||||||
|
|||||||
Reference in New Issue
Block a user