Skip to content

Commit ea695b6

Browse files
author
YOung
committed
Support SeparateTranslucencyScreenPercentage on mobile platforms.
1 parent 1a24cb3 commit ea695b6

32 files changed

Lines changed: 406 additions & 192 deletions

Engine/Shaders/Private/DownsampleDepthPixelShader.usf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define DOWNSAMPLE_DEPTH_FILTER_CBMINMAX 2
1414

1515
Texture2D<float> DepthTexture;
16+
SamplerState DepthTexturePointClampedSampler;
1617
float4 SourceTexelOffsets01;
1718
float4 SourceTexelOffsets23;
1819
float2 SourceMaxUV;
@@ -21,7 +22,7 @@ uint DownsampleDepthFilter;
2122

2223
float GetDeviceZ(float2 UV)
2324
{
24-
return DepthTexture.Sample(GlobalPointClampedSampler, min(UV, SourceMaxUV));
25+
return DepthTexture.Sample(DepthTexturePointClampedSampler, min(UV, SourceMaxUV));
2526
}
2627

2728
void Main(

Engine/Shaders/Private/SeparateTranslucency.ush

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
Texture2D<float> LowResDepthTexture;
1010
Texture2D<float> FullResDepthTexture;
1111

12+
SamplerState PointClampedSampler;
13+
SamplerState BilinearClampedSampler;
14+
1215
void UpdateNearestSample(float Z, float2 UV, float FullResZ, inout float MinDist, inout float2 NearestUV)
1316
{
1417
float DepthDelta = abs(Z - FullResZ);
@@ -23,7 +26,7 @@ void UpdateNearestSample(float Z, float2 UV, float FullResZ, inout float MinDist
2326

2427
float4 BilinearUpsampling(float2 UV, Texture2D LowResTex)
2528
{
26-
return Texture2DSample(LowResTex, GlobalBilinearClampedSampler, UV);
29+
return Texture2DSample(LowResTex, BilinearClampedSampler, UV);
2730
}
2831

2932
float4 NearestDepthNeighborUpsampling(float2 Position, float2 UV, Texture2D LowResTex, float2 LowResTexelSize)
@@ -35,7 +38,7 @@ float4 NearestDepthNeighborUpsampling(float2 Position, float2 UV, Texture2D LowR
3538
float MaxOperationDepth = 2000000.0f;
3639

3740
// Note: this upsample is specialized for half res to full res
38-
float4 LowResDepthBuffer = LowResDepthTexture.GatherRed(GlobalBilinearClampedSampler, UV);
41+
float4 LowResDepthBuffer = LowResDepthTexture.GatherRed(BilinearClampedSampler, UV);
3942
float4 LowResDepth = min(float4(ConvertFromDeviceZ(LowResDepthBuffer.x), ConvertFromDeviceZ(LowResDepthBuffer.y), ConvertFromDeviceZ(LowResDepthBuffer.z), ConvertFromDeviceZ(LowResDepthBuffer.w)), MaxOperationDepth.xxxx);
4043
float FullResDepth = min(ConvertFromDeviceZ(FullResDepthTexture[uint2(Position.xy)].x), MaxOperationDepth);
4144

@@ -66,18 +69,18 @@ float4 NearestDepthNeighborUpsampling(float2 Position, float2 UV, Texture2D LowR
6669
&& abs(LowResDepth.x - FullResDepth) * InvFullResDepth < RelativeDepthThreshold
6770
&& abs(LowResDepth.y - FullResDepth) * InvFullResDepth < RelativeDepthThreshold)
6871
{
69-
Output = Texture2DSampleLevel(LowResTex, GlobalBilinearClampedSampler, UV, 0);
72+
Output = Texture2DSampleLevel(LowResTex, BilinearClampedSampler, UV, 0);
7073
}
7174
else
7275
{
73-
Output = Texture2DSampleLevel(LowResTex, GlobalPointClampedSampler, NearestUV, 0);
76+
Output = Texture2DSampleLevel(LowResTex, PointClampedSampler, NearestUV, 0);
7477
}
7578

7679
return Output;
7780

7881
#else
7982

80-
return Texture2DSample(LowResTex, GlobalBilinearClampedSampler, UV);
83+
return Texture2DSample(LowResTex, BilinearClampedSampler, UV);
8184

8285
#endif
8386
}

Engine/Source/Runtime/Engine/Private/Materials/MaterialInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ FMaterialRelevance UMaterialInterface::GetRelevance_Internal(const UMaterial* Ma
211211
{
212212
// Check whether the material can be drawn in the separate translucency pass as per FMaterialResource::IsTranslucencyAfterDOFEnabled and IsMobileSeparateTranslucencyEnabled
213213
bool bSupportsSeparateTranslucency = Material->MaterialDomain != MD_UI && Material->MaterialDomain != MD_DeferredDecal;
214-
bool bMaterialSeparateTranslucency = bSupportsSeparateTranslucency && (bIsMobile ? Material->bEnableMobileSeparateTranslucency : Material->bEnableSeparateTranslucency);
214+
bool bMaterialSeparateTranslucency = bSupportsSeparateTranslucency && Material->bEnableSeparateTranslucency;
215215

216216
// If dual blending is supported, and we are rendering separate translucency, then we also need to render a second pass to the modulation buffer.
217217
// The modulation buffer can also be used for regular modulation shaders after DoF.

Engine/Source/Runtime/Renderer/Private/DepthRendering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ClearQuad.h"
2929
#include "GPUSkinCache.h"
3030
#include "MeshPassProcessor.inl"
31+
#include "MobileShadingRenderer.h"
3132

3233
static TAutoConsoleVariable<int32> CVarParallelPrePass(
3334
TEXT("r.ParallelPrePass"),

Engine/Source/Runtime/Renderer/Private/EditorPrimitivesRendering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void FEditorPrimitivesBasePassMeshProcessor::ProcessMobileShadingPath(const FMes
134134

135135
if (bTranslucentBasePass)
136136
{
137-
MobileBasePass::SetTranslucentRenderState(DrawRenderState, Material);
137+
MobileBasePass::SetTranslucentRenderState(DrawRenderState, Material, ETranslucencyPass::TPT_AllTranslucency);
138138
}
139139

140140
const FMeshDrawingPolicyOverrideSettings OverrideSettings = ComputeMeshOverrideSettings(MeshBatch);

Engine/Source/Runtime/Renderer/Private/MobileBasePass.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,14 @@ void MobileBasePass::SetOpaqueRenderState(FMeshPassProcessorRenderState& DrawRen
374374
}
375375
}
376376

377-
void MobileBasePass::SetTranslucentRenderState(FMeshPassProcessorRenderState& DrawRenderState, const FMaterial& Material)
377+
void MobileBasePass::SetTranslucentRenderState(FMeshPassProcessorRenderState& DrawRenderState, const FMaterial& Material, ETranslucencyPass::Type InTranslucencyPassType)
378378
{
379379
const bool bIsUsingMobilePixelProjectedReflection = Material.IsUsingPlanarForwardReflections() && IsUsingMobilePixelProjectedReflection(GetFeatureLevelShaderPlatform(Material.GetFeatureLevel()));
380380

381+
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataFloat(TEXT("r.SeparateTranslucencyScreenPercentage"));
382+
const float DownsampleScale = CVar ? FMath::Clamp(CVar->GetValueOnRenderThread() / 100.0f, 0.0f, 1.0f) : 1.0f;
383+
const bool bSeparateTranslucencyActive = IsMobileSeparateTranslucencyColorTextureEnabled(InTranslucencyPassType, DownsampleScale);
384+
381385
if (Material.GetShadingModels().HasShadingModel(MSM_ThinTranslucent))
382386
{
383387
// the mobile thin translucent fallback uses a similar mode as BLEND_Translucent, but multiplies color by 1 insead of SrcAlpha.
@@ -394,20 +398,28 @@ void MobileBasePass::SetTranslucentRenderState(FMeshPassProcessorRenderState& Dr
394398
}
395399
else
396400
{
397-
DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_SourceAlpha, BF_InverseSourceAlpha, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI());
401+
bSeparateTranslucencyActive
402+
? DrawRenderState.SetBlendState(TStaticBlendState<CW_RGBA, BO_Add, BF_SourceAlpha, BF_InverseSourceAlpha, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI())
403+
: DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_SourceAlpha, BF_InverseSourceAlpha, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI());
398404
}
399405
break;
400406
case BLEND_Additive:
401407
// Add to the existing scene color
402-
DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_One, BF_One, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI());
408+
bSeparateTranslucencyActive
409+
? DrawRenderState.SetBlendState(TStaticBlendState<CW_RGBA, BO_Add, BF_One, BF_One, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI())
410+
: DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_One, BF_One, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI());
403411
break;
404412
case BLEND_Modulate:
405413
// Modulate with the existing scene color
406-
DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_DestColor, BF_Zero>::GetRHI());
414+
bSeparateTranslucencyActive
415+
? DrawRenderState.SetBlendState(TStaticBlendState<CW_RGBA, BO_Add, BF_DestColor, BF_Zero>::GetRHI())
416+
: DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_DestColor, BF_Zero>::GetRHI());
407417
break;
408418
case BLEND_AlphaComposite:
409419
// Blend with existing scene color. New color is already pre-multiplied by alpha.
410-
DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_One, BF_InverseSourceAlpha, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI());
420+
bSeparateTranslucencyActive
421+
? DrawRenderState.SetBlendState(TStaticBlendState<CW_RGBA, BO_Add, BF_One, BF_InverseSourceAlpha, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI())
422+
: DrawRenderState.SetBlendState(TStaticBlendState<CW_RGB, BO_Add, BF_One, BF_InverseSourceAlpha, BO_Add, BF_Zero, BF_InverseSourceAlpha>::GetRHI());
411423
break;
412424
case BLEND_AlphaHoldout:
413425
// Blend by holding out the matte shape of the source alpha
@@ -657,8 +669,8 @@ void FMobileBasePassMeshProcessor::AddMeshBatch(const FMeshBatch& RESTRICT MeshB
657669
// Skipping TPT_TranslucencyAfterDOFModulate. That pass is only needed for Dual Blending, which is not supported on Mobile.
658670
bool bShouldDraw = (bIsTranslucent || bUsesWaterMaterial || bIsUsingMobilePixelProjectedReflection) &&
659671
(TranslucencyPassType == ETranslucencyPass::TPT_AllTranslucency
660-
|| (TranslucencyPassType == ETranslucencyPass::TPT_StandardTranslucency && !Material.IsMobileSeparateTranslucencyEnabled())
661-
|| (TranslucencyPassType == ETranslucencyPass::TPT_TranslucencyAfterDOF && Material.IsMobileSeparateTranslucencyEnabled()));
672+
|| TranslucencyPassType == ETranslucencyPass::TPT_StandardTranslucency
673+
|| TranslucencyPassType == ETranslucencyPass::TPT_TranslucencyAfterDOF);
662674

663675
if (bShouldDraw)
664676
{
@@ -735,7 +747,7 @@ void FMobileBasePassMeshProcessor::Process(
735747
{
736748
if (bTranslucentBasePass)
737749
{
738-
MobileBasePass::SetTranslucentRenderState(DrawRenderState, MaterialResource);
750+
MobileBasePass::SetTranslucentRenderState(DrawRenderState, MaterialResource, TranslucencyPassType);
739751
}
740752
else if (bMaskedInEarlyPass)
741753
{

Engine/Source/Runtime/Renderer/Private/MobileBasePassRendering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "FramePro/FrameProProfiler.h"
1919
#include "PostProcess/PostProcessPixelProjectedReflectionMobile.h"
20+
#include "MobileShadingRenderer.h"
2021

2122
// Changing this causes a full shader recompile
2223
static TAutoConsoleVariable<int32> CVarMobileDisableVertexFog(

Engine/Source/Runtime/Renderer/Private/MobileBasePassRendering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ namespace MobileBasePass
353353
bool StaticCanReceiveCSM(const FLightSceneInfo* LightSceneInfo, const FPrimitiveSceneProxy* PrimitiveSceneProxy);
354354

355355
void SetOpaqueRenderState(FMeshPassProcessorRenderState& DrawRenderState, const FPrimitiveSceneProxy* PrimitiveSceneProxy, const FMaterial& Material, bool bEnableReceiveDecalOutput, bool bUsesDeferredShading);
356-
void SetTranslucentRenderState(FMeshPassProcessorRenderState& DrawRenderState, const FMaterial& Material);
356+
void SetTranslucentRenderState(FMeshPassProcessorRenderState& DrawRenderState, const FMaterial& Material, ETranslucencyPass::Type InTranslucencyPassType);
357357

358358
bool StationarySkyLightHasBeenApplied(const FScene* Scene, ELightMapPolicyType LightMapPolicyType);
359359
};

Engine/Source/Runtime/Renderer/Private/MobileDecalRendering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "SceneRendering.h"
1515
#include "ScenePrivate.h"
1616
#include "DecalRenderingShared.h"
17+
#include "MobileShadingRenderer.h"
1718

1819
extern FRHIRasterizerState* GetDecalRasterizerState(EDecalRasterizerState DecalRasterizerState);
1920
extern void RenderMeshDecalsMobile(FRHICommandList& RHICmdList, const FViewInfo& View);

Engine/Source/Runtime/Renderer/Private/MobileSceneCaptureRendering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ MobileSceneCaptureRendering.cpp - Mobile specific scene capture code.
2828
#include "PipelineStateCache.h"
2929
#include "CommonRenderResources.h"
3030
#include "GenerateMips.h"
31+
#include "MobileShadingRenderer.h"
3132

3233
/**
3334
* Shader set for the copy of scene color to capture target, alpha channel will contain opacity information. (Determined from depth buffer content)

0 commit comments

Comments
 (0)