mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Render 2D with depth, reverse depth of camera projection
dirty fix in Renderer...
This commit is contained in:
@@ -274,15 +274,16 @@ namespace GlitchyEngine.World
|
||||
float halfWidth = halfHeight * _aspectRatio;
|
||||
|
||||
_projection = Matrix.OrthographicProjectionOffCenter(-halfWidth, halfWidth, halfHeight, -halfHeight,
|
||||
_orthographicNearPlane, _orthographicFarPlane);
|
||||
// Swap far and near plane, because we use reversed depth!
|
||||
_orthographicFarPlane, _orthographicNearPlane);
|
||||
}
|
||||
else if (_projectionType case .Perspective)
|
||||
{
|
||||
_projection = Matrix.PerspectiveProjection(_perspectiveFovY, _aspectRatio, _perspectiveNearPlane, _perspectiveFarPlane);
|
||||
_projection = Matrix.ReversedPerspectiveProjection(_perspectiveFovY, _aspectRatio, _perspectiveNearPlane, _perspectiveFarPlane);
|
||||
}
|
||||
else if (_projectionType case .InfinitePerspective)
|
||||
{
|
||||
_projection = Matrix.InfinitePerspectiveProjection(_perspectiveFovY, _aspectRatio, _perspectiveNearPlane);
|
||||
_projection = Matrix.ReversedInfinitePerspectiveProjection(_perspectiveFovY, _aspectRatio, _perspectiveNearPlane);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace GlitchyEngine.World
|
||||
private void UpdateProjection() mut
|
||||
{
|
||||
//_projection = Matrix.InfinitePerspectiveProjection(_fovY, _aspectRatio, _nearPlane);
|
||||
_projection = Matrix.PerspectiveProjection(_fovY, _aspectRatio, _nearPlane, 10000);
|
||||
_projection = Matrix.ReversedPerspectiveProjection(_fovY, _aspectRatio, _nearPlane, 10000);
|
||||
}
|
||||
|
||||
public void OnViewportResize(uint32 sizeX, uint32 sizeY) mut
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Content;
|
||||
using GlitchyEngine.Math;
|
||||
using System;
|
||||
|
||||
namespace GlitchyEngine.World;
|
||||
|
||||
@@ -26,20 +27,23 @@ class SceneRenderer
|
||||
{
|
||||
RenderTargetGroupDescription desc = .(100, 100,
|
||||
TargetDescription[](
|
||||
RenderTargetFormat.R16G16B16A16_Float,
|
||||
.(RenderTargetFormat.R32_UInt) {ClearColor = .UInt(uint32.MaxValue)}),
|
||||
RenderTargetFormat.D24_UNorm_S8_UInt);
|
||||
.(.R16G16B16A16_Float, ownDebugName: new String("Color")),
|
||||
.(.R32_UInt) {ClearColor = .UInt(uint32.MaxValue), DebugName = new String("EntityId")}
|
||||
),
|
||||
TargetDescription(.D24_UNorm_S8_UInt, clearColor: ClearColor.DepthStencil(0.0f, 0)));
|
||||
_compositeTarget = new RenderTargetGroup(desc);
|
||||
_compositeTarget.[Friend]Identifier = "Composite Target";
|
||||
|
||||
_cameraTarget = new RenderTargetGroup(.(){
|
||||
Width = 100,
|
||||
Height = 100,
|
||||
ColorTargetDescriptions = TargetDescription[](
|
||||
.(.R16G16B16A16_Float),
|
||||
.(.R32_UInt)
|
||||
.(.R16G16B16A16_Float, ownDebugName: new String("Color")),
|
||||
.(.R32_UInt) {ClearColor = .UInt(uint32.MaxValue), DebugName = new String("EntityId")}
|
||||
),
|
||||
DepthTargetDescription = .(.D24_UNorm_S8_UInt)
|
||||
DepthTargetDescription = .(.D24_UNorm_S8_UInt, clearColor: ClearColor.DepthStencil(0.0f, 0))
|
||||
});
|
||||
_cameraTarget.[Friend]Identifier = "Camera Target";
|
||||
|
||||
_gammaCorrectEffect = Content.LoadAsset("Resources/Shaders/GammaCorrect.hlsl");
|
||||
}
|
||||
@@ -83,6 +87,8 @@ class SceneRenderer
|
||||
finalTarget.AddRef();
|
||||
|
||||
renderTarget = _cameraTarget..AddRef();
|
||||
|
||||
RenderCommand.Clear(_compositeTarget, .ColorDepth);
|
||||
|
||||
// 3D render
|
||||
Renderer.BeginScene(*primaryCamera, primaryCameraTransform, renderTarget, _compositeTarget);
|
||||
|
||||
Reference in New Issue
Block a user