Skip to content
Permalink
Browse files

[Rendering] Made LightShafts independent from LightShaftProcessor

  • Loading branch information
xen2 committed Feb 13, 2019
1 parent 921dd9d commit 034abed5674cc05bc9373833e5abf1f0a554a705
Git LFS file not shown
@@ -80,4 +80,7 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Git LFS file not shown
Git LFS file not shown
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
@@ -80,4 +80,7 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Git LFS file not shown
@@ -382,7 +382,7 @@ public static IEnumerable<SerializableItem> GetSerializableItems(TypeDefinition
}
}

private static bool IsMemberIgnored(ICollection<CustomAttribute> customAttributes, ComplexTypeSerializerFlags flags, DataMemberMode dataMemberMode)
internal static bool IsMemberIgnored(ICollection<CustomAttribute> customAttributes, ComplexTypeSerializerFlags flags, DataMemberMode dataMemberMode)
{
// Check for DataMemberIgnore
if (customAttributes.Any(x => x.AttributeType.FullName == "Xenko.Core.DataMemberIgnoreAttribute"))
@@ -17,6 +17,9 @@ public void ProcessSerializers(CecilSerializerContext context)
if (!member.IsStatic || !member.IsPublic)
continue;

if (ComplexSerializerRegistry.IsMemberIgnored(member.CustomAttributes, ComplexTypeSerializerFlags.SerializePublicFields, DataMemberMode.Default))
continue;

if (member.FieldType.Name == "PropertyKey`1"
|| member.FieldType.Name == "ParameterKey`1"
|| member.FieldType.Name == "ValueParameterKey`1"
@@ -16,7 +16,7 @@ namespace Xenko.Engine
/// </summary>
[Display("Light shaft", Expand = ExpandRule.Always)]
[DataContract("LightShaftComponent")]
[DefaultEntityComponentProcessor(typeof(LightShaftProcessor), ExecutionMode = ExecutionMode.All)]
[DefaultEntityComponentRenderer(typeof(LightShaftProcessor))]
public class LightShaftComponent : ActivableEntityComponent
{
/// <summary>
@@ -17,11 +17,7 @@ public class LightShaftBoundingVolumeProcessor : EntityProcessor<LightShaftBound

public override void Update(GameTime time)
{
if (isDirty)
{
UpdateVolumesPerLightShaft();
isDirty = false;
}
RegenerateVolumesPerLightShaft();
}

public IReadOnlyList<RenderLightShaftBoundingVolume> GetBoundingVolumesForComponent(LightShaftComponent component)
@@ -62,9 +58,21 @@ private void ComponentOnLightShaftChanged(object sender, EventArgs eventArgs)
isDirty = true;
}

private void UpdateVolumesPerLightShaft()
private void RegenerateVolumesPerLightShaft()
{
volumesPerLightShaft.Clear();
// Clear
if (isDirty)
{
volumesPerLightShaft.Clear();
}
// Keep existing collections
else
{
foreach (var lightShaft in volumesPerLightShaft)
{
lightShaft.Value.Clear();
}
}

foreach (var pair in ComponentDatas)
{
@@ -85,6 +93,8 @@ private void UpdateVolumesPerLightShaft()
Model = pair.Key.Model,
});
}

isDirty = false;
}
}
}
@@ -5,16 +5,32 @@
using System.Linq;
using Xenko.Core.Mathematics;
using Xenko.Games;
using Xenko.Rendering;
using Xenko.Rendering.Images;
using Xenko.Rendering.Lights;

namespace Xenko.Engine.Processors
{
public class LightShaftProcessor : EntityProcessor<LightShaftComponent, LightShaftProcessor.AssociatedData>
public class LightShaftProcessor : EntityProcessor<LightShaftComponent, LightShaftProcessor.AssociatedData>, IEntityComponentRenderProcessor
{
private readonly List<RenderLightShaft> activeLightShafts = new List<RenderLightShaft>();

public List<RenderLightShaft> LightShafts => activeLightShafts;
/// <inheritdoc/>
public VisibilityGroup VisibilityGroup { get; set; }

protected internal override void OnSystemAdd()
{
base.OnSystemAdd();

VisibilityGroup.Tags.Set(LightShafts.CurrentLightShafts, activeLightShafts);
}

protected internal override void OnSystemRemove()
{
VisibilityGroup.Tags.Set(LightShafts.CurrentLightShafts, null);

base.OnSystemRemove();
}

/// <inheritdoc />
protected override AssociatedData GenerateComponentData(Entity entity, LightShaftComponent component)
@@ -9,7 +9,6 @@
using Xenko.Core.Collections;
using Xenko.Core.Extensions;
using Xenko.Core.Mathematics;
using Xenko.Engine.Processors;
using Xenko.Graphics;
using Xenko.Rendering.Lights;
using Xenko.Rendering.Shadows;
@@ -20,6 +19,12 @@ namespace Xenko.Rendering.Images
[DataContract("LightShafts")]
public class LightShafts : ImageEffect
{
/// <summary>
/// Property key to access the current collection of <see cref="List{RenderLightShaft}"/> from <see cref="VisibilityGroup.Tags"/>.
/// </summary>
[DataMemberIgnore]
public static readonly PropertyKey<List<RenderLightShaft>> CurrentLightShafts = new PropertyKey<List<RenderLightShaft>>("LightShafts.CurrentLightShafts", typeof(LightShafts));

/// <summary>
/// The number of times the resolution is lowered for the light buffer
/// </summary>
@@ -50,7 +55,7 @@ public class LightShafts : ImageEffect
private GaussianBlur blur;

private IShadowMapRenderer shadowMapRenderer;
private LightShaftProcessor lightShaftProcessor;
private List<RenderLightShaft> lightShafts;

private MutablePipelineState[] minmaxPipelineStates = new MutablePipelineState[2];
private EffectBytecode previousMinmaxEffectBytecode;
@@ -120,21 +125,19 @@ protected override void Destroy()

public void Collect(RenderContext context)
{
lightShaftProcessor = Engine.SceneInstance.GetCurrent(context).GetProcessor<LightShaftProcessor>();
lightShafts = context.VisibilityGroup.Tags.Get(CurrentLightShafts);
}

protected override void DrawCore(RenderDrawContext context)
{
if (lightShaftProcessor == null)
if (lightShafts == null)
return; // Not collected

if (LightBufferDownsampleLevel < 1)
throw new ArgumentOutOfRangeException(nameof(LightBufferDownsampleLevel));
if (BoundingVolumeBufferDownsampleLevel < 1)
throw new ArgumentOutOfRangeException(nameof(BoundingVolumeBufferDownsampleLevel));

var lightShaftDatas = lightShaftProcessor.LightShafts;

var depthInput = GetSafeInput(0);

// Create a min/max buffer generated from scene bounding volumes
@@ -169,7 +172,7 @@ protected override void DrawCore(RenderDrawContext context)

applyLightEffectShader.SetOutput(GetSafeOutput(0));

foreach (var lightShaft in lightShaftDatas)
foreach (var lightShaft in lightShafts)
{
if (lightShaft.Light == null)
continue; // Skip entities without a light component

0 comments on commit 034abed

Please sign in to comment.
You can’t perform that action at this time.