RenderTargetGroup GetData, Shader uint support

This commit is contained in:
Simon Lübeß
2022-05-25 22:00:11 +02:00
parent 1418063d68
commit 28f1fad464
19 changed files with 354 additions and 44 deletions
@@ -0,0 +1,16 @@
cbuffer Constants : register(b0)
{
uint ClearValue;
}
float4 VS(float2 input : POSITION) : SV_Position
{
return float4(input, 0.0f, 1.0f);
}
uint PS(float4 input : SV_Position) : SV_Target0
{
return ClearValue;
}
#effect[VS = VS, PS = PS]
@@ -1,3 +1,5 @@
#define OutputEntityId
#include "ShaderHelpers.hlsl"
Texture2D AlbedoTexture : register(t0);
@@ -28,6 +30,9 @@ cbuffer ObjectConstants
* \remarks This matrix is used in order to correctly transform normal vectors.
*/
float3x3 Transform_InvT;
#ifdef OutputEntityId
uint EntityId;
#endif
}
cbuffer Constants
@@ -60,6 +65,9 @@ struct PS_IN
float3 Tangent : TANGENT;
float2 TexCoord : TEXCOORD;
//nointerpolation float Handedness : HANDEDNESS;
#ifdef OutputEntityId
nointerpolation uint EntityId : ENTITYID;
#endif
};
PS_IN VS(VS_IN input)
@@ -76,6 +84,8 @@ PS_IN VS(VS_IN input)
// TODO: output.Handedness = input.Tangent.w
output.TexCoord = input.TexCoord;
output.EntityId = EntityId;
return output;
}
@@ -90,6 +100,9 @@ struct PS_OUT
float4 Position : SV_TARGET3;
// R: Metallicity G: Roughness B: Ambient
float4 Material : SV_TARGET4;
#ifdef OutputEntityId
uint EntityId : SV_TARGET5;
#endif
};
PS_OUT PS(PS_IN input)
@@ -134,6 +147,10 @@ PS_OUT PS(PS_IN input)
output.Position = float4(input.WorldPosition, 1.0);
output.Material = float4(finalMetallic, finalRoughness, 1.0, 0);
#ifdef OutputEntityId
output.EntityId = input.EntityId;
#endif
return output;
}
@@ -33,7 +33,17 @@ namespace GlitchyEditor.EditWindows
_selectedEntities.Clear();
_scene = scene;
}
/*public bool SelectEntityWithId(uint32 id, bool addToSelection = false)
{
if (!addToSelection)
_selectedEntities.Clear();
_scene.[Friend]_ecsWorld.IsValid(id);
_selectedEntities.Add();
}*/
protected override void InternalShow()
{
if(!ImGui.Begin(s_WindowTitle, &_open, .MenuBar))
@@ -12,11 +12,11 @@ namespace GlitchyEditor.EditWindows
{
public const String s_WindowTitle = "Scene";
private RenderTarget2D _renderTarget ~ _?.ReleaseRef();
private RenderTargetGroup _renderTarget ~ _?.ReleaseRef();
public Event<EventHandler<Vector2>> ViewportSizeChangedEvent ~ _.Dispose();
public RenderTarget2D RenderTarget
public RenderTargetGroup RenderTarget
{
get => _renderTarget;
set
@@ -93,7 +93,34 @@ namespace GlitchyEditor.EditWindows
if(_renderTarget != null)
{
ImGui.Image(_renderTarget, viewportSize);
ImGui.Image(_renderTarget.GetViewBinding(0), viewportSize);
}
Vector2 relativeMouse = (Vector2)ImGui.GetMousePos() - (Vector2)ImGui.GetItemRectMin();
int x = Renderer.[Friend]_gBuffer.Target.Width;
int y = Renderer.[Friend]_gBuffer.Target.Height;
if (Input.IsMouseButtonPressing(.LeftButton) && relativeMouse.X >= 0 && relativeMouse.Y >= 0 &&
relativeMouse.X < viewportSize.x && relativeMouse.Y < viewportSize.y &&
relativeMouse.X < x && relativeMouse.Y < y)
{
uint32 id = 0;
Renderer.[Friend]_gBuffer.Target.GetData<uint32>(&id, 5, (.)relativeMouse.X, (.)relativeMouse.Y, 1, 1);
id--;
//_renderTarget.GetData<uint32>(&pixel, 0, );
Log.EngineLogger.Info($"{relativeMouse} || ID = {id}");
/*if (id != uint32.MaxValue)
{
_editor.CurrentScene.[Friend]_ecsWorld.GetCurrentVersion()
}*/
//_editor.EntityHierarchyWindow.SelectEntityWithId(id, true);
}
DrawImGuizmo(viewportSize);
+12 -4
View File
@@ -44,7 +44,7 @@ namespace GlitchyEditor
Editor _editor ~ delete _;
RenderTarget2D _cameraTarget ~ _.ReleaseRef();
RenderTarget2D _viewportTarget ~ _.ReleaseRef();
RenderTargetGroup _viewportTarget ~ _.ReleaseRef();
SettingsWindow _settingsWindow = new .() ~ delete _;
@@ -89,8 +89,16 @@ namespace GlitchyEditor
_cameraTarget = new RenderTarget2D(RenderTarget2DDescription(.R16G16B16A16_Float, 100, 100) {DepthStencilFormat = .D32_Float});
_cameraTarget.SamplerState = SamplerStateManager.LinearClamp;
_viewportTarget = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100));
_viewportTarget.SamplerState = SamplerStateManager.LinearClamp;
//_viewportTarget = new RenderTarget2D(RenderTarget2DDescription(.R8G8B8A8_UNorm, 100, 100));
//_viewportTarget.SamplerState = SamplerStateManager.LinearClamp;
_viewportTarget = new RenderTargetGroup(.()
{
Width = 100,
Height = 100,
ColorTargetDescriptions = TargetDescription[](
.(.R8G8B8A8_UNorm))
});
_editorIcons = new Texture2D("Textures/EditorIcons.dds");
_editorIcons.SamplerState = SamplerStateManager.AnisotropicClamp;
@@ -114,7 +122,7 @@ namespace GlitchyEditor
RenderCommand.Clear(_viewportTarget, .Color | .Depth, .(0.2f, 0.2f, 0.2f), 1.0f, 0);
RenderCommand.SetRenderTarget(_viewportTarget, 0, true);
RenderCommand.SetRenderTargetGroup(_viewportTarget, true);
RenderCommand.BindRenderTargets();
RenderCommand.SetViewport(Viewport(0, 0, _viewportTarget.Width, _viewportTarget.Height));