-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start implementing node graph * update Sekai * remove previous rendering impl * add coordinate providing interfaces * add `Node` * add `Effect` * add material-related interfaces * add `ShaderMaterial` * add `UnlitMaterial` * add `Behavior` * add `Renderable` * add `RenderGroup`s * add `RenderObject`s * add `RenderData` * add `RenderQueue` and `RenderContext` * add `RenderTarget` * add `Renderer` * add `SortedFilteredCollection<T>` * add `Drawable` * add projectors * add `World` * add `Window` node * add executable * ensure material resources are applied * remove `Renderable` * cleanup pass * add `ServiceLocator` * add `Node.Services` * make `Window` override `Services` * refactor `World`
- Loading branch information
Showing
48 changed files
with
2,970 additions
and
2,577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
Oops, something went wrong.