diff --git a/Content/Editor/MaterialTemplates/Features/ForwardShading.hlsl b/Content/Editor/MaterialTemplates/Features/ForwardShading.hlsl index 29a00c9b7..230c454f4 100644 --- a/Content/Editor/MaterialTemplates/Features/ForwardShading.hlsl +++ b/Content/Editor/MaterialTemplates/Features/ForwardShading.hlsl @@ -88,8 +88,12 @@ void PS_Forward( gBuffer.ShadingModel = MATERIAL_SHADING_MODEL; // Calculate lighting from a single directional light +#if LIGHTING_NO_SHADOW + float4 shadowMask = (float4)1; +#else ShadowSample shadow = SampleDirectionalLightShadow(DirectionalLight, ShadowsBuffer, ShadowMap, gBuffer); float4 shadowMask = GetShadowMask(shadow); +#endif float4 light = GetLighting(ViewPos, DirectionalLight, gBuffer, shadowMask, false, false); // Calculate lighting from sky light diff --git a/Source/Editor/Windows/Assets/MaterialWindow.cs b/Source/Editor/Windows/Assets/MaterialWindow.cs index df227c733..934cd6594 100644 --- a/Source/Editor/Windows/Assets/MaterialWindow.cs +++ b/Source/Editor/Windows/Assets/MaterialWindow.cs @@ -92,6 +92,9 @@ namespace FlaxEditor.Windows.Assets [EditorOrder(220), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables distortion effect when rendering.")] public bool EnableDistortion; + [EditorOrder(221), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables shadows sampling for lights when rendering material.")] + public bool EnableShadows; + [EditorOrder(224), DefaultValue(false), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables sampling Global Illumination in material (eg. light probes or volumetric lightmap).")] public bool EnableGlobalIllumination; @@ -166,6 +169,7 @@ namespace FlaxEditor.Windows.Assets EnableScreenSpaceReflections = (info.FeaturesFlags & MaterialFeaturesFlags.ScreenSpaceReflections) != 0; EnableFog = (info.FeaturesFlags & MaterialFeaturesFlags.DisableFog) == 0; EnableDistortion = (info.FeaturesFlags & MaterialFeaturesFlags.DisableDistortion) == 0; + EnableShadows = (info.FeaturesFlags & MaterialFeaturesFlags.DisableShadows) == 0; EnableGlobalIllumination = (info.FeaturesFlags & MaterialFeaturesFlags.GlobalIllumination) != 0; PixelNormalOffsetRefraction = (info.FeaturesFlags & MaterialFeaturesFlags.PixelNormalOffsetRefraction) != 0; InputWorldSpaceNormal = (info.FeaturesFlags & MaterialFeaturesFlags.InputWorldSpaceNormal) != 0; @@ -207,6 +211,8 @@ namespace FlaxEditor.Windows.Assets info.FeaturesFlags |= MaterialFeaturesFlags.DisableFog; if (!EnableDistortion) info.FeaturesFlags |= MaterialFeaturesFlags.DisableDistortion; + if (!EnableShadows) + info.FeaturesFlags |= MaterialFeaturesFlags.DisableShadows; if (EnableGlobalIllumination) info.FeaturesFlags |= MaterialFeaturesFlags.GlobalIllumination; if (PixelNormalOffsetRefraction) diff --git a/Source/Engine/Content/Assets/Material.cpp b/Source/Engine/Content/Assets/Material.cpp index a508cb2f8..79fd79041 100644 --- a/Source/Engine/Content/Assets/Material.cpp +++ b/Source/Engine/Content/Assets/Material.cpp @@ -506,6 +506,8 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options) options.Macros.Add({ "USE_REFLECTIONS", Numbers[EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::DisableReflections) ? 0 : 1] }); if (!(info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::ScreenSpaceReflections)) options.Macros.Add({ "MATERIAL_REFLECTIONS", Numbers[1] }); + if (useForward && EnumHasAllFlags(info.FeaturesFlags, MaterialFeaturesFlags::DisableShadows)) + options.Macros.Add({ "LIGHTING_NO_SHADOW", Numbers[1] }); options.Macros.Add({ "USE_FOG", Numbers[EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::DisableFog) ? 0 : 1] }); if (useForward) { diff --git a/Source/Engine/Graphics/Materials/MaterialInfo.h b/Source/Engine/Graphics/Materials/MaterialInfo.h index 84771fed8..40314bdd7 100644 --- a/Source/Engine/Graphics/Materials/MaterialInfo.h +++ b/Source/Engine/Graphics/Materials/MaterialInfo.h @@ -286,6 +286,11 @@ API_ENUM(Attributes="Flags") enum class MaterialFeaturesFlags : uint32 /// The flag used to enable sampling Global Illumination in material (eg. light probes or volumetric lightmap). The Forward Pass materials option. /// GlobalIllumination = 1 << 11, + + /// + /// The flag used to disable shadow maps sampling when shading object with a light. The Forward Pass materials option. + /// + DisableShadows = 1 << 12, }; DECLARE_ENUM_OPERATORS(MaterialFeaturesFlags); diff --git a/Source/Shaders/Lighting.hlsl b/Source/Shaders/Lighting.hlsl index 2e3f9dc76..656696a3e 100644 --- a/Source/Shaders/Lighting.hlsl +++ b/Source/Shaders/Lighting.hlsl @@ -8,8 +8,13 @@ ShadowSample GetShadow(LightData lightData, GBufferSample gBuffer, float4 shadowMask) { ShadowSample shadow; +#if LIGHTING_NO_SHADOW + shadow.SurfaceShadow = gBuffer.AO; + shadow.TransmissionShadow = 1.0f; +#else shadow.SurfaceShadow = gBuffer.AO * shadowMask.r; shadow.TransmissionShadow = shadowMask.g; +#endif return shadow; } diff --git a/Source/Shaders/LightingCommon.hlsl b/Source/Shaders/LightingCommon.hlsl index 734b9b709..caa7600a1 100644 --- a/Source/Shaders/LightingCommon.hlsl +++ b/Source/Shaders/LightingCommon.hlsl @@ -16,6 +16,11 @@ #define LIGHTING_NO_SPECULAR 0 #endif +// Disables shadows +#ifndef LIGHTING_NO_SHADOW +#define LIGHTING_NO_SHADOW 0 +#endif + // Structure that contains information about light struct LightData {