代码改变世界

shadowDepth变体条件

2023-02-09 18:33  kk20161206  阅读(21)  评论(0编辑  收藏  举报

投射动态shadow函数

inline bool ShouldCastDynamicShadows() const
    {
        return !GetShadingModels().HasOnlyShadingModel(MSM_SingleLayerWater) &&
                (GetBlendMode() == BLEND_Opaque
                  || GetBlendMode() == BLEND_Masked
                   || (GetBlendMode() == BLEND_Translucent && GetCastDynamicShadowAsMasked()));
    }

变量赋值

FMaterialShaderParameters(const FMaterial* InMaterial)
    {
        // Make sure to zero-initialize so we get consistent hashes
        FMemory::Memzero(*this);

        ……
        bShouldCastDynamicShadows = InMaterial->ShouldCastDynamicShadows();

TshadowDepthVS的should函数

/**
* A vertex shader for rendering the depth of a mesh.
*/
template <EShadowDepthVertexShaderMode ShaderMode, bool bRenderReflectiveShadowMap, bool bUsePositionOnlyStream, bool bIsForGeometryShader = false>
class TShadowDepthVS : public FShadowDepthVS
{
    DECLARE_SHADER_TYPE(TShadowDepthVS, MeshMaterial);
public:

    TShadowDepthVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) :
        FShadowDepthVS(Initializer)
    {
    }

    TShadowDepthVS() {}

    static bool ShouldCompilePermutation(const FMeshMaterialShaderPermutationParameters& Parameters)
    {
        const EShaderPlatform Platform = Parameters.Platform;

        static const auto SupportAllShaderPermutationsVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SupportAllShaderPermutations"));
        const bool bForceAllPermutations = SupportAllShaderPermutationsVar && SupportAllShaderPermutationsVar->GetValueOnAnyThread() != 0;
        const bool bSupportPointLightWholeSceneShadows = CVarSupportPointLightWholeSceneShadows.GetValueOnAnyThread() != 0 || bForceAllPermutations;
        const bool bRHISupportsShadowCastingPointLights = RHISupportsGeometryShaders(Platform) || RHISupportsVertexShaderLayer(Platform);

        if (bIsForGeometryShader && ShaderMode == VertexShadowDepth_VSLayer)
        {
            return false;
        }

        if (bIsForGeometryShader && (!bSupportPointLightWholeSceneShadows || !bRHISupportsShadowCastingPointLights))
        {
            return false;
        }

        //Note: This logic needs to stay in sync with OverrideWithDefaultMaterialForShadowDepth!
        // Compile for special engine materials.
        if (bRenderReflectiveShadowMap)
        {
            static const auto SupportLPV = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.LightPropagationVolume"));
            if (SupportLPV && SupportLPV->GetValueOnAnyThread() == 0)
            {
                return false;
            }
            else
            {
                // Reflective shadow map shaders must be compiled for every material because they access the material normal
                return !bUsePositionOnlyStream
                    // Don't render ShadowDepth for translucent unlit materials, unless we're injecting emissive
                    && (Parameters.MaterialParameters.bShouldCastDynamicShadows || Parameters.MaterialParameters.bShouldInjectEmissiveIntoLPV || Parameters.MaterialParameters.bShouldBlockGI)
                    && IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
            }
        }
        else
        {
            return (Parameters.MaterialParameters.bIsSpecialEngineMaterial
                // Masked and WPO materials need their shaders but cannot be used with a position only stream.
                || ((!Parameters.MaterialParameters.bWritesEveryPixelShadowPass || Parameters.MaterialParameters.bMaterialMayModifyMeshPosition) && !bUsePositionOnlyStream))
                // Only compile one pass point light shaders for feature levels >= SM5
                && ((ShaderMode != VertexShadowDepth_OnePassPointLight && ShaderMode != VertexShadowDepth_VSLayer) || IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5))
                // Only compile position-only shaders for vertex factories that support it. (Note: this assumes that a vertex factor which supports PositionOnly, supports also PositionAndNormalOnly)
                && (!bUsePositionOnlyStream || Parameters.VertexFactoryType->SupportsPositionOnly())
                // Don't render ShadowDepth for translucent unlit materials
                && Parameters.MaterialParameters.bShouldCastDynamicShadows;
        }
    }

需要材质参数的shouldCastDynamicShadows为true。

Parameters.MaterialParameters.bMaterialMayModifyMeshPosition)来自:

bool FMaterial::MaterialMayModifyMeshPosition() const
{
// Conservative estimate when called before material translation has occurred.
// This function is only intended for use in deciding whether or not shader permutations are required.
return HasVertexPositionOffsetConnected() || HasPixelDepthOffsetConnected() || HasMaterialAttributesConnected() || GetTessellationMode() != MTM_NoTessellation
|| (GetMaterialDomain() == MD_DeferredDecal && GetDecalBlendMode() == DBM_Volumetric_DistanceFunction);
}
连着
PositionOffset或
PixelDepthOffset或
MaterialAttributes