Skip to content
Permalink
Browse files

[Render] Decouple RenderMesh and others from ECS

  • Loading branch information
xen2 committed Feb 8, 2019
1 parent fc805ea commit 15ffffd2163468ca4c6540bd3a726fec32ebf4c6
Showing with 198 additions and 188 deletions.
  1. +3 −10 ...o.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameEntitySelectionService.cs
  2. +1 −1 ...o.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameLightProbeGizmoService.cs
  3. +3 −1 ...Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameMaterialHighlightService.cs
  4. +2 −2 ...ko.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameModelSelectionService.cs
  5. +3 −1 sources/editor/Xenko.Assets.Presentation/SceneEditor/HighlightRenderFeature.cs
  6. +8 −3 sources/editor/Xenko.Assets.Presentation/SceneEditor/PickingRenderFeature.cs
  7. +4 −51 sources/engine/Xenko.Engine/Engine/SpriteComponent.cs
  8. +2 −2 sources/engine/Xenko.Engine/Rendering/Background/BackgroundRenderProcessor.cs
  9. +10 −10 sources/engine/Xenko.Engine/Rendering/ModelRenderProcessor.cs
  10. +0 −5 sources/engine/Xenko.Engine/Rendering/RenderModel.cs
  11. +7 −0 sources/engine/Xenko.Engine/Rendering/RenderObject.cs
  12. +62 −18 sources/engine/Xenko.Engine/Rendering/Sprites/RenderSprite.cs
  13. +29 −32 sources/engine/Xenko.Engine/Rendering/Sprites/SpriteRenderFeature.cs
  14. +22 −13 sources/engine/Xenko.Engine/Rendering/Sprites/SpriteRenderProcessor.cs
  15. +1 −1 sources/engine/Xenko.Engine/Rendering/Sprites/SpriteTransparentRenderStageSelector.cs
  16. +7 −2 sources/engine/Xenko.SpriteStudio.Runtime/RenderSpriteStudio.cs
  17. +0 −3 sources/engine/Xenko.SpriteStudio.Runtime/SpriteStudioComponent.cs
  18. +0 −13 sources/engine/Xenko.SpriteStudio.Runtime/SpriteStudioProcessor.cs
  19. +6 −6 sources/engine/Xenko.SpriteStudio.Runtime/SpriteStudioRenderFeature.cs
  20. +26 −12 sources/engine/Xenko.SpriteStudio.Runtime/SpriteStudioRendererProcessor.cs
  21. +2 −2 sources/engine/Xenko.UI/Rendering/UI/UIRenderProcessor.cs
@@ -601,17 +601,10 @@ public PickingFilter(EditorGameEntitySelectionService service)

public override bool IsVisible(RenderObject renderObject, RenderView renderView, RenderViewStage renderViewStage)
{
var renderMesh = renderObject as RenderMesh;
if (renderMesh != null)
var entity = (renderObject.Source as EntityComponent)?.Entity;
if (entity != null)
{
var entityId = service.Editor.Controller.GetAbsoluteId(renderMesh.RenderModel.ModelComponent.Entity);
return service.SelectableIds.Contains(entityId);
}

var renderSprite = renderObject as RenderSprite;
if (renderSprite != null)
{
var entityId = service.Editor.Controller.GetAbsoluteId(renderSprite.SpriteComponent.Entity);
var entityId = service.Editor.Controller.GetAbsoluteId(entity);
return service.SelectableIds.Contains(entityId);
}

@@ -384,7 +384,7 @@ public override bool IsVisible(RenderObject renderObject, RenderView renderView,
if (renderMesh != null)
{
// TODO: Avoid having to go through entity
return renderMesh.RenderModel?.ModelComponent?.Entity?.Tags.Get(EditorGameComponentGizmoService.SelectedKey) ?? false;
return (renderMesh.Source as ModelComponent)?.Entity?.Tags.Get(EditorGameComponentGizmoService.SelectedKey) ?? false;
}

return false;
@@ -360,7 +360,9 @@ public override bool IsVisible(RenderObject renderObject, RenderView renderView,
return renderMesh != null &&
(HighlightRenderFeature.MaterialHighlightColors.ContainsKey(renderMesh.MaterialPass.Material) ||
HighlightRenderFeature.MeshHighlightColors.ContainsKey(renderMesh.Mesh) ||
HighlightRenderFeature.MaterialsHighlightedForModel.Contains(renderMesh.MaterialPass.Material) && HighlightRenderFeature.ModelHighlightColors.ContainsKey(renderMesh.RenderModel.ModelComponent));
(HighlightRenderFeature.MaterialsHighlightedForModel.Contains(renderMesh.MaterialPass.Material)
&& renderMesh.Source is ModelComponent component
&& HighlightRenderFeature.ModelHighlightColors.ContainsKey(component)));
}
}
}
@@ -113,8 +113,8 @@ public WireframeFilter(HashSet<Entity> selectedEntities)

public override bool IsVisible(RenderObject renderObject, RenderView renderView, RenderViewStage renderViewStage)
{
var renderMesh = renderObject as RenderMesh;
return renderMesh != null && selectedEntities.Contains(renderMesh.RenderModel.ModelComponent.Entity);
var entity = ((renderObject as RenderMesh)?.Source as ModelComponent)?.Entity;
return entity != null && selectedEntities.Contains(entity);
}
}

@@ -47,7 +47,9 @@ public override void Extract()
var isHighlighted =
MaterialHighlightColors.TryGetValue(renderMesh.MaterialPass.Material, out highlightColor) ||
MeshHighlightColors.TryGetValue(renderMesh.Mesh, out highlightColor) ||
MaterialsHighlightedForModel.Contains(renderMesh.MaterialPass.Material) && ModelHighlightColors.TryGetValue(renderMesh.RenderModel.ModelComponent, out highlightColor);
(MaterialsHighlightedForModel.Contains(renderMesh.MaterialPass.Material)
&& renderMesh.Source is ModelComponent component
&& ModelHighlightColors.TryGetValue(component, out highlightColor));

renderModelObjectInfo[objectNodeReference] = highlightColor;
}
@@ -1,6 +1,7 @@
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using Xenko.Core;
using Xenko.Engine;
using Xenko.Rendering;

namespace Xenko.Assets.Presentation.SceneEditor
@@ -35,16 +36,20 @@ public override void Extract()
continue;

int meshIndex = 0;
for (int i = 0; i < renderMesh.RenderModel.ModelComponent.Model.Meshes.Count; i++)
var modelComponent = renderMesh.Source as ModelComponent;
if (modelComponent == null)
continue;

for (int i = 0; i < modelComponent.Model.Meshes.Count; i++)
{
if (renderMesh.RenderModel.ModelComponent.Model.Meshes[i] == renderMesh.Mesh)
if (modelComponent.Model.Meshes[i] == renderMesh.Mesh)
{
meshIndex = i;
break;
}
}

modelObjectInfo[objectNodeReference] = new PickingObjectInfo(RuntimeIdHelper.ToRuntimeId(renderMesh.RenderModel.ModelComponent), meshIndex, renderMesh.Mesh.MaterialIndex);
modelObjectInfo[objectNodeReference] = new PickingObjectInfo(RuntimeIdHelper.ToRuntimeId(modelComponent), meshIndex, renderMesh.Mesh.MaterialIndex);
}
}

@@ -22,43 +22,6 @@ namespace Xenko.Engine
[ComponentOrder(10000)]
public sealed class SpriteComponent : ActivableEntityComponent
{
public enum SpriteSampler
{
[Display("Point (Nearest)")]
PointClamp,

[Display("Linear")]
LinearClamp,

[Display("Anisotropic")]
AnisotropicClamp,

// Note These values are left out on purpose, but can be included if needed
//PointWrap,
//LinearWrap,
//AnisotropicWrap,
}
public enum SpriteBlend
{
///<userdoc>No blending, the sprite is drawn as-is.</userdoc>
None,

///<userdoc>Use alpha blending if the sprite has transparent pixels, disable the blending otherwise.</userdoc>
Auto,

/// <userdoc>Use the alpha component for blending the source and sprite.</userdoc>
[Display("Alpha blend")]
AlphaBlend,

/// <userdoc>The sprite color is added to the source without using the alpha.</userdoc>
[Display("Additive blend")]
AdditiveBlend,

///<userdoc>Do not render the colors of the sprite. Renders only the depth to the stencil buffer.</userdoc>
[Display("No color")]
NoColor,
}

/// <summary>
/// The group of sprites associated to the component.
/// </summary>
@@ -78,36 +41,26 @@ public enum SpriteBlend
public SpriteType SpriteType;

/// <summary>
/// The color shade to apply on the sprite. If you need the final color, use <see cref="ColorFinal"/> instead.
/// The color shade to apply on the sprite.
/// </summary>
/// <userdoc>The color to apply to the sprite.</userdoc>
[DataMember(40)]
[Display("Color")]
public Color4 Color { get { return color; } set { color = value; colorFinal = color * intensity; colorFinal.A = color.A; } }

private Color4 color = Color4.White;
public Color4 Color { get; set; } = Color4.White;

/// <summary>
/// The intensity by which the color is scaled. If you need the final color, use <see cref="ColorFinal"/> instead.
/// The intensity by which the color is scaled.
/// </summary>
/// <userdoc>
/// The intensity by which the color is scaled. Mainly used for rendering LDR sprites in in HDR scenes.
/// </userdoc>
[DataMember(42)]
[Display("Intensity")]
[DefaultValue(1f)]
public float Intensity { get { return intensity; } set { intensity = Math.Max(value, 0f); colorFinal = color * intensity; colorFinal.A = color.A; } }
public float Intensity { get => intensity; set => intensity = Math.Max(value, 0f); }

private float intensity = 1f;

/// <summary>
/// The combined value of Color and Intensity
/// </summary>
[DataMemberIgnore]
public Color4 ColorFinal { get { return colorFinal; } }

private Color4 colorFinal = Color4.White;

/// <summary>
/// Gets or sets a value indicating whether the sprite is a pre-multiplied alpha (default is true).
/// </summary>
@@ -34,13 +34,13 @@ protected internal override void OnSystemRemove()
/// <inheritdoc />
protected override RenderBackground GenerateComponentData(Entity entity, BackgroundComponent component)
{
return new RenderBackground { RenderGroup = component.RenderGroup };
return new RenderBackground { Source = component, RenderGroup = component.RenderGroup };
}

/// <inheritdoc />
protected override bool IsAssociatedDataValid(Entity entity, BackgroundComponent component, RenderBackground associatedData)
{
return component.RenderGroup == associatedData.RenderGroup;
return component == associatedData.Source && component.RenderGroup == associatedData.RenderGroup;
}

/// <inheritdoc />
@@ -43,13 +43,13 @@ protected internal override void OnSystemAdd()
/// <inheritdoc />
protected override RenderModel GenerateComponentData(Entity entity, ModelComponent component)
{
return new RenderModel(component);
return new RenderModel();
}

/// <inheritdoc />
protected override bool IsAssociatedDataValid(Entity entity, ModelComponent component, RenderModel associatedData)
{
return component == associatedData.ModelComponent;
return true;
}

/// <inheritdoc />
@@ -74,19 +74,19 @@ public override void Draw(RenderContext context)
//foreach (var entity in ComponentDatas)
Dispatcher.ForEach(ComponentDatas, entity =>
{
var modelComponent = entity.Key;
var renderModel = entity.Value;

CheckMeshes(renderModel);
UpdateRenderModel(renderModel);
CheckMeshes(modelComponent, renderModel);
UpdateRenderModel(modelComponent, renderModel);
});
}

private void UpdateRenderModel(RenderModel renderModel)
private void UpdateRenderModel(ModelComponent modelComponent, RenderModel renderModel)
{
if (renderModel.ModelComponent.Model == null)
if (modelComponent.Model == null)
return;

var modelComponent = renderModel.ModelComponent;
var modelViewHierarchy = modelComponent.Skeleton;
var nodeTransformations = modelViewHierarchy.NodeTransformations;

@@ -134,10 +134,9 @@ private Material FindMaterial(Material materialOverride, MaterialInstance modelM
return materialOverride ?? modelMaterialInstance?.Material ?? fallbackMaterial;
}

private void CheckMeshes(RenderModel renderModel)
private void CheckMeshes(ModelComponent modelComponent, RenderModel renderModel)
{
// Check if model changed
var modelComponent = renderModel.ModelComponent;
var model = modelComponent.Model;
if (renderModel.Model == model)
{
@@ -222,6 +221,7 @@ private void CheckMeshes(RenderModel renderModel)
var materialIndex = mesh.MaterialIndex;
renderMeshes[meshIndex] = new RenderMesh
{
Source = modelComponent,
RenderModel = renderModel,
Mesh = mesh,
};
@@ -234,7 +234,7 @@ private void CheckMeshes(RenderModel renderModel)
renderModel.Meshes = renderMeshes;

// Update before first add so that RenderGroup is properly set
UpdateRenderModel(renderModel);
UpdateRenderModel(modelComponent, renderModel);

// Update and register with render system
lock (VisibilityGroup.RenderObjects)
@@ -10,15 +10,10 @@ namespace Xenko.Rendering
/// </summary>
public class RenderModel
{
public readonly ModelComponent ModelComponent;
public Model Model;
public RenderMesh[] Meshes;
public MaterialInfo[] Materials;

public RenderModel(ModelComponent modelComponent)
{
ModelComponent = modelComponent;
}

public struct MaterialInfo
{
@@ -32,5 +32,12 @@ public abstract class RenderObject

// TODO: Switch to a "StaticPropertyContainer" that will be optimized by assembly processor
//public PropertyContainer Tags;

// TODO: We should probably switch to RenderData (but right now its local to either VisibilityGroup or RenderFeature) or the previously mentioned StaticPropertyContainer to have more flexibility.
/// <summary>
/// Can be used to setup a link to a source.
/// Typically, this might be an entity component.
/// </summary>
public object Source;
}
}

0 comments on commit 15ffffd

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