Skip to content

Commit d8e45fb

Browse files
authored
Add DDGI for global illumination (#243)
* Continue work on DDGI * Move sample counts to globals in shader to allow for setting up the probe buffers CPU side * Continued DDGI work * DDGI volume deletion Selection tool scales with size of item, even if not a model Fixed error in component inspection that would recreate an item indefinitely when a uint value was defined * Split ddgi debug to own shader * Continued DDGI work. Initial probe update close to finished. * Fix ratio calculation and add range adjustment for texture preview * Start working on step 2 of DDGI, finalizing the light contributions * Continued work on finalization shader * Continue work on probe finalize * More work on probe finalization * More DDGI stuff, feeding the blending shader and syncing resources. * Minor fixes * Add DDGI to clustering system * Add color masking to Imgui shader * Add more DDGI settings * Add switch to enable/disable terrain shadows * Continued DDGI work and added script to convert old surface definitions to new. * Add mode for converting an entire folder to the surface updater * Make DDGI buffers full precision when working * Raytracing fixes * Fix resource server not picking the correct loader * Fix bugs in material parsing * Make area lights cull in view space in shader, but passed in world space * Add texture channel masking to resource browser * Fixed typo * Bind ray tracing pipeline before binding resources to ensure the layout change doesn't invalidate the bindings * Fix lights not showing in raytracing. Also fix surface updater correctly setting the value in tags instead of putting it as XML content. * Broken, but trying to fix probe direction being wrong in finalize. * DDGI almost working * Many DDGI fixes * Got DDGI running! * Initial implementation of probe relocation feature * Add blending between GI volumes and continue work on extra DDGI features like infinite scrolling, classification, etc. * Merge together the different DDGI volume structs to one. Fix debug rendering of DDGI probes * Fix ddgi probe relocation * Add probe classification function. * Use new raytracing payload. Use true random rotation transform for DDGI instead of just rotating the current one. * Add missing attributes to GI volume component * Move graphicsfeature settings to levelsettings and projectsettings * Remove old graphics feature flatbuffer schemas * Make DDGI use project settings * Use level settings to load the terrain and vegetation stuff * Fix materials and frame scripts not detecting when a recompile is necessary * Fix validation error for shader resource access now when we do the lighting in the hit shader * Fix raytracing test pass so it doesn't flicker. Also fixes incorrect GLTF emissive calculation * Add tbui to graphics feature * Fix DDGI partial update * Fix incorrect GLTF shader implementations * Area lights were missing diffuse... * Allow interactions with viewport without explicit focus. Allows hovering to get 'focus' for picking and manipulating gadgets. * Fix materials not getting updated in the raytracing material system * Comments * -128 is 0x80, +127 is 0x7F... * Add names to resource tables * Minor fixes * Options fixes * Ensure we can't have less than the lowest required amount of rays per probe * More fixes for lowest amount of allowed rays per probe * Fix build * More build fixes * Fix test apps with new API for setting up globallight (w/o backlight garbage) * Add base level and fix include of old terrain settings. Fix DDGI compile issue * Working on fixing a raytracing bug and fixing some stupid decisions with mesh exporting * Fix physics with the new nvx format * Use uint64 for GPU offsets and sizes Also limit uniform buffer binding to size min(MaxUniformSize, buffer.size) * Fix graphics manager not triggering DDGI if raytracing is off * Some raytracing fixes * Revert max vertex count * Working on fixing what appears to be incorrect material assignment when raytracing. * Fix raytracing issues where a model with multiple primitive groups wouldn't render correctly. * Fix mesh unload double delete * Improve DDGI debugging and safe guard against negative energy * Material template generator spits out 16 bit aligned material types when used as pointers. * Remove StackAlloc in favor of ArrayAllocStack, which is a thread local linear buffer. * Fix some export issues * Material asset editor allows for copy-paste of textures using right click (copy) and middle click (paste) * Correctly scale selection boxes based on object scale * Minor fixes in material loader, mainly renaming the global state to materialLoaderState to not confuse debuggers (didn't work) * Disable point sampling for mip mapped normal maps. Technically normal maps "can't" be mipped but whatever... * Add DDGI update frequency to project settings * New syswork export with the changes done to the content * Fix bug with light grid where lights didn't have enough cells to be culled into. Miracle it ever worked. I think this could be solved in a better way, but it will work for now. * Turn on raytracing by default on models. Only does something if raytracing is enabled anyways.
1 parent 016c7ad commit d8e45fb

File tree

131 files changed

+4552
-1064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+4552
-1064
lines changed

code/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ add_subdirectory(physics)
55
add_subdirectory(application)
66
add_subdirectory(addons)
77
add_subdirectory(audio)
8-
add_subdirectory(input)
8+
add_subdirectory(input)
9+
add_subdirectory(options)

code/addons/dynui/imgui/shaders/imgui.fx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
#include "lib/shared.fxh"
1212
#include "lib/defaultsamplers.fxh"
1313

14+
1415
// put variables in push-constant block
1516
push constant ImGUI [ string Visibility = "PS|VS"; ]
1617
{
1718
mat4 TextProjectionModel;
19+
uint ColorMask;
1820
uint PackedTextureInfo;
21+
float RangeMin;
22+
float RangeMax;
1923
};
2024

2125
group(BATCH_GROUP) sampler_state TextureSampler
@@ -37,13 +41,31 @@ render_state TextState
3741
//------------------------------------------------------------------------------
3842
/**
3943
*/
40-
void UnpackTexture(uint val, out uint id, out uint type, out uint mip, out uint layer, out uint useAlpha)
44+
void
45+
UnpackTexture(uint val, out uint id, out uint type, out uint mip, out uint layer, out uint useRange, out uint useAlpha)
46+
{
47+
const uint TEXTURE_TYPE_MASK = 0xF;
48+
const uint TEXTURE_LAYER_MASK = 0xFF;
49+
const uint TEXTURE_MIP_MASK = 0xF;
50+
const uint TEXTURE_USE_RANGE_MASK = 0x1;
51+
const uint TEXTURE_USE_ALPHA_MASK = 0x1;
52+
const uint TEXTURE_ID_MASK = 0xFFF;
53+
54+
type = val & TEXTURE_TYPE_MASK;
55+
layer = (val >> 4) & TEXTURE_LAYER_MASK;
56+
mip = (val >> 12) & TEXTURE_MIP_MASK;
57+
useRange = (val >> 16) & TEXTURE_USE_RANGE_MASK;
58+
useAlpha = (val >> 17) & TEXTURE_USE_ALPHA_MASK;
59+
id = (val >> 18) & TEXTURE_ID_MASK;
60+
}
61+
62+
//------------------------------------------------------------------------------
63+
/**
64+
*/
65+
vec4
66+
UnpackMask(uint val)
4167
{
42-
type = val & 0xF;
43-
layer = (val >> 4) & 0xFF;
44-
mip = (val >> 12) & 0xFF;
45-
useAlpha = (val >> 20) & 0x1;
46-
id = (val >> 21) & 0xFFF;
68+
return vec4(val & 0x1, (val >> 1) & 0x1, (val >> 2) & 0x1, (val >> 3) & 0x1);
4769
}
4870

4971
//------------------------------------------------------------------------------
@@ -75,8 +97,8 @@ psMain(
7597
[color0] out vec4 FinalColor)
7698
{
7799
vec4 texColor;
78-
uint id, type, layer, mip, useAlpha;
79-
UnpackTexture(ImGUI.PackedTextureInfo, id, type, mip, layer, useAlpha);
100+
uint id, type, layer, mip, useAlpha, useRange;
101+
UnpackTexture(ImGUI.PackedTextureInfo, id, type, mip, layer, useRange, useAlpha);
80102
if (type == 0)
81103
texColor = sample2DLod(id, TextureSampler, UV, mip);
82104
else if (type == 1)
@@ -86,12 +108,19 @@ psMain(
86108
ivec3 size = textureSize(make_sampler3D(id, TextureSampler), int(mip));
87109
texColor = sample3DLod(id, TextureSampler, vec3(UV, layer / float(size.z)), mip);
88110
}
111+
112+
if (useRange != 0)
113+
{
114+
texColor.rgb = (texColor.rgb - ImGUI.RangeMin) / (ImGUI.RangeMax - ImGUI.RangeMin);
115+
}
89116

90117
if (useAlpha == 0)
91118
texColor.a = 1;
119+
120+
vec4 mask = UnpackMask(ImGUI.ColorMask);
92121

93122
// Since we are using sRGB output, remember to degamma
94-
FinalColor = Color * texColor;
123+
FinalColor = Color * texColor * mask;
95124
}
96125

97126

code/addons/dynui/imguicontext.cc

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,24 @@ ImguiDrawFunction(const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle<
128128

129129
struct TextureInfo
130130
{
131-
uint32 type : 4;
132-
uint32 layer : 8;
133-
uint32 mip : 8;
134-
uint32 useAlpha : 1;
135-
uint32 id : 11;
131+
uint type : 4;
132+
uint layer : 8;
133+
uint mip : 4;
134+
uint useRange : 1;
135+
uint useAlpha : 1;
136+
uint id : 11;
137+
};
138+
139+
union ColorMask
140+
{
141+
struct
142+
{
143+
uint red: 1;
144+
uint green: 1;
145+
uint blue: 1;
146+
uint alpha: 1;
147+
};
148+
uint bits = 0xF;
136149
};
137150

138151
IndexT vertexOffset = 0;
@@ -175,6 +188,7 @@ ImguiDrawFunction(const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle<
175188

176189
TextureInfo texInfo;
177190
texInfo.type = 0;
191+
texInfo.useRange = tex.useRange;
178192
texInfo.useAlpha = tex.useAlpha;
179193

180194
// set texture in shader, we shouldn't have to put it into ImGui
@@ -199,7 +213,19 @@ ImguiDrawFunction(const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle<
199213
texInfo.mip = tex.mip;
200214
texInfo.id = CoreGraphics::TextureGetBindlessHandle(texture);
201215

216+
ColorMask colorMask;
217+
colorMask.red = tex.red;
218+
colorMask.green = tex.green;
219+
colorMask.blue = tex.blue;
220+
colorMask.alpha = tex.alpha;
221+
202222
CoreGraphics::CmdPushConstants(cmdBuf, CoreGraphics::GraphicsPipeline, ImguiContext::state.packedTextureInfo, sizeof(TextureInfo), (byte*)& texInfo);
223+
CoreGraphics::CmdPushConstants(cmdBuf, CoreGraphics::GraphicsPipeline, ImguiContext::state.colorMaskConstant, sizeof(ColorMask), (byte*)&colorMask);
224+
if (texInfo.useRange)
225+
{
226+
CoreGraphics::CmdPushConstants(cmdBuf, CoreGraphics::GraphicsPipeline, ImguiContext::state.rangeMinConstant, sizeof(float), &tex.rangeMin);
227+
CoreGraphics::CmdPushConstants(cmdBuf, CoreGraphics::GraphicsPipeline, ImguiContext::state.rangeMaxConstant, sizeof(float), &tex.rangeMax);
228+
}
203229

204230
// setup primitive
205231
CoreGraphics::PrimitiveGroup primitive;
@@ -343,6 +369,9 @@ ImguiContext::Create()
343369

344370
state.textProjectionConstant = CoreGraphics::ShaderGetConstantBinding(state.uiShader, "TextProjectionModel");
345371
state.packedTextureInfo = CoreGraphics::ShaderGetConstantBinding(state.uiShader, "PackedTextureInfo");
372+
state.rangeMinConstant = CoreGraphics::ShaderGetConstantBinding(state.uiShader, "RangeMin");
373+
state.rangeMaxConstant = CoreGraphics::ShaderGetConstantBinding(state.uiShader, "RangeMax");
374+
state.colorMaskConstant = CoreGraphics::ShaderGetConstantBinding(state.uiShader, "ColorMask");
346375

347376
state.inputHandler = ImguiInputHandler::Create();
348377
Input::InputServer::Instance()->AttachInputHandler(Input::InputPriority::DynUi, state.inputHandler.upcast<Input::InputHandler>());
@@ -353,7 +382,7 @@ ImguiContext::Create()
353382
components.Append(VertexComponent(1, VertexComponent::Float2, 0));
354383
components.Append(VertexComponent(2, VertexComponent::UByte4N, 0));
355384
state.vlo = CoreGraphics::CreateVertexLayout({ .name = "ImGui"_atm, .comps = components });
356-
385+
357386
#if WITH_NEBULA_EDITOR
358387
if (App::GameApplication::IsEditorEnabled())
359388
{
@@ -394,6 +423,24 @@ ImguiContext::Create()
394423
});
395424
}
396425

426+
FrameScript_default::RegisterSubgraphPipelines_ImGUI_Pass([](const CoreGraphics::PassId pass, uint subpass)
427+
{
428+
CoreGraphics::InputAssemblyKey inputAssembly{ CoreGraphics::PrimitiveTopology::TriangleList, false };
429+
if (state.editorPipeline != CoreGraphics::InvalidPipelineId)
430+
CoreGraphics::DestroyGraphicsPipeline(state.editorPipeline);
431+
state.pipeline = CoreGraphics::CreateGraphicsPipeline({ state.prog, pass, subpass, inputAssembly });
432+
});
433+
434+
FrameScript_default::RegisterSubgraph_ImGUI_Pass([](const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle<int>& viewport, const IndexT frame, const IndexT bufferIndex)
435+
{
436+
#ifdef NEBULA_NO_DYNUI_ASSERTS
437+
ImguiContext::RecoverImGuiContextErrors();
438+
#endif
439+
//ImGui::Render();
440+
//ImguiDrawFunction(cmdBuf, viewport, false);
441+
});
442+
443+
397444
SizeT numBuffers = CoreGraphics::GetNumBufferedFrames();
398445

399446
CoreGraphics::BufferCreateInfo vboInfo;

code/addons/dynui/imguicontext.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ struct ImguiTextureId
3131
uint layer : 8 = 0;
3232
uint mip : 4 = 0;
3333
uint useAlpha : 1 = 0;
34+
uint useRange : 1 = 0;
35+
float rangeMin, rangeMax;
36+
uint red : 1 = 1;
37+
uint green : 1 = 1;
38+
uint blue : 1 = 1;
39+
uint alpha : 1 = 1;
40+
3441
};
3542

3643
class ImguiContext : public Graphics::GraphicsContext
@@ -79,6 +86,9 @@ class ImguiContext : public Graphics::GraphicsContext
7986

8087
IndexT textProjectionConstant;
8188
IndexT packedTextureInfo;
89+
IndexT rangeMinConstant;
90+
IndexT rangeMaxConstant;
91+
IndexT colorMaskConstant;
8292
CoreGraphics::ResourceTableId resourceTable;
8393
//Ptr<CoreGraphics::BufferLock> vboBufferLock;
8494
//Ptr<CoreGraphics::BufferLock> iboBufferLock;

code/addons/graphicsfeature/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
nebula_begin_module(graphicsfeature)
2-
nebula_flatc(SYSTEM graphicsfeature/graphicsfeatureschema.fbs graphicsfeature/terrainschema.fbs graphicsfeature/vegetationschema.fbs)
32
fips_deps(render application dynui tbui nflatbuffer)
43
target_precompile_headers(graphicsfeature PRIVATE <application/stdneb.h>)
54
fips_ide_group(features)
@@ -20,6 +19,7 @@ fips_dir(components)
2019
decal.json
2120
lighting.json
2221
model.json
22+
gi.json
2323
)
2424
nebula_end_module()
2525

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"namespace": "GraphicsFeature",
3+
"components": {
4+
"DDGIVolume": {
5+
"graphicsEntityId": {
6+
"type": "uint",
7+
"default": -1,
8+
"hideInInspector": true
9+
},
10+
"numProbesX": {
11+
"type": "uint",
12+
"default": 8
13+
},
14+
"numProbesY": {
15+
"type": "uint",
16+
"default": 8
17+
},
18+
"numProbesZ": {
19+
"type": "uint",
20+
"default": 8
21+
},
22+
"numRaysPerProbe": {
23+
"type": "uint",
24+
"default": 188
25+
},
26+
"relocate": {
27+
"type": "bool",
28+
"default": false,
29+
"description": "Relocate probes if they are inside geometry"
30+
},
31+
"scrolling": {
32+
"type": "bool",
33+
"default": false,
34+
"description": "Scroll probes infinitely based on camera position"
35+
},
36+
"updateBudget": {
37+
"type": "float",
38+
"default": 1.0,
39+
"description": "Percentage of probes to update per frame, 1.0 means 100%"
40+
},
41+
"classify": {
42+
"type": "bool",
43+
"default": false,
44+
"description": "Automatically disable probes that hit no geometry. This is to save performance. Said probes shoot a minimal set of rays to check if they should invalidate their status"
45+
},
46+
"irradianceScale": {
47+
"type": "float",
48+
"default": 1,
49+
"description": "Energy of output irradiance"
50+
},
51+
"normalBias": {
52+
"type": "float",
53+
"default": 0.1,
54+
"description": "Adds distance on surface along normal direction to avoid aliasing"
55+
},
56+
"viewBias": {
57+
"type": "float",
58+
"default": 0.1,
59+
"description": "Adds distance on surface along camera view direction to avoid aliasing"
60+
},
61+
"distanceExponent": {
62+
"type": "float",
63+
"default": 50
64+
},
65+
"hysteresis": {
66+
"type": "float",
67+
"default": 0.97
68+
},
69+
"borderBlendCutoff": {
70+
"type": "float",
71+
"default": 0.0,
72+
"description": "Percentage distance from the volume edge where blending should start"
73+
},
74+
"borderBlend": {
75+
"type": "float",
76+
"default": 0.0,
77+
"description": "Blend gradient factor based on cutoff point and outer edge of volume"
78+
}
79+
}
80+
}
81+
}

code/addons/graphicsfeature/components/model.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"default": -1,
1212
"hideInInspector": true
1313
},
14-
"raytracing": "bool",
14+
"raytracing": {
15+
"type": "bool",
16+
"default": true
17+
},
1518
"anim": {
1619
"type": "resource",
1720
"default": ""

0 commit comments

Comments
 (0)