Skip to content
Permalink
Browse files

[Rendering] Made ForwardLightingRenderFeature not dependent on LightP…

…rocessor anymore
  • Loading branch information
xen2 committed Feb 13, 2019
1 parent b07e779 commit 9eceed040ce44d73cf42f16509970a5793ea7250
@@ -18,7 +18,7 @@ namespace Xenko.Engine
[Display("Light", Expand = ExpandRule.Once)]
// TODO GRAPHICS REFACTOR
//[DefaultEntityComponentRenderer(typeof(LightComponentRenderer), -10)]
[DefaultEntityComponentProcessor(typeof(LightProcessor))]
[DefaultEntityComponentRenderer(typeof(LightProcessor))]
[ComponentOrder(12000)]
public sealed class LightComponent : ActivableEntityComponent
{
@@ -12,7 +12,6 @@
using Xenko.Core.Collections;
using Xenko.Core.Storage;
using Xenko.Core.Threading;
using Xenko.Engine;
using Xenko.Graphics;
using Xenko.Rendering.Shadows;
using Xenko.Shaders;
@@ -24,6 +23,11 @@ namespace Xenko.Rendering.Lights
/// </summary>
public class ForwardLightingRenderFeature : SubRenderFeature
{
/// <summary>
/// Property key to access the current collection of <see cref="CameraComponent"/> from <see cref="RenderContext.Tags"/>.
/// </summary>
public static readonly PropertyKey<RenderLightCollection> CurrentLights = new PropertyKey<RenderLightCollection>("ForwardLightingRenderFeature.CurrentLights", typeof(ForwardLightingRenderFeature));

public class RenderViewLightData
{
/// <summary>
@@ -63,8 +67,6 @@ public RenderViewLightData()

private readonly LightShaderPermutationEntry shaderPermutation = new LightShaderPermutationEntry();

private LightProcessor lightProcessor;

private readonly TrackingCollection<LightGroupRendererBase> lightRenderers = new TrackingCollection<LightGroupRendererBase>();

/// <summary>
@@ -546,18 +548,18 @@ private void CollectVisibleLights()
renderViewLightData.VisibleLights.Clear();
renderViewLightData.VisibleLightsWithShadows.Clear();

lightProcessor = SceneInstance.GetCurrent(Context).GetProcessor<LightProcessor>();
var lights = Context.VisibilityGroup.Tags.Get(CurrentLights);

// No light processors means no light in the scene, so we can early exit
if (lightProcessor == null)
if (lights == null)
continue;

// TODO GRAPHICS REFACTOR
var sceneCullingMask = lightRenderView.CullingMask;

// 2) Cull lights with the frustum
var frustum = lightRenderView.Frustum;
foreach (var light in lightProcessor.Lights)
foreach (var light in lights)
{
// TODO: New mechanism for light selection (probably in ForwardLighting configuration)
// Light should probably have their own LightGroup (separate from RenderGroup)
@@ -10,7 +10,7 @@ namespace Xenko.Rendering.Lights
/// <summary>
/// Process <see cref="LightComponent"/> stored in an <see cref="EntityManager"/> by providing grouped lights per types/shadows.
/// </summary>
public class LightProcessor : EntityProcessor<LightComponent, RenderLight>
public class LightProcessor : EntityProcessor<LightComponent, RenderLight>, IEntityComponentRenderProcessor
{
/// <summary>
/// The default direction of a light vector is (x,y,z) = (0,0,-1)
@@ -26,6 +26,9 @@ public LightProcessor()
{
}

/// <inheritdoc/>
public VisibilityGroup VisibilityGroup { get; set; }

/// <summary>
/// Gets the active lights.
/// </summary>
@@ -38,18 +41,22 @@ public RenderLight GetRenderLight(LightComponent lightComponent)
return renderLight;
}

protected override void OnEntityComponentAdding(Entity entity, LightComponent component, RenderLight state)
protected override RenderLight GenerateComponentData(Entity entity, LightComponent component) => new RenderLight();

protected override bool IsAssociatedDataValid(Entity entity, LightComponent component, RenderLight associatedData) => true;

protected internal override void OnSystemAdd()
{
base.OnSystemAdd();
VisibilityGroup.Tags.Set(ForwardLightingRenderFeature.CurrentLights, Lights);
}

protected override void OnEntityComponentRemoved(Entity entity, LightComponent component, RenderLight state)
protected internal override void OnSystemRemove()
{
VisibilityGroup.Tags.Set(ForwardLightingRenderFeature.CurrentLights, null);
base.OnSystemRemove();
}

protected override RenderLight GenerateComponentData(Entity entity, LightComponent component) => new RenderLight();

protected override bool IsAssociatedDataValid(Entity entity, LightComponent component, RenderLight associatedData) => true;

public override void Draw(RenderContext context)
{
// 1) Clear the cache of current lights (without destroying collections but keeping previously allocated ones)
@@ -43,13 +43,20 @@ public class VisibilityGroup : IDisposable
/// </summary>
public RenderDataHolder RenderData;

/// <summary>
/// Gets the attached properties to this visibility group.
/// </summary>
public PropertyContainer Tags;

/// <summary>
/// List of objects registered in this group.
/// </summary>
public RenderObjectCollection RenderObjects { get; }

public VisibilityGroup(RenderSystem renderSystem)
{
Tags = new PropertyContainer(this);

RenderSystem = renderSystem;
RenderObjects = new RenderObjectCollection(this);
RenderData.Initialize(ComputeDataArrayExpectedSize);

0 comments on commit 9eceed0

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