This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Basics of debug renderer -kill me please
- Loading branch information
1 parent
9164e91
commit a95579b
Showing
51 changed files
with
444 additions
and
73 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
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,9 @@ | ||
#version 450 | ||
|
||
layout(location = 1) in vec4 fsin_Color; | ||
|
||
layout(location = 0) out vec4 fsout_Color; | ||
|
||
void main() { | ||
fsout_Color = fsin_Color; | ||
} |
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,19 @@ | ||
#version 450 | ||
|
||
layout(location = 0) in vec3 Position; | ||
layout(location = 1) in vec4 Color; | ||
layout(location = 2) in vec2 UV; | ||
|
||
|
||
layout(location = 1) out vec4 fsin_Color; | ||
|
||
layout (set = 0, binding = 0) uniform CameraData { | ||
mat4 VPMatrix; | ||
}; | ||
|
||
void main() { | ||
vec4 pos = vec4(Position, 1) * VPMatrix; | ||
gl_Position = pos; | ||
|
||
fsin_Color = Color; | ||
} |
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
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
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,97 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using GlmSharp; | ||
using Veldrid; | ||
using Voxel.Client.Rendering.VertexTypes; | ||
|
||
namespace Voxel.Client.Rendering.Debug; | ||
|
||
public class DebugRenderer : Renderer { | ||
private const int BatchSize = 2048; | ||
private static DebugRenderer Instance; | ||
|
||
public readonly Pipeline DebugPipeline; | ||
private readonly DeviceBuffer vertexBuffer; | ||
|
||
private readonly DebugVertex[] DebugVertices = new DebugVertex[BatchSize]; | ||
private int vertexIndex = 0; | ||
|
||
public DebugRenderer(VoxelClient client) : base(client) { | ||
Instance = this; | ||
|
||
if (!client.RenderSystem.ShaderManager.GetShaders("shaders/debug", out var shaders)) | ||
throw new("Shaders not present."); | ||
|
||
DebugPipeline = ResourceFactory.CreateGraphicsPipeline(new() { | ||
BlendState = BlendStateDescription.SingleOverrideBlend, | ||
DepthStencilState = new() { | ||
DepthComparison = ComparisonKind.LessEqual, DepthTestEnabled = true, DepthWriteEnabled = true, | ||
}, | ||
Outputs = RenderSystem.GraphicsDevice.SwapchainFramebuffer.OutputDescription, | ||
PrimitiveTopology = PrimitiveTopology.LineList, | ||
RasterizerState = new() { | ||
CullMode = FaceCullMode.None, DepthClipEnabled = false, FillMode = PolygonFillMode.Wireframe, ScissorTestEnabled = false, | ||
}, | ||
ResourceLayouts = new[] { | ||
Client.GameRenderer.CameraStateManager.CameraResourceLayout, | ||
}, | ||
ShaderSet = new() { | ||
VertexLayouts = new[] { | ||
DebugVertex.Layout | ||
}, | ||
Shaders = shaders | ||
} | ||
}); | ||
|
||
|
||
vertexBuffer = ResourceFactory.CreateBuffer(new BufferDescription { | ||
Usage = BufferUsage.Dynamic | BufferUsage.VertexBuffer, SizeInBytes = (uint)Marshal.SizeOf<DebugVertex>() * BatchSize | ||
}); | ||
} | ||
public override void Render(double delta) { | ||
|
||
DrawLine(new() { | ||
position = new vec3(0, 0, 0) - (vec3)Client.GameRenderer.MainCamera.position, color = new vec4(1, 1, 1, 1) | ||
}, | ||
new() { | ||
position = new vec3(0, 1000, 0) - (vec3)Client.GameRenderer.MainCamera.position, color = new vec4(1, 1, 1, 1) | ||
} | ||
); | ||
|
||
Flush(); | ||
} | ||
|
||
private void Flush() { | ||
if (vertexIndex == 0) | ||
return; | ||
|
||
CommandList.UpdateBuffer(vertexBuffer, 0, DebugVertices.AsSpan(0, vertexIndex)); | ||
CommandList.SetPipeline(DebugPipeline); | ||
|
||
CommandList.SetGraphicsResourceSet(0, Client.GameRenderer.CameraStateManager.CameraResourceSet); | ||
|
||
CommandList.SetVertexBuffer(0, vertexBuffer); | ||
CommandList.Draw((uint)vertexIndex); | ||
|
||
vertexIndex = 0; | ||
} | ||
|
||
public override void Dispose() { | ||
DebugPipeline.Dispose(); | ||
} | ||
|
||
|
||
public static void DrawLine(DebugVertex a, DebugVertex b) { | ||
Instance.DebugVertices[Instance.vertexIndex++] = a; | ||
Instance.DebugVertices[Instance.vertexIndex++] = b; | ||
|
||
if (Instance.vertexIndex >= BatchSize) { | ||
Instance.Flush(); | ||
} | ||
} | ||
|
||
/*public static void DrawCube(DebugVertex min, DebugVertex max) { | ||
DebugVertices.Add(a); | ||
DebugVertices.Add(b); | ||
}*/ | ||
} |
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
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
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
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,17 @@ | ||
using GlmSharp; | ||
using Veldrid; | ||
|
||
namespace Voxel.Client.Rendering.VertexTypes; | ||
|
||
public struct DebugVertex { | ||
|
||
public static readonly VertexLayoutDescription Layout = new( | ||
new VertexElementDescription("Position", VertexElementFormat.Float3, VertexElementSemantic.Position), | ||
new VertexElementDescription("Color", VertexElementFormat.Float4, VertexElementSemantic.Color), | ||
new VertexElementDescription("UV", VertexElementFormat.Float2, VertexElementSemantic.TextureCoordinate) | ||
); | ||
|
||
public vec3 position; | ||
public vec4 color; | ||
public vec2 uv; | ||
} |
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
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
Oops, something went wrong.