// @return see EDecalRenderStage
EDecalRenderStage FDecalRendering::ComputeRenderStage(EShaderPlatform Platform, EDecalBlendMode DecalBlendMode)
{
	if (IsMobilePlatform(Platform))
	{
		return DRS_ForwardShading;
	}
		
	switch(DecalBlendMode)
	{
		case DBM_DBuffer_ColorNormalRoughness:
		case DBM_DBuffer_Color:
		case DBM_DBuffer_ColorNormal:
		case DBM_DBuffer_ColorRoughness:
		case DBM_DBuffer_Normal:
		case DBM_DBuffer_NormalRoughness:
		case DBM_DBuffer_Roughness:
			return DRS_BeforeBasePass;

		case DBM_Translucent:
		case DBM_Stain:
		case DBM_Normal:
		case DBM_Emissive:
			return DRS_BeforeLighting;
		
		case DBM_Volumetric_DistanceFunction:
			return DRS_AfterBasePass;

		default:
			check(0);
	}
	
	return DRS_BeforeBasePass;
}
Exemplo n.º 2
0
void FForwardShadingSceneRenderer::ConditionalResolveSceneDepth(FRHICommandListImmediate& RHICmdList)
{
    FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(RHICmdList);

    SceneContext.ResolveSceneDepthToAuxiliaryTexture(RHICmdList);

#if !PLATFORM_HTML5
    auto ShaderPlatform = ViewFamily.GetShaderPlatform();

    if (IsMobilePlatform(ShaderPlatform)
            && !IsPCPlatform(ShaderPlatform)) // exclude mobile emulation on PC
    {
        bool bSceneDepthInAlpha = (SceneContext.GetSceneColor()->GetDesc().Format == PF_FloatRGBA);
        bool bOnChipDepthFetch = (GSupportsShaderDepthStencilFetch || (bSceneDepthInAlpha && GSupportsShaderFramebufferFetch));

        if (!bOnChipDepthFetch)
        {
            // Only these features require depth texture
            bool bDecals = ViewFamily.EngineShowFlags.Decals && Scene->Decals.Num();
            bool bModulatedShadows = ViewFamily.EngineShowFlags.DynamicShadows && GetShadowQuality() > 0 && bModulatedShadowsInUse;

            if (bDecals || bModulatedShadows)
            {
                // Switch target to force hardware flush current depth to texture
                FTextureRHIRef DummySceneColor = GSystemTextures.BlackDummy->GetRenderTargetItem().TargetableTexture;
                FTextureRHIRef DummyDepthTarget = GSystemTextures.DepthDummy->GetRenderTargetItem().TargetableTexture;
                SetRenderTarget(RHICmdList, DummySceneColor, DummyDepthTarget, ESimpleRenderTargetMode::EUninitializedColorClearDepth, FExclusiveDepthStencil::DepthWrite_StencilWrite);
                RHICmdList.DiscardRenderTargets(true, true, 0);
            }
        }
    }
#endif //!PLATFORM_HTML5
}
// @return DECAL_RENDERTARGET_COUNT for the shader
uint32 FDecalRendering::ComputeRenderTargetCount(EShaderPlatform Platform, ERenderTargetMode RenderTargetMode)
{
	// has to be SceneColor on mobile 
	check(!IsMobilePlatform(Platform) || RenderTargetMode == RTM_SceneColor);

	switch(RenderTargetMode)
	{
		case RTM_SceneColorAndGBuffer:				return 4;
		case RTM_SceneColorAndGBufferDepthWrite:	return 4;
		case RTM_DBuffer:							return 3;
		case RTM_GBufferNormal:						return 1;
		case RTM_SceneColor:						return 1;
	}

	return 0;
}
static bool IsBlendModeSupported(EShaderPlatform Platform, EDecalBlendMode DecalBlendMode)
{
	if (IsMobilePlatform(Platform))
	{
		switch (DecalBlendMode)
		{
			case DBM_Stain:			// Modulate
			case DBM_Emissive:		// Additive
			case DBM_Translucent:	// Translucent
				break;
			default:
				return false;
		}
	}

	return true;
}
FDecalRendering::ERenderTargetMode FDecalRendering::ComputeRenderTargetMode(EShaderPlatform Platform, EDecalBlendMode DecalBlendMode)
{
	if (IsMobilePlatform(Platform))
	{
		return RTM_SceneColor;
	}
	
	switch(DecalBlendMode)
	{
		case DBM_Translucent:
		case DBM_Stain:
			return RTM_SceneColorAndGBuffer;

		case DBM_Normal:
			return RTM_GBufferNormal;

		case DBM_Emissive:
			return RTM_SceneColor;

		case DBM_DBuffer_ColorNormalRoughness:
		case DBM_DBuffer_Color:
		case DBM_DBuffer_ColorNormal:
		case DBM_DBuffer_ColorRoughness:
		case DBM_DBuffer_Normal:
		case DBM_DBuffer_NormalRoughness:
		case DBM_DBuffer_Roughness:
			// can be optimized using less MRT when possible
			return RTM_DBuffer;

		case DBM_Volumetric_DistanceFunction:
			return RTM_SceneColorAndGBufferDepthWrite;
	}

	// add the missing decal blend mode to the switch
	check(0);
	return RTM_Unknown;
}