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

Add Node Graph #275

Merged
merged 30 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f93e651
start implementing node graph
LeNitrous Jul 14, 2023
0762ed8
update Sekai
LeNitrous Jul 14, 2023
a544bdc
remove previous rendering impl
LeNitrous Jul 14, 2023
cddf178
add coordinate providing interfaces
LeNitrous Jul 14, 2023
36e3e00
add `Node`
LeNitrous Jul 14, 2023
738f467
add `Effect`
LeNitrous Jul 14, 2023
16c4b28
add material-related interfaces
LeNitrous Jul 14, 2023
b7ac6d6
add `ShaderMaterial`
LeNitrous Jul 14, 2023
51a4f8a
add `UnlitMaterial`
LeNitrous Jul 14, 2023
e617ca5
add `Behavior`
LeNitrous Jul 14, 2023
3287a4e
add `Renderable`
LeNitrous Jul 14, 2023
0d6d8c4
add `RenderGroup`s
LeNitrous Jul 14, 2023
07b1a50
add `RenderObject`s
LeNitrous Jul 14, 2023
702ccce
add `RenderData`
LeNitrous Jul 14, 2023
27f904b
add `RenderQueue` and `RenderContext`
LeNitrous Jul 14, 2023
f99c0b7
add `RenderTarget`
LeNitrous Jul 14, 2023
f58ec7e
add `Renderer`
LeNitrous Jul 14, 2023
3f07cd2
add `SortedFilteredCollection<T>`
LeNitrous Jul 14, 2023
536e586
add `Drawable`
LeNitrous Jul 14, 2023
48b8a7b
add projectors
LeNitrous Jul 14, 2023
194e1e1
add `World`
LeNitrous Jul 14, 2023
072cc4e
add `Window` node
LeNitrous Jul 14, 2023
f3a3e54
add executable
LeNitrous Jul 14, 2023
54940e9
ensure material resources are applied
LeNitrous Jul 14, 2023
64e87b4
remove `Renderable`
LeNitrous Jul 14, 2023
347daea
cleanup pass
LeNitrous Jul 14, 2023
37fa552
add `ServiceLocator`
LeNitrous Jul 15, 2023
36919c2
add `Node.Services`
LeNitrous Jul 15, 2023
2398f20
make `Window` override `Services`
LeNitrous Jul 15, 2023
b8b57fd
refactor `World`
LeNitrous Jul 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/source/Vignette.Desktop/bin/Debug/net7.0/Vignette.Desktop.dll",
"args": [],
"cwd": "${workspaceFolder}/source/Vignette.Desktop",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/source/Vignette.Desktop/Vignette.Desktop.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/source/Vignette.Desktop/Vignette.Desktop.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/source/Vignette.Desktop/Vignette.Desktop.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
7 changes: 7 additions & 0 deletions source/Vignette.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Cosyne
// Licensed under GPL 3.0 with SDK Exception. See LICENSE for details.

using Sekai;
using Vignette;

Host.Run<VignetteGame>(new HostOptions { Name = "Vignette" });
4 changes: 3 additions & 1 deletion source/Vignette.Desktop/Vignette.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Sekai.Desktop" Version="0.1.0-alpha.8" />
<PackageReference Include="Sekai.OpenGL" Version="0.1.0-alpha.9" />
<PackageReference Include="Sekai.OpenAL" Version="0.1.0-alpha.9" />
<PackageReference Include="Sekai.Desktop" Version="0.1.0-alpha.9" />
</ItemGroup>

</Project>
100 changes: 100 additions & 0 deletions source/Vignette/Behavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Cosyne
// Licensed under GPL 3.0 with SDK Exception. See LICENSE for details.

using System;

namespace Vignette;

/// <summary>
/// A <see cref="Node"/> that processes itself per-frame.
/// </summary>
public abstract class Behavior : Node, IComparable<Behavior>
{
/// <summary>
/// The processing order for this <see cref="Behavior"/>.
/// </summary>
public int Order
{
get => order;
set
{
if (order.Equals(value))
{
return;
}

order = value;
OrderChanged?.Invoke(this, EventArgs.Empty);
}
}

/// <summary>
/// Whether this <see cref="Behavior"/> should be enabled or not affecting <see cref="Update(TimeSpan)"/> calls.
/// </summary>
public bool Enabled
{
get => enabled;
set
{
if (enabled.Equals(value))
{
return;
}

enabled = value;
EnabledChanged?.Invoke(this, EventArgs.Empty);
}
}

/// <summary>
/// Called when <see cref="Order"/> has been changed.
/// </summary>
public event EventHandler? OrderChanged;

/// <summary>
/// Called when <see cref="Enabled"/> has been changed.
/// </summary>
public event EventHandler? EnabledChanged;

private int order;
private bool enabled = true;

/// <summary>
/// Called once in the update loop after the <see cref="Node"/> has entered the node graph.
/// </summary>
public virtual void Load()
{
}

/// <summary>
/// Called every frame to perform updates on this <see cref="Behavior"/>.
/// </summary>
/// <param name="elapsed">The time elapsed between frames.</param>
public virtual void Update(TimeSpan elapsed)
{
}

/// <summary>
/// Called once in the update loop before the <see cref="Node"/> exits the node graph.
/// </summary>
public virtual void Unload()
{
}

public int CompareTo(Behavior? other)
{
if (other is null)
{
return -1;
}

int value = Depth.CompareTo(other.Depth);

if (value != 0)
{
return value;
}

return Order.CompareTo(other.Order);
}
}
106 changes: 106 additions & 0 deletions source/Vignette/Camera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) Cosyne
// Licensed under GPL 3.0 with SDK Exception. See LICENSE for details.

using System;
using System.Numerics;
using Sekai.Mathematics;
using Vignette.Graphics;

namespace Vignette;

public class Camera : Node, IProjector
{
/// <summary>
/// The near plane distance.
/// </summary>
public float NearPlane = 0.1f;

/// <summary>
/// The far plane distance.
/// </summary>
public float FarPlane = 1000f;

/// <summary>
/// The camera's aspect ratio.
/// </summary>
/// <remarks>Used when <see cref="ProjectionMode"/> is <see cref="CameraProjectionMode.Perspective"/>.</remarks>
public float AspectRatio = 16.0f / 9.0f;

/// <summary>
/// The camera's field of view.
/// </summary>
public float FieldOfView = 60.0f;

/// <summary>
/// The camera's view size.
/// </summary>
public SizeF ViewSize = SizeF.Zero;

/// <summary>
/// The camera's view scale.
/// </summary>
public Vector2 ViewScale = Vector2.One;

/// <summary>
/// The camera's top left position.
/// </summary>
public Vector2 ViewTopLeft = Vector2.Zero;

/// <summary>
/// The camera projection mode.
/// </summary>
public CameraProjectionMode ProjectionMode = CameraProjectionMode.OrthographicOffCenter;

/// <summary>
/// The camera's rendering groups.
/// </summary>
public RenderGroup Groups { get; set; } = RenderGroup.Default;

/// <summary>
/// The camera's view frustum.
/// </summary>
public BoundingFrustum Frustum => BoundingFrustum.FromMatrix(((IProjector)this).ProjMatrix);

Matrix4x4 IProjector.ViewMatrix => Matrix4x4.CreateLookAt(Position, Position + Vector3.Transform(-Vector3.UnitZ, Matrix4x4.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z)), Vector3.UnitY);

Matrix4x4 IProjector.ProjMatrix => ProjectionMode switch
{
CameraProjectionMode.Perspective => Matrix4x4.CreatePerspective(ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, NearPlane, FarPlane),
CameraProjectionMode.PerspectiveOffCenter => Matrix4x4.CreatePerspectiveOffCenter(ViewTopLeft.X, ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, ViewTopLeft.Y, NearPlane, FarPlane),
CameraProjectionMode.PerspectiveFieldOfView => Matrix4x4.CreatePerspectiveFieldOfView(FieldOfView, AspectRatio, NearPlane, FarPlane),
CameraProjectionMode.Orthographic => Matrix4x4.CreateOrthographic(ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, NearPlane, FarPlane),
CameraProjectionMode.OrthographicOffCenter => Matrix4x4.CreateOrthographicOffCenter(ViewTopLeft.X, ViewSize.Width * ViewScale.X, ViewSize.Height * ViewScale.Y, ViewTopLeft.Y, NearPlane, FarPlane),
_ => throw new InvalidOperationException($"Unknown {nameof(ProjectionMode)} {ProjectionMode}."),
};
}

/// <summary>
/// An enumeration of camera projection modes.
/// </summary>
public enum CameraProjectionMode
{
/// <summary>
/// Orthographic projection.
/// </summary>
Orthographic,

/// <summary>
/// Custom orthographic projection.
/// </summary>
OrthographicOffCenter,

/// <summary>
/// Perspective projection.
/// </summary>
Perspective,

/// <summary>
/// Custom perspective projection.
/// </summary>
PerspectiveOffCenter,

/// <summary>
/// Perspective field of view projection.
/// </summary>
PerspectiveFieldOfView,
}
Loading
Loading