Add option to disable shadows on transparent material

This commit is contained in:
2026-04-09 14:47:39 +02:00
parent 095cfcdde2
commit 1d3d20e6c5
6 changed files with 27 additions and 0 deletions
@@ -88,8 +88,12 @@ void PS_Forward(
gBuffer.ShadingModel = MATERIAL_SHADING_MODEL; gBuffer.ShadingModel = MATERIAL_SHADING_MODEL;
// Calculate lighting from a single directional light // Calculate lighting from a single directional light
#if LIGHTING_NO_SHADOW
float4 shadowMask = (float4)1;
#else
ShadowSample shadow = SampleDirectionalLightShadow(DirectionalLight, ShadowsBuffer, ShadowMap, gBuffer); ShadowSample shadow = SampleDirectionalLightShadow(DirectionalLight, ShadowsBuffer, ShadowMap, gBuffer);
float4 shadowMask = GetShadowMask(shadow); float4 shadowMask = GetShadowMask(shadow);
#endif
float4 light = GetLighting(ViewPos, DirectionalLight, gBuffer, shadowMask, false, false); float4 light = GetLighting(ViewPos, DirectionalLight, gBuffer, shadowMask, false, false);
// Calculate lighting from sky light // Calculate lighting from sky light
@@ -92,6 +92,9 @@ namespace FlaxEditor.Windows.Assets
[EditorOrder(220), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables distortion effect when rendering.")] [EditorOrder(220), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables distortion effect when rendering.")]
public bool EnableDistortion; 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).")] [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; public bool EnableGlobalIllumination;
@@ -166,6 +169,7 @@ namespace FlaxEditor.Windows.Assets
EnableScreenSpaceReflections = (info.FeaturesFlags & MaterialFeaturesFlags.ScreenSpaceReflections) != 0; EnableScreenSpaceReflections = (info.FeaturesFlags & MaterialFeaturesFlags.ScreenSpaceReflections) != 0;
EnableFog = (info.FeaturesFlags & MaterialFeaturesFlags.DisableFog) == 0; EnableFog = (info.FeaturesFlags & MaterialFeaturesFlags.DisableFog) == 0;
EnableDistortion = (info.FeaturesFlags & MaterialFeaturesFlags.DisableDistortion) == 0; EnableDistortion = (info.FeaturesFlags & MaterialFeaturesFlags.DisableDistortion) == 0;
EnableShadows = (info.FeaturesFlags & MaterialFeaturesFlags.DisableShadows) == 0;
EnableGlobalIllumination = (info.FeaturesFlags & MaterialFeaturesFlags.GlobalIllumination) != 0; EnableGlobalIllumination = (info.FeaturesFlags & MaterialFeaturesFlags.GlobalIllumination) != 0;
PixelNormalOffsetRefraction = (info.FeaturesFlags & MaterialFeaturesFlags.PixelNormalOffsetRefraction) != 0; PixelNormalOffsetRefraction = (info.FeaturesFlags & MaterialFeaturesFlags.PixelNormalOffsetRefraction) != 0;
InputWorldSpaceNormal = (info.FeaturesFlags & MaterialFeaturesFlags.InputWorldSpaceNormal) != 0; InputWorldSpaceNormal = (info.FeaturesFlags & MaterialFeaturesFlags.InputWorldSpaceNormal) != 0;
@@ -207,6 +211,8 @@ namespace FlaxEditor.Windows.Assets
info.FeaturesFlags |= MaterialFeaturesFlags.DisableFog; info.FeaturesFlags |= MaterialFeaturesFlags.DisableFog;
if (!EnableDistortion) if (!EnableDistortion)
info.FeaturesFlags |= MaterialFeaturesFlags.DisableDistortion; info.FeaturesFlags |= MaterialFeaturesFlags.DisableDistortion;
if (!EnableShadows)
info.FeaturesFlags |= MaterialFeaturesFlags.DisableShadows;
if (EnableGlobalIllumination) if (EnableGlobalIllumination)
info.FeaturesFlags |= MaterialFeaturesFlags.GlobalIllumination; info.FeaturesFlags |= MaterialFeaturesFlags.GlobalIllumination;
if (PixelNormalOffsetRefraction) if (PixelNormalOffsetRefraction)
@@ -506,6 +506,8 @@ void Material::InitCompilationOptions(ShaderCompilationOptions& options)
options.Macros.Add({ "USE_REFLECTIONS", Numbers[EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::DisableReflections) ? 0 : 1] }); options.Macros.Add({ "USE_REFLECTIONS", Numbers[EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::DisableReflections) ? 0 : 1] });
if (!(info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::ScreenSpaceReflections)) if (!(info.FeaturesFlags & MaterialFeaturesFlags::DisableReflections) && EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::ScreenSpaceReflections))
options.Macros.Add({ "MATERIAL_REFLECTIONS", Numbers[1] }); 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] }); options.Macros.Add({ "USE_FOG", Numbers[EnumHasAnyFlags(info.FeaturesFlags, MaterialFeaturesFlags::DisableFog) ? 0 : 1] });
if (useForward) if (useForward)
{ {
@@ -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. /// The flag used to enable sampling Global Illumination in material (eg. light probes or volumetric lightmap). The Forward Pass materials option.
/// </summary> /// </summary>
GlobalIllumination = 1 << 11, GlobalIllumination = 1 << 11,
/// <summary>
/// The flag used to disable shadow maps sampling when shading object with a light. The Forward Pass materials option.
/// </summary>
DisableShadows = 1 << 12,
}; };
DECLARE_ENUM_OPERATORS(MaterialFeaturesFlags); DECLARE_ENUM_OPERATORS(MaterialFeaturesFlags);
+5
View File
@@ -8,8 +8,13 @@
ShadowSample GetShadow(LightData lightData, GBufferSample gBuffer, float4 shadowMask) ShadowSample GetShadow(LightData lightData, GBufferSample gBuffer, float4 shadowMask)
{ {
ShadowSample shadow; ShadowSample shadow;
#if LIGHTING_NO_SHADOW
shadow.SurfaceShadow = gBuffer.AO;
shadow.TransmissionShadow = 1.0f;
#else
shadow.SurfaceShadow = gBuffer.AO * shadowMask.r; shadow.SurfaceShadow = gBuffer.AO * shadowMask.r;
shadow.TransmissionShadow = shadowMask.g; shadow.TransmissionShadow = shadowMask.g;
#endif
return shadow; return shadow;
} }
+5
View File
@@ -16,6 +16,11 @@
#define LIGHTING_NO_SPECULAR 0 #define LIGHTING_NO_SPECULAR 0
#endif #endif
// Disables shadows
#ifndef LIGHTING_NO_SHADOW
#define LIGHTING_NO_SHADOW 0
#endif
// Structure that contains information about light // Structure that contains information about light
struct LightData struct LightData
{ {