Skip to content

Commit

Permalink
MSAA WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Benualdo committed Oct 26, 2024
1 parent 46deed9 commit 7eb3e2b
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Renderer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Property type="Bool" name="m_aabb" flags="SingleLine" value="false"/>
<Property type="Bool" name="m_debugUI" flags="SingleLine" value="false"/>
<Property type="EnumU8" name="m_VSync" value="VSync_1"/>
<Property type="EnumU8" name="m_antiAliasing" value="FXAA"/>
<Property type="EnumU8" name="m_aaPostProcess" value="FXAA"/>
<Property type="EnumU8" name="m_HDRmode" value="HDR16"/>
<Property type="Float4" name="m_backgroundColor" flags="Color" x="0.48101264" y="0.7895999" z="1" w="0"/>
<Property type="EnumFlagsU32" name="m_renderPassFlags" flags="Bitfield" value="ZPrepass|Opaque|Transparency"/>
Expand Down
17 changes: 8 additions & 9 deletions data/Shaders/default/default.hlsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ namespace vg::gfx
class DefaultHLSLDesc : public HLSLDesc
{
public:
//enum Flags : ShaderKey::Flags
//{
// // Flags 0..12 are available
//
// // Flags 13..15 are reserved and should be common for all shaders
// ZOnly = HLSLDesc::Flags::ZOnly,
// RayTracing = HLSLDesc::Flags::RayTracing,
// Toolmode = HLSLDesc::Flags::Toolmode
//};
enum Flags : ShaderKey::Flags
{

// Last flags are common for all shaders
ZOnly = HLSLDesc::Flags::ZOnly,
RayTracing = HLSLDesc::Flags::RayTracing,
Toolmode = HLSLDesc::Flags::Toolmode
};

DefaultHLSLDesc()
{
Expand Down
10 changes: 5 additions & 5 deletions data/Shaders/postprocess/postprocess.hlsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace vg::gfx
enum Flags : ShaderKey::Flags
{
// Bits 0..1 for AA mode
AntiAliasingMode = 0,
AAPostProcess = 0,

// Flags 13..15 are reserved and should be common for all shaders
RayTracing = HLSLDesc::Flags::RayTracing,
Toolmode = HLSLDesc::Flags::Toolmode
// Last flags are common for all shaders
RayTracing = HLSLDesc::Flags::RayTracing,
Toolmode = HLSLDesc::Flags::Toolmode
};

PostProcessHLSLDesc()
{
setFile("postprocess/postprocess.hlsl");

declFlags(AntiAliasingMode, ShaderStageFlags::CS, { "", "_FXAA", "_SMAA" } );
declFlags(AAPostProcess, ShaderStageFlags::CS, { "", "_FXAA", "_SMAA" } );
declFlag(RayTracing, ShaderStageFlags::CS, "_RAYTRACING");
declFlag(Toolmode, ShaderStageFlags::CS, "_TOOLMODE");

Expand Down
6 changes: 6 additions & 0 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3095,6 +3095,12 @@ Column 0 Width=96
Column 1 Width=96
Column 2 Weight=1.0000

[Table][0x170BBB16,3]
RefScale=14
Column 0 Width=96
Column 1 Width=96
Column 2 Weight=1.0000

[Docking][Data]
DockNode ID=0x0000001B Pos=517,135 Size=821,613 Selected=0x766639F3
DockSpace ID=0x09EF459F Pos=0,24 Size=1920,1056 Split=X
Expand Down
12 changes: 10 additions & 2 deletions src/editor/ImGui/Window/ImGuiWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,16 @@ namespace vg::editor
}
else
{
auto enumVal = (T)enumPairs[_index].value;
const bool disabled = asBool(EnumValueFlags::Disabled & _prop->GetEnumValueFlags(enumVal));

if (disabled)
PushDisabledStyle(true);

if (ImGui::Selectable(_enumName.c_str()))
{
if (!_propContext.m_readOnly)
if (!_propContext.m_readOnly && !disabled)
{
auto enumVal = (T)enumPairs[_index].value;
bool edited = true;
auto editingState = undoRedoBeforeEdit<T>(edited, _propContext, _object, _prop, (T *)&enumVal, _pEnum, InteractionType::Single);

Expand All @@ -553,6 +558,9 @@ namespace vg::editor
}
}
}

if (disabled)
PopDisabledStyle();
}

return changed;
Expand Down
7 changes: 6 additions & 1 deletion src/gfx/Device/Device_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ namespace vg::gfx
VSync_4
);

vg_enum_class(AntiAliasing, core::u8,
vg_enum_class(MSAA, core::u8,
None = 0,
MSAA4X
);

vg_enum_class(AAPostProcess, core::u8,
None = 0,
FXAA,
SMAA
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/IRendererOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace vg::gfx
{
enum class VSync : core::u8;
enum class HDR : core::u8;
enum class AntiAliasing : core::u8;
enum class AAPostProcess : core::u8;
}

namespace vg::renderer
Expand All @@ -21,8 +21,8 @@ namespace vg::renderer
virtual gfx::VSync GetVSync () const = 0;
virtual bool SetVSync (const gfx::VSync & _vsync) = 0;

virtual gfx::AntiAliasing GetAliasing () const = 0;
virtual bool SetAliasing (const gfx::AntiAliasing & _aa) = 0;
virtual gfx::AAPostProcess GetAAPostProcess () const = 0;
virtual bool SetAAPostProcess (const gfx::AAPostProcess & _aa) = 0;

virtual gfx::HDR GetHDR () const = 0;
virtual bool SetHDR (const gfx::HDR & _hdr) = 0;
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/Options/RendererOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace vg::renderer
gfx::VSync GetVSync () const final override;
bool SetVSync (const gfx::VSync & _vsync) final override;

gfx::AntiAliasing GetAliasing () const final override;
bool SetAliasing (const gfx::AntiAliasing & _aa) final override;
gfx::AAPostProcess GetAAPostProcess () const final override;
bool SetAAPostProcess (const gfx::AAPostProcess & _aa) final override;

gfx::HDR GetHDR () const final override;
bool SetHDR (const gfx::HDR & _hdr) final override;
Expand Down Expand Up @@ -88,7 +88,8 @@ namespace vg::renderer
bool m_postProcess = true;
bool m_rayTracing = false;
gfx::HDR m_HDRmode = gfx::HDR::None;
gfx::AntiAliasing m_antiAliasing = gfx::AntiAliasing::None;
gfx::MSAA m_msaa = gfx::MSAA::None;
gfx::AAPostProcess m_aaPostProcess = gfx::AAPostProcess::None;
gfx::VSync m_VSync = gfx::VSync::VSync_1;
LightingMode m_lightingMode = LightingMode::Forward;
DisplayMode m_debugDisplayMode = DisplayMode::None;
Expand All @@ -97,5 +98,6 @@ namespace vg::renderer

core::IProperty * m_hdrProp = nullptr;
core::IProperty * m_vsyncProp = nullptr;
core::IProperty * m_aaPostProcessProp = nullptr;
};
}
86 changes: 59 additions & 27 deletions src/renderer/Options/RendererOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,62 @@ namespace vg::renderer
{
super::registerProperties(_desc);

registerPropertyEx(RendererOptions, m_toolMode, "Toolmode", PropertyFlags::SingleLine);
registerProperty(RendererOptions, m_toolMode, "Toolmode");
setPropertyDescription(LightDesc, m_toolMode, "Enable Toolmode in Game views");

registerPropertyEx(RendererOptions, m_rayTracing, "RayTracing", PropertyFlags::SingleLine);
setPropertyDescription(LightDesc, m_rayTracing, "Enable Ray-Tracing features");
//registerPropertyEnumEx(RendererOptions, DisplayMode, m_debugDisplayMode, "Debug", PropertyFlags::AlphabeticalOrder);
registerPropertyEnum(RendererOptions, DisplayMode, m_debugDisplayMode, "Debug");

registerPropertyEx(RendererOptions, m_postProcess, "PostProcess", PropertyFlags::SingleLine);
setPropertyDescription(RendererOptions, m_postProcess, "Enable Post-Process features");
registerPropertyGroupBegin(RendererOptions, "Lighting");
{
registerPropertyEnum(RendererOptions, LightingMode, m_lightingMode, "Mode");
setPropertyDescription(LightDesc, m_lightingMode, "Lighting monde will affect how lights are computed.\nIn \"Forward\" mode lighting is computed on the fly in pixel shader\nIn \"Defered\" mode lighting is computed in screen-space");
}
registerPropertyGroupEnd(RendererOptions);

registerPropertyEnum(RendererOptions, LightingMode, m_lightingMode, "Lighting");
setPropertyDescription(LightDesc, m_lightingMode, "Lighting monde will affect how lights are computed.\nIn \"Forward\" mode lighting is computed on the fly in pixel shader\nIn \"Defered\" mode lighting is computed in screen-space");
registerPropertyGroupBegin(RendererOptions, "Presentation");
{
registerPropertyEnum(RendererOptions, gfx::HDR, m_HDRmode, "HDR");
setPropertyDescription(LightDesc, m_HDRmode, "High-dynamic range display mode");

//registerPropertyEnumEx(RendererOptions, DisplayMode, m_debugDisplayMode, "Debug", PropertyFlags::AlphabeticalOrder);
registerPropertyEnum(RendererOptions, DisplayMode, m_debugDisplayMode, "Debug");
registerPropertyEnumBitfield(RendererOptions, DisplayFlags, m_displayFlags, "Flags");
registerPropertyEnumEx(RendererOptions, gfx::MSAA, m_msaa, "MSAA", PropertyFlags::ReadOnly);
setPropertyDescription(LightDesc, m_msaa, "Multisample anti-aliasing");

registerPropertyEnum(RendererOptions, gfx::VSync, m_VSync, "VSync");
setPropertyDescription(LightDesc, m_VSync, "Sync display frequency with monitor refresh rate");
}
registerPropertyGroupEnd(RendererOptions);

registerPropertyGroupBegin(RendererOptions, "Advanced");
registerPropertyGroupBegin(RendererOptions, "Raytracing");
{
registerProperty(RendererOptions, m_rayTracing, "Enable");
setPropertyDescription(LightDesc, m_rayTracing, "Enable Raytracing");
}
registerPropertyGroupEnd(RendererOptions);

registerPropertyGroupBegin(RendererOptions, "Post-process");
{
registerProperty(RendererOptions, m_postProcess, "Enable");
setPropertyDescription(RendererOptions, m_postProcess, "Enable Post-Process");

registerPropertyEnum(RendererOptions, gfx::AAPostProcess, m_aaPostProcess, "Anti-aliasing");
setPropertyDescription(LightDesc, m_aaPostProcess, "Post-Process anti-aliasing");
}
registerPropertyGroupEnd(RendererOptions);

registerPropertyGroupBegin(RendererOptions, "Framegraph");
{
registerPropertyEnumBitfield(RendererOptions, RenderPassFlags, m_renderPassFlags, "Passes");
}
registerPropertyGroupEnd(RendererOptions);

registerPropertyGroupBegin(RendererOptions, "Materials");
{
registerPropertyEnumBitfield(RendererOptions, DisplayFlags, m_displayFlags, "Features");
}
registerPropertyGroupEnd(RendererOptions);

registerPropertyGroupBegin(RendererOptions, "Misc");
{
registerPropertyEx(RendererOptions, m_wireframe, "Wireframe", PropertyFlags::SingleLine);
setPropertyDescription(LightDesc, m_wireframe, "Show Wireframe");
Expand All @@ -42,19 +81,8 @@ namespace vg::renderer
registerPropertyEx(RendererOptions, m_debugUI, "Debug UI", PropertyFlags::SingleLine);
setPropertyDescription(LightDesc, m_debugUI, "Show UI debug");

registerPropertyEnum(RendererOptions, gfx::VSync, m_VSync, "VSync");
setPropertyDescription(LightDesc, m_VSync, "Sync display frequency with monitor refresh rate");

registerPropertyEnum(RendererOptions, gfx::AntiAliasing, m_antiAliasing, "Anti-Aliasing");
setPropertyDescription(LightDesc, m_antiAliasing, "Screen-space anti-aliasing technique");

registerPropertyEnum(RendererOptions, gfx::HDR, m_HDRmode, "HDR");
setPropertyDescription(LightDesc, m_HDRmode, "High-dynamic range display mode");

registerPropertyEx(RendererOptions, m_backgroundColor, "Background", PropertyFlags::Color);
setPropertyDescription(LightDesc, m_backgroundColor, "Scene background color");

registerPropertyEnumBitfield(RendererOptions, RenderPassFlags, m_renderPassFlags, "Passes");
}
registerPropertyGroupEnd(RendererOptions);

Expand All @@ -76,6 +104,10 @@ namespace vg::renderer

m_hdrProp = GetClassDesc()->GetPropertyByName("m_HDRmode");
m_vsyncProp = GetClassDesc()->GetPropertyByName("m_VSync");
m_aaPostProcessProp = GetClassDesc()->GetPropertyByName("m_aaPostProcess");

// Temp: disable SMAA
m_aaPostProcessProp->SetEnumValueFlags((u64)gfx::AAPostProcess::SMAA, EnumValueFlags::Disabled, true);
}

//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -130,17 +162,17 @@ namespace vg::renderer
}

//--------------------------------------------------------------------------------------
gfx::AntiAliasing RendererOptions::GetAliasing() const
gfx::AAPostProcess RendererOptions::GetAAPostProcess() const
{
return m_antiAliasing;
return m_aaPostProcess;
}

//--------------------------------------------------------------------------------------
bool RendererOptions::SetAliasing(const gfx::AntiAliasing & _aa)
bool RendererOptions::SetAAPostProcess(const gfx::AAPostProcess & _aa)
{
if (m_antiAliasing != _aa)
if (m_aaPostProcess != _aa)
{
m_antiAliasing = _aa;
m_aaPostProcess = _aa;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ namespace vg::renderer
}

const auto * options = RendererOptions::get();
const auto aaMode = options->GetAliasing();
const auto aaMode = options->GetAAPostProcess();
switch (aaMode)
{
default:
VG_ASSERT_ENUM_NOT_IMPLEMENTED(aaMode);

case AntiAliasing::None:
case AAPostProcess::None:
break;

case AntiAliasing::FXAA:
shaderKey.setFlag(PostProcessHLSLDesc::AntiAliasingMode, (uint)AntiAliasing::FXAA);
case AAPostProcess::FXAA:
shaderKey.setFlag(PostProcessHLSLDesc::AAPostProcess, (uint)AAPostProcess::FXAA);
break;

case AntiAliasing::SMAA:
shaderKey.setFlag(PostProcessHLSLDesc::AntiAliasingMode, (uint)AntiAliasing::SMAA);
case AAPostProcess::SMAA:
shaderKey.setFlag(PostProcessHLSLDesc::AAPostProcess, (uint)AAPostProcess::SMAA);
break;
}

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/View/Lit/LitView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ namespace vg::renderer
break;
}

_frameGraph.addUserPass(_renderPassContext, m_forwardTransparentPass, "ForwardTransparent");
if (options->isTransparencyEnabled())
_frameGraph.addUserPass(_renderPassContext, m_forwardTransparentPass, "ForwardTransparent");

// Render editor display to "Color"
if (toolmode)
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/renderer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@
<ClInclude Include="RenderPass\ImGui\ImGui.hpp" />
<ClInclude Include="RenderPass\ImGui\imguiAdapter.h" />
<ClInclude Include="RenderPass\ImGui\ImGuiAdapter.hpp" />
<ClInclude Include="RenderPass\ImGui\ImGuiSettings.h" />
<ClInclude Include="RenderPass\ImGui\ImGuiPass.h" />
<ClInclude Include="RenderPass\ImGui\ImGuiSettings.hpp" />
<ClInclude Include="RenderPass\Render2D\Background\BackgroundPass.h" />
<ClInclude Include="RenderPass\Render2D\Background\BackgroundPass.hpp" />
<ClInclude Include="RenderPass\Render2D\FinalBlit\FinalBlitPass.h" />
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/renderer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@
<ClInclude Include="Importer\NamingConvention\CharacterStudioBipedNamingConvention.h">
<Filter>Importer\Naming</Filter>
</ClInclude>
<ClInclude Include="RenderPass\ImGui\ImGuiSettings.h">
<Filter>Pass\ImGui</Filter>
</ClInclude>
<ClInclude Include="RenderPass\ImGui\ImGuiSettings.hpp">
<Filter>Pass\ImGui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Pass">
Expand Down

0 comments on commit 7eb3e2b

Please sign in to comment.