Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/524 point cloud with multiple cameras #529

Merged
merged 10 commits into from
Jun 22, 2022
2 changes: 0 additions & 2 deletions Examples/Complete/ImGui/Desktop/Main.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Fusee.Base.Common;
using Fusee.Base.Core;
using Fusee.Base.Imp.Desktop;
using Fusee.Engine.Common;
using Fusee.Engine.Core;
using Fusee.Engine.Core.Scene;
using Fusee.Serialization;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;

namespace Fusee.Examples.FuseeImGui.Desktop
Expand Down
6 changes: 3 additions & 3 deletions Examples/Complete/PointCloudPotree2/Core/PointCloudPotree2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override void Init()
_spaceMouse = GetDevice<SixDOFDevice>();

PtRenderingParams.Instance.DepthPassEf = MakePointCloudEffect.ForDepthPass(PtRenderingParams.Instance.Size, PtRenderingParams.Instance.PtMode, PtRenderingParams.Instance.Shape);
PtRenderingParams.Instance.ColorPassEf = MakePointCloudEffect.ForColorPass(PtRenderingParams.Instance.Size, PtRenderingParams.Instance.ColorMode, PtRenderingParams.Instance.PtMode, PtRenderingParams.Instance.Shape, PtRenderingParams.Instance.EdlStrength, PtRenderingParams.Instance.EdlNoOfNeighbourPx);
PtRenderingParams.Instance.ColorPassEf = MakePointCloudEffect.ForColorPass(PtRenderingParams.Instance.Size, PtRenderingParams.Instance.PointCloudColorMode, PtRenderingParams.Instance.PtMode, PtRenderingParams.Instance.Shape, PtRenderingParams.Instance.EdlStrength, PtRenderingParams.Instance.EdlNoOfNeighbourPx);
PtRenderingParams.Instance.PointThresholdHandler = OnThresholdChanged;
PtRenderingParams.Instance.ProjectedSizeModifierHandler = OnProjectedSizeModifierChanged;

Expand Down Expand Up @@ -143,9 +143,9 @@ public override void Init()
_sih = new SceneInteractionHandler(_gui);

_sceneRenderer = new SceneRendererForward(_scene);
_sceneRenderer.VisitorModules.Add(new PointCloudRenderModule());
_sceneRenderer.VisitorModules.Add(new PointCloudRenderModule(_sceneRenderer.GetType() == typeof(SceneRendererForward)));
_guiRenderer = new SceneRendererForward(_gui);

_pointCloud.Camera = _cam;
IsInitialized = true;
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/Complete/PointCloudPotree2/Core/PtRenderParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public PointSizeMode PtMode

private PointColorMode _colorMode = PointColorMode.VertexColor0;

public PointColorMode ColorMode
public PointColorMode PointCloudColorMode
{
get { return _colorMode; }
set
{
_colorMode = value;
ColorPassEf.ColorMode = (int)_colorMode;
ColorPassEf.PointCloudColorMode = (int)_colorMode;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public override void Init()
};

_sceneRenderer = new SceneRendererForward(_scene);
_sceneRenderer.VisitorModules.Add(new PointCloudRenderModule());
_sceneRenderer.VisitorModules.Add(new PointCloudRenderModule(_sceneRenderer.GetType() == typeof(SceneRendererForward)));

_pointCloud.Camera = _cam;

IsInitialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public PointColorMode ColorMode
set
{
_colorMode = value;
ColorPassEf.ColorMode = (int)_colorMode;
ColorPassEf.PointCloudColorMode = (int)_colorMode;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/Complete/PointCloudPotree2/Wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void PtSizeMode_SelectionChanged(object sender, SelectionChangedEventArg
private void ColorMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (app == null || !app.IsInitialized) return;
PtRenderingParams.Instance.ColorMode = (PointColorMode)e.AddedItems[0];
PtRenderingParams.Instance.PointCloudColorMode = (PointColorMode)e.AddedItems[0];

//ColorPicker is unavailable right now
//if (PtRenderingParams.Instance.ColorMode != PointCloud.Common.ColorMode.Single)
Expand Down Expand Up @@ -346,7 +346,7 @@ private void CreateApp()

PtShape.SelectedValue = PtRenderingParams.Instance.Shape;
PtSizeMode.SelectedValue = PtRenderingParams.Instance.PtMode;
ColorMode.SelectedValue = PtRenderingParams.Instance.ColorMode;
ColorMode.SelectedValue = PtRenderingParams.Instance.PointCloudColorMode;

PtSize.Value = PtRenderingParams.Instance.Size;
PtSizeVal.Content = PtRenderingParams.Instance.Size;
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Core/Effects/PointCloudSurfaceEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public int EDLNeighbourPixels
/// </summary>
[FxShader(ShaderCategory.Fragment)]
[FxShard(ShardCategory.Uniform)]
public int ColorMode
public int PointCloudColorMode
{
get { return _colorMode; }
set
{
_colorMode = value;
SetFxParam(nameof(ColorMode), _colorMode);
SetFxParam(nameof(PointCloudColorMode), _colorMode);
}
}
private int _colorMode;
Expand Down
15 changes: 11 additions & 4 deletions src/Engine/Core/IRendererModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ namespace Fusee.Engine.Core
public interface IRendererModule : IVisitorModule
{
/// <summary>
/// The RenderLayer this renderer should render.
/// Sets the currently used <see cref="RenderLayer"/>.
/// </summary>
public RenderLayers RenderLayer { get; set; }
/// <param name="renderLayer"></param>
public void UpdateRenderLayer(RenderLayers renderLayer);

/// <summary>
/// Sets the currently used <see cref="Camera"/>.
/// </summary>
/// <param name="cam"></param>
public void UpdateCamera(Camera cam);

/// <summary>
/// Sets the render context for the given scene.
/// </summary>
/// <param name="rc"></param>
public void SetContext(RenderContext rc);
public void UpdateContext(RenderContext rc);

/// <summary>
/// Sets the <see cref="RendererState"/> for this module. Pass the state from the base renderer.
/// </summary>
/// <param name="state">The state to set.</param>
public void SetState(RendererState state);
public void UpdateState(RendererState state);
}
}
2 changes: 2 additions & 0 deletions src/Engine/Core/RenderCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public void InitApp()
RC = new RenderContext(ContextImplementor);
RC.Viewport(0, 0, Width, Height);
RC.SetRenderStateSet(RenderStateSet.Default);
RC.GetWindowHeight = () => CanvasImplementor.Height;
RC.GetWindowWidth = () => CanvasImplementor.Width;

VideoManager.Instance.VideoManagerImp = VideoManagerImplementor;

Expand Down
18 changes: 15 additions & 3 deletions src/Engine/Core/RenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public float ClearDepth
/// </summary>
public int ViewportYStart { get; private set; }

/// <summary>
/// Gets the window width.
/// </summary>
public Func<int> GetWindowWidth { get; internal set; }

/// <summary>
/// Sets the window width.
/// </summary>
public Func<int> GetWindowHeight { get; internal set; }

#endregion

#region Shader Management fields
Expand Down Expand Up @@ -1707,9 +1717,11 @@ public void SetRenderTarget(IWritableArrayTexture tex, int layer)
/// <param name="tex">The render texture.</param>
public void SetRenderTarget(IWritableTexture tex)
{
if (tex is WritableTexture wt)
if (tex == null)
SetRenderTarget();
else if (tex is WritableTexture wt)
SetRenderTarget(wt);
if (tex is WritableMultisampleTexture wmst)
else if (tex is WritableMultisampleTexture wmst)
SetRenderTarget(wmst);
}

Expand All @@ -1719,7 +1731,7 @@ public void SetRenderTarget(IWritableTexture tex)
/// <param name="tex">The render texture.</param>
public void SetRenderTarget(WritableTexture tex)
{
var texHandle = _textureManager.GetTextureHandle((WritableTexture)tex);
var texHandle = _textureManager.GetTextureHandle(tex);
_rci.SetRenderTarget(tex, texHandle);
}

Expand Down
35 changes: 25 additions & 10 deletions src/Engine/Core/Scene/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class Camera : SceneComponent
public RenderLayers RenderLayer;

/// <summary>
/// Scales the orthograpic viewing frustum. Dosn't have an effect if <see cref="ProjectionMethod.Perspective"/> is used.
/// Scales the orthographic viewing frustum. Doesn't have an effect if <see cref="ProjectionMethod.Perspective"/> is used.
/// </summary>
public float Scale = 1;

Expand All @@ -130,6 +130,27 @@ public Camera(ProjectionMethod projectionMethod, float zNear, float zFar, float
RenderLayer = renderLayer;
}

/// <summary>
/// Returns the viewport in px as float4.
/// x: start pixel in x direction.
/// y: start pixel in y direction.
/// z: width of the viewport.
/// w: height of the viewport.
/// </summary>
/// <param name="canvasWidthPx"></param>
/// <param name="canvasHeightPx"></param>
/// <returns></returns>
public float4 GetViewportInPx(int canvasWidthPx, int canvasHeightPx)
{
var startX = (int)(canvasWidthPx * (Viewport.x / 100));
var startY = (int)(canvasHeightPx * (Viewport.y / 100));

var width = (int)(canvasWidthPx * (Viewport.z / 100));
var height = (int)(canvasHeightPx * (Viewport.w / 100));

return new float4(startX, startY, width, height);
}

/// <summary>
/// Calculates and returns the projection matrix.
/// </summary>
Expand All @@ -145,18 +166,12 @@ public float4x4 GetProjectionMat(int canvasWidthPx, int canvasHeightPx, out floa
return proj;
}

var startX = (int)(canvasWidthPx * (Viewport.x / 100));
var startY = (int)(canvasHeightPx * (Viewport.y / 100));

var width = (int)(canvasWidthPx * (Viewport.z / 100));
var height = (int)(canvasHeightPx * (Viewport.w / 100));

viewport = new float4(startX, startY, width, height);
viewport = GetViewportInPx(canvasWidthPx, canvasHeightPx);

return ProjectionMethod switch
{
ProjectionMethod.Orthographic => float4x4.CreateOrthographic(width * Scale, height * Scale, ClippingPlanes.x, ClippingPlanes.y),
_ => float4x4.CreatePerspectiveFieldOfView(Fov, System.Math.Abs((float)width / height), ClippingPlanes.x, ClippingPlanes.y),
ProjectionMethod.Orthographic => float4x4.CreateOrthographic(viewport.z * Scale, viewport.w * Scale, ClippingPlanes.x, ClippingPlanes.y),
_ => float4x4.CreatePerspectiveFieldOfView(Fov, System.Math.Abs((float)viewport.z / viewport.w), ClippingPlanes.x, ClippingPlanes.y),
};
}

Expand Down
Loading