Skip to content

Commit 34d0835

Browse files
committed
Add screenSpaceAmbient option
1 parent 61a7173 commit 34d0835

15 files changed

Lines changed: 220 additions & 18 deletions

File tree

data/Shaders/lighting/deferredLighting.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void CS_DeferredLighting(int2 dispatchThreadID : SV_DispatchThreadID)
138138
depthStencilSamples[i].Load(coords, i);
139139

140140
// TODO: early out if all depth samples >= 1.0f or keep early-out per-sample?
141-
//if (depth >= 1.0f)
141+
//if (depthStencilSamples[0].depth >= 1.0f)
142142
// return;
143143

144144
GBufferSample gbufferSamples[SAMPLE_COUNT];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "screenSpaceAmbient.hlsli"
2+
#include "system/bindless.hlsli"
3+
#include "system/samplers.hlsli"
4+
#include "system/view.hlsli"
5+
#include "system/msaa.hlsli"
6+
#include "system/depthstencil.hlsli"
7+
#include "lighting/GBuffer.hlsli"
8+
9+
[numthreads(SCREEN_SPACE_AMBIENT_OCCLUSION_THREADGROUP_SIZE_X, SCREEN_SPACE_AMBIENT_OCCLUSION_THREADGROUP_SIZE_X, 1)]
10+
void CS_ScreenSpaceAmbient(int2 dispatchThreadID : SV_DispatchThreadID)
11+
{
12+
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include "gfx/Shader/HLSLDesc.h"
4+
5+
namespace vg::gfx
6+
{
7+
class ScreenSpaceAmbientHLSLDesc : public HLSLDesc
8+
{
9+
public:
10+
enum Flags : ShaderKey::Flags
11+
{
12+
// 3 bits for MSAA
13+
MSAA = 0,
14+
15+
// Reserved 11..15
16+
RayTracing = HLSLDesc::Flags::RayTracing,
17+
Toolmode = HLSLDesc::Flags::Toolmode
18+
};
19+
20+
ScreenSpaceAmbientHLSLDesc()
21+
{
22+
setFile("lighting/screenSpaceAmbient.hlsl");
23+
24+
declFlags(MSAA, ShaderStageFlags::CS, { "", "_MSAA2X", "_MSAA4X", "_MSAA8X", "_MSAA16X" });
25+
declFlag(RayTracing, ShaderStageFlags::CS, "_RAYTRACING");
26+
declFlag(Toolmode, ShaderStageFlags::CS, "_TOOLMODE");
27+
28+
auto & screenSpaceAmbientTech = declTechnique("ScreenSpaceAmbient");
29+
{
30+
screenSpaceAmbientTech.cs = declCS("CS_ScreenSpaceAmbient");
31+
screenSpaceAmbientTech.flags = (Flags)0;
32+
}
33+
}
34+
};
35+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#define SCREEN_SPACE_AMBIENT_OCCLUSION_THREADGROUP_SIZE_X 16
4+
#define SCREEN_SPACE_AMBIENT_OCCLUSION_THREADGROUP_SIZE_Y 16
5+
6+
#include "system/constants.hlsli"
7+
#include "system/packing.hlsli"
8+
9+
struct ScreenSpaceAmbientConstants
10+
{
11+
void setScreenSize (uint2 _size) { width_height = packUint16(_size.xy);}
12+
uint2 getScreenSize () { return unpackUint16(width_height); }
13+
14+
void setDepthBuffer (uint _depth) { depth_normal = packUint16low(depth_normal, _depth); }
15+
uint getDepthBuffer () { return unpackUint16low(depth_normal); }
16+
17+
void setNormalGBuffer (uint _normal) { depth_normal = packUint16high(depth_normal, _normal); }
18+
uint getNormalGBuffer () { return unpackUint16high(depth_normal); }
19+
20+
void setRWBufferOut (uint _rwbuffer){ rwbuffer = packUint16low(rwbuffer, _rwbuffer); }
21+
uint getRWBufferOut () { return unpackUint16low(rwbuffer); }
22+
23+
uint width_height;
24+
uint depth_normal;
25+
uint rwbuffer;
26+
};
27+
28+
#define ScreenSpaceAmbientConstantsCount sizeof(ScreenSpaceAmbientConstants)/sizeof(u32)
29+
30+
#ifndef __cplusplus
31+
DECL_ROOTCONSTANTS(ScreenSpaceAmbientConstants, screenSpaceAmbientConstants, 0, 0);
32+
#endif

src/gfx/Shader/ShaderManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ namespace vg::gfx
172172
}
173173
}
174174

175-
VG_ASSERT(false, "File \"%s\" not found", _file.c_str());
175+
VG_ASSERT(false, "File \"%s\" not found. Please check the corresponding HLSLDesc is declared in 'Renderer::registerShaders()'", _file.c_str());
176176
return false;
177177
}
178178

src/renderer/Camera/CameraSettings.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,29 @@ namespace vg::renderer
2323
float GetNear () const final override;
2424
float GetFar () const final override;
2525

26+
ScreenSpaceAmbient GetScreenSpaceAmbient () const final override;
2627
bool IsOutlinesEnabled () const final override;
2728
bool IsDepthOfFieldEnabled () const final override;
2829
bool IsMotionBlurEnabled () const final override;
2930
core::float4 GetFadeColor () const final override;
3031

3132
private:
32-
float m_near = 0.1f;
33-
float m_far = 1000.0f;
34-
core::IResource * m_lensRes = nullptr;
35-
float m_focalLength = 35.0f;
36-
float m_focusDistance = 3.0f;
37-
GateFitMode m_gateFitMode = GateFitMode::Vertical;
38-
float m_aperture = 4.0f;
39-
bool m_outlines = false;
40-
bool m_depthOfField = false;
41-
bool m_motionBlur = false;
42-
bool m_fade = false;
43-
core::float4 m_fadeColor = core::float4(0,0,0,1);
44-
33+
float m_near = 0.1f;
34+
float m_far = 1000.0f;
35+
36+
// lens
37+
core::IResource * m_lensRes = nullptr;
38+
float m_focalLength = 35.0f;
39+
float m_focusDistance = 3.0f;
40+
GateFitMode m_gateFitMode = GateFitMode::Vertical;
41+
float m_aperture = 4.0f;
42+
43+
// postprocess
44+
ScreenSpaceAmbient m_screenSpaceAmbient = ScreenSpaceAmbient::None;
45+
bool m_outlines = false;
46+
bool m_depthOfField = false;
47+
bool m_motionBlur = false;
48+
bool m_fade = false;
49+
core::float4 m_fadeColor = core::float4(0,0,0,1);
4550
};
4651
}

src/renderer/Camera/CameraSettings.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ namespace vg::renderer
7373

7474
registerPropertyGroupBegin(CameraSettings, "Post-processing");
7575
{
76+
registerPropertyEnum(CameraSettings, ScreenSpaceAmbient, m_screenSpaceAmbient, "Ambient");
77+
setPropertyDescription(CameraSettings, m_screenSpaceAmbient, "Screen-Space Ambient Occlusion technique")
78+
7679
registerProperty(CameraSettings, m_outlines, "Outlines");
7780
registerProperty(CameraSettings, m_depthOfField, "Depth-of-field");
78-
registerPropertyEx(CameraSettings, m_motionBlur, "Motion blur", PropertyFlags::ReadOnly);
79-
81+
//registerPropertyEx(CameraSettings, m_motionBlur, "Motion blur", PropertyFlags::ReadOnly);
8082
registerOptionalPropertyEx(CameraSettings, m_fade, m_fadeColor, "Fade", PropertyFlags::Color);
8183
}
8284
registerPropertyGroupEnd(CameraComponent);
@@ -159,6 +161,13 @@ namespace vg::renderer
159161
return m_far;
160162
}
161163

164+
165+
//--------------------------------------------------------------------------------------
166+
ScreenSpaceAmbient CameraSettings::GetScreenSpaceAmbient() const
167+
{
168+
return m_screenSpaceAmbient;
169+
}
170+
162171
//--------------------------------------------------------------------------------------
163172
bool CameraSettings::IsOutlinesEnabled() const
164173
{

src/renderer/ICameraSettings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace vg::renderer
1010
Vertical
1111
);
1212

13+
vg_enum_class(vg::renderer, ScreenSpaceAmbient, core::u8,
14+
None,
15+
SSAO
16+
);
17+
1318
class ICameraLens;
1419

1520
class ICameraSettings : public core::Object
@@ -27,6 +32,7 @@ namespace vg::renderer
2732
virtual float GetNear () const = 0;
2833
virtual float GetFar () const = 0;
2934

35+
virtual ScreenSpaceAmbient GetScreenSpaceAmbient () const = 0;
3036
virtual bool IsOutlinesEnabled () const = 0;
3137
virtual bool IsDepthOfFieldEnabled () const = 0;
3238
virtual bool IsMotionBlurEnabled () const = 0;

src/renderer/RenderPass/Compute/ComputeDeferredLighting/ComputeDeferredLightingPass.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace vg::renderer
1616
const RootSignatureTableDesc & bindlessTable = device->getBindlessTable()->getTableDesc();
1717

1818
RootSignatureDesc rsDesc;
19-
rsDesc.addRootConstants(ShaderStageFlags::CS, 0, 0, RootConstants2DCount);
19+
rsDesc.addRootConstants(ShaderStageFlags::CS, 0, 0, DeferredLightingConstantsCount);
2020
rsDesc.addTable(bindlessTable);
2121

2222
m_computeDeferredLightingRootSignature = device->addRootSignature(rsDesc);

src/renderer/RenderPass/Compute/ComputePass.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Compute/ComputePostProcess/ComputePostProcessPass.hpp"
44
#include "Compute/ComputeSkinning/ComputeSkinningPass.hpp"
5+
#include "Compute/ComputeScreenSpaceAmbient/ComputeScreenSpaceAmbientPass.hpp"
56
#include "Compute/ComputeDeferredLighting/ComputeDeferredLightingPass.hpp"
67
#include "Compute/ComputeSpecularBRDF/ComputeSpecularBRDFPass.hpp"
78
#include "Compute/ComputeIBLCubemaps/ComputeIBLCubemapsPass.hpp"

0 commit comments

Comments
 (0)