Files
UnrealEngineUWP/Engine/Shaders/Private/ClearCoatCommon.ush
jon nabozny b278addb8d Clamp roughness on clear coat bottom reflection to the range that screen probes can give good quality at
FastUpdateMode uses a single frame history to stabilize and propagate lighting changes to where the object used to be last frame
Experimental option for FastUpdateMode to use neighborhood clamp, disabled for now
Experimental option for Screen Space Bent Normal to calculate FastUpdateMode, costs too much
#rb Patrick.Kelly
#preflight 615b77a998985b0001a2f0bc
#lockdown Michal.Valient

#ROBOMERGE-OWNER: jon.nabozny
#ROBOMERGE-AUTHOR: daniel.wright
#ROBOMERGE-SOURCE: CL 17716674 via CL 17978839 via CL 18366648 via CL 18366728
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v895-18170469)

[CL 18366785 by jon nabozny in ue5-release-engine-test branch]
2021-12-03 02:43:50 -05:00

75 lines
3.0 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
float3 GetClearCoatBottomNormal(FGBufferData GBuffer, float3 WorldNormal)
{
if (GBuffer.ShadingModelID == SHADINGMODELID_CLEAR_COAT && CLEAR_COAT_BOTTOM_NORMAL)
{
const float2 oct1 = ((float2(GBuffer.CustomData.a, GBuffer.CustomData.z) * 4) - (512.0 / 255.0)) + UnitVectorToOctahedron(WorldNormal);
WorldNormal = OctahedronToUnitVector(oct1);
}
return WorldNormal;
}
float GetClearCoatRoughness(FGBufferData GBuffer)
{
return GBuffer.ShadingModelID == SHADINGMODELID_CLEAR_COAT ? GBuffer.CustomData.y : GBuffer.Roughness;
}
void RemapClearCoatDiffuseAndSpecularColor(FGBufferData GBuffer, float NoV, inout float3 DiffuseColor, inout float3 SpecularColor)
{
if (GBuffer.ShadingModelID == SHADINGMODELID_CLEAR_COAT)
{
// Attenuate base color and recompute diffuse color
float RefractionScale = ((NoV * 0.5 + 0.5) * NoV - 1) * saturate(1.25 - 1.25 * GBuffer.Roughness) + 1;
float MetalSpec = 0.9;
float3 AbsorptionColor = GBuffer.BaseColor * (1 / MetalSpec);
float3 Absorption = AbsorptionColor * ((NoV - 1) * 0.85 * (1 - lerp(AbsorptionColor, Square(AbsorptionColor), -0.78)) + 1);
float F0 = 0.04;
float Fc = Pow5(1 - NoV);
float F = Fc + (1 - Fc) * F0;
float ClearCoat = GBuffer.CustomData.x;
float LayerAttenuation = lerp(1, (1 - F), ClearCoat);
float3 BaseColor = lerp(GBuffer.BaseColor * LayerAttenuation, MetalSpec * Absorption * RefractionScale, GBuffer.Metallic * ClearCoat);
//BaseColor += Dither / 255.f;
DiffuseColor = BaseColor - BaseColor * GBuffer.Metallic;
float Specular = lerp(GBuffer.Specular, RefractionScale, ClearCoat);
SpecularColor = ComputeF0(Specular, BaseColor, GBuffer.Metallic) * View.SpecularOverrideParameter.w + View.SpecularOverrideParameter.xyz;
}
}
void RemapClearCoatDiffuseAndSpecularColor(FGBufferData GBuffer, float2 ScreenPosition, inout float3 DiffuseColor, inout float3 SpecularColor)
{
if (GBuffer.ShadingModelID == SHADINGMODELID_CLEAR_COAT)
{
float3 TranslatedWorldPosition = mul(float4(ScreenPosition * GBuffer.Depth, GBuffer.Depth, 1), View.ScreenToTranslatedWorld).xyz;
float3 CameraToPixel = normalize(TranslatedWorldPosition - PrimaryView.TranslatedWorldCameraOrigin);
float3 V = -CameraToPixel;
float NoV = saturate(dot(GBuffer.WorldNormal, V));
RemapClearCoatDiffuseAndSpecularColor(GBuffer, NoV, DiffuseColor, SpecularColor);
}
}
float3 ClearCoatLayerCombine(FGBufferData GBuffer, float NoV, float3 TopLayerReflections, float3 BottomLayerReflections, float3 SpecularColor)
{
const float ClearCoat = GBuffer.CustomData.x;
const float ClearCoatRoughness = GBuffer.CustomData.y;
// TODO EnvBRDF should have a mask param
float2 AB = PreIntegratedGF.SampleLevel( PreIntegratedGFSampler, float2( NoV, GBuffer.Roughness ), 0 ).rg;
BottomLayerReflections *= SpecularColor * AB.x + AB.y * saturate( 50 * SpecularColor.g ) * (1 - ClearCoat);
// F_Schlick
float F = EnvBRDF( 0.04, ClearCoatRoughness, NoV ).x;
F *= ClearCoat;
return BottomLayerReflections * (1 - F) + TopLayerReflections * F;
}