Skip to content

Commit dd55a68

Browse files
Merge pull request #102 from Devsh-Graphics-Programming/visibility_buffer
Visibility buffer
2 parents 4ce79ba + 8aadac2 commit dd55a68

File tree

88 files changed

+3936
-2302
lines changed

Some content is hidden

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

88 files changed

+3936
-2302
lines changed

3rdparty/spirv_cross

Submodule spirv_cross updated 603 files

examples_tests/09.ColorSpaceTest/ApplicationHandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void ApplicationHandler::performImageTest(std::string path)
182182

183183
auto tryToWrite = [&](asset::IAsset* asset)
184184
{
185+
return true;
185186
asset::IAssetWriter::SAssetWriteParams wparams(asset);
186187
return assetManager->writeAsset((io::path("imageAsset_") + finalFileNameWithExtension).c_str(), wparams);
187188
};

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ vec2 SampleSphericalMap(in vec3 v)
5858
return uv;
5959
}
6060
61-
vec3 nbl_computeLighting(inout nbl_glsl_AnisotropicViewSurfaceInteraction out_interaction, in mat2 dUV)
61+
vec3 nbl_computeLighting(inout nbl_glsl_AnisotropicViewSurfaceInteraction out_interaction)
6262
{
6363
nbl_glsl_xoroshiro64star_state_t scramble_start_state = textureLod(scramblebuf,gl_FragCoord.xy/VIEWPORT_SZ,0).rg;
6464
@@ -92,7 +92,7 @@ vec3 nbl_computeLighting(inout nbl_glsl_AnisotropicViewSurfaceInteraction out_in
9292
const float intensityScale = LIGHT_INTENSITY_SCALE;//ehh might want to render to hdr fbo and do tonemapping
9393
nbl_glsl_LightSample _sample;
9494
_sample.L = L*inversesqrt(d2);
95-
color += nbl_bsdf_cos_eval(_sample,out_interaction, dUV)*l.intensity*intensityScale/d2;
95+
color += nbl_bsdf_cos_eval(_sample,out_interaction)*l.intensity*intensityScale/d2;
9696
}
9797
9898
return color+emissive;
@@ -112,12 +112,12 @@ void main()
112112
nbl_glsl_MC_runTexPrefetchStream(nbl_glsl_MC_oriented_material_t_getTexPrefetchStream(material), UV, dUV);
113113
#endif
114114
#ifdef NORM_PRECOMP_STREAM
115-
nbl_glsl_MC_runNormalPrecompStream(nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(precomp), dUV, precomp);
115+
nbl_glsl_MC_runNormalPrecompStream(nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(material), precomp);
116116
#endif
117117
118118
119119
nbl_glsl_AnisotropicViewSurfaceInteraction inter;
120-
vec3 color = nbl_computeLighting(inter, dUV);
120+
vec3 color = nbl_computeLighting(inter);
121121
122122
OutColor = vec4(color, 1.0);
123123
}

examples_tests/21.DynamicTextureIndexing/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
//! I advise to check out this file, its a basic input handler
99
#include "../common/QToQuitEventReceiver.h"
10-
#include "nbl/asset/utils/CCPUMeshPacker.h"
1110

1211
using namespace nbl;
1312
using namespace core;

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ auto fillIotaDescriptorBindingDeclarations = [](auto* outBindings, ISpecializedS
4747
Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::ISceneManager* _smgr, bool useDenoiser) :
4848
m_useDenoiser(useDenoiser), m_driver(_driver), m_smgr(_smgr), m_assetManager(_assetManager),
4949
m_rrManager(ext::RadeonRays::Manager::create(m_driver)),
50-
#ifdef _IRR_BUILD_OPTIX_
50+
#ifdef _NBL_BUILD_OPTIX_
5151
m_optixManager(), m_cudaStream(nullptr), m_optixContext(),
5252
#endif
5353
rrShapeCache(), rrInstances(), m_prevView(), m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
@@ -60,7 +60,7 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::I
6060
while (m_useDenoiser)
6161
{
6262
m_useDenoiser = false;
63-
#ifdef _IRR_BUILD_OPTIX_
63+
#ifdef _NBL_BUILD_OPTIX_
6464
m_optixManager = ext::OptiX::Manager::create(m_driver, m_assetManager->getFileSystem());
6565
if (!m_optixManager)
6666
break;
@@ -70,12 +70,12 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::I
7070
m_optixContext = m_optixManager->createContext(0);
7171
if (!m_optixContext)
7272
break;
73-
OptixDenoiserOptions opts = {OPTIX_DENOISER_INPUT_RGB_ALBEDO_NORMAL,OPTIX_PIXEL_FORMAT_HALF3};
73+
OptixDenoiserOptions opts = {OPTIX_DENOISER_INPUT_RGB_ALBEDO_NORMAL};
7474
m_denoiser = m_optixContext->createDenoiser(&opts);
7575
if (!m_denoiser)
7676
break;
7777

78-
m_useDenoiser = true;
78+
m_useDenoiser = false; // TODO
7979
#endif
8080
break;
8181
}
@@ -913,7 +913,7 @@ void Renderer::deinit()
913913

914914
glFinish();
915915

916-
#ifdef _IRR_BUILD_OPTIX_
916+
#ifdef _NBL_BUILD_OPTIX_
917917
if (m_cudaStream)
918918
cuda::CCUDAHandler::cuda.pcuStreamSynchronize(m_cudaStream);
919919
m_denoiserInputBuffer = {};

examples_tests/22.RaytracedAO/Renderer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
102102
nbl::scene::ISceneManager* m_smgr;
103103

104104
nbl::core::smart_refctd_ptr<nbl::ext::RadeonRays::Manager> m_rrManager;
105-
#ifdef _IRR_BUILD_OPTIX_
105+
#ifdef _NBL_BUILD_OPTIX_
106106
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::Manager> m_optixManager;
107107
CUstream m_cudaStream;
108108
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::IContext> m_optixContext;
@@ -164,7 +164,7 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
164164
nbl::core::smart_refctd_ptr<nbl::video::IGPUImageView> m_accumulation,m_tonemapOutput;
165165
nbl::video::IFrameBuffer* m_visibilityBuffer,* m_colorBuffer,* tmpTonemapBuffer;
166166

167-
#ifdef _IRR_BUILD_OPTIX_
167+
#ifdef _NBL_BUILD_OPTIX_
168168
nbl::core::smart_refctd_ptr<nbl::ext::OptiX::IDenoiser> m_denoiser;
169169
OptixDenoiserSizes m_denoiserMemReqs;
170170
nbl::cuda::CCUDAHandler::GraphicsAPIObjLink<nbl::video::IGPUBuffer> m_denoiserInputBuffer,m_denoiserStateBuffer,m_denoisedBuffer,m_denoiserScratchBuffer;

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
2929
{
3030
return normalizedN;
3131
}
32-
vec3 worldPosition;
33-
mat2x3 dPosdScreen = mat2x3(vec3(0.0),vec3(0.0)); // TODO
34-
mat2x3 nbl_glsl_MC_getdPos()
32+
// TODO: compute from barycentrics
33+
mat2x3 nbl_glsl_perturbNormal_dPdSomething() {return mat2x3(0.0);}
34+
mat2 nbl_glsl_perturbNormal_dUVdSomething()
3535
{
36-
return dPosdScreen;
36+
return mat2(0.0);
3737
}
3838
#define _NBL_USER_PROVIDED_MATERIAL_COMPILER_GLSL_BACKEND_FUNCTIONS_
3939
#include <nbl/builtin/glsl/material_compiler/common.glsl>
@@ -115,6 +115,7 @@ void main()
115115

116116
nbl_glsl_xoroshiro64star_state_t scramble_start_state; // this should get advanced for secondary rays by 3 or 4 iterations
117117

118+
vec3 worldPosition;
118119
nbl_glsl_MC_instr_stream_t gcs;
119120
nbl_glsl_MC_instr_stream_t rnps;
120121
nbl_glsl_MC_precomputed_t precomputed;
@@ -130,16 +131,9 @@ void main()
130131
// tmp gbuffer reads
131132
const vec2 normalBuffer = texelFetch(encodedNormal,pixelCoord,0).rg;
132133
const vec2 UV = texelFetch(uvCoords,pixelCoord,0).xy;
133-
mat2 dUVdScreen = mat2(0.0,0.0,0.0,0.0);/*
134-
mat2x3 dBarydScreen;/*
135-
{
136-
// TODO: future https://diaryofagraphicsprogrammer.blogspot.com/2018/03/triangle-visibility-buffer.html
137-
vec4 data;// = texelFetch(barycentricDerivatives,pixelCoord,0);
138-
dBarydScreen[0] = vec3(data.rg,-data.r-data.g);
139-
dBarydScreen[1] = vec3(data.ba,-data.b-data.a);
140-
}
141-
dPosdScreen = mat3(vPos[0],vPos[1],vPos[2])*dBarydScreen;
142-
*/
134+
mat2 dBarydScreen = mat2(0.0); // TODO:
135+
mat2 dUVdBary = mat2(0.0); // TODO:
136+
mat2 dUVdScreen = nbl_glsl_applyChainRule2D(dUVdBary,dBarydScreen);
143137

144138
// unproject
145139
{
@@ -179,7 +173,7 @@ void main()
179173
nbl_glsl_MC_runTexPrefetchStream(nbl_glsl_MC_oriented_material_t_getTexPrefetchStream(material), UV, dUVdScreen);
180174
#endif
181175
#ifdef NORM_PRECOMP_STREAM
182-
nbl_glsl_MC_runNormalPrecompStream(nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(material), dUVdScreen, precomputed);
176+
nbl_glsl_MC_runNormalPrecompStream(nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(material), precomputed);
183177
#endif
184178
}
185179
}

examples_tests/39.DenoiserTonemapper/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ nbl_glsl_complex nbl_glsl_ext_FFT_getPaddedData(ivec3 coordinate, in uint channe
17431743
state.inMipLevel = region->imageSubresource.mipLevel;
17441744
state.outMipLevel = region->imageSubresource.mipLevel;
17451745

1746-
if (!convertFilter.execute(&state))
1746+
if (!convertFilter.execute(std::execution::par_unseq,&state))
17471747
os::Printer::log("WARNING (" + std::to_string(__LINE__) + " line): Something went wrong while converting the image!", ELL_WARNING);
17481748

17491749
_NBL_DELETE(state.ditherState);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef _COMMON_GLSL_INCLUDED_
2+
#define _COMMON_GLSL_INCLUDED_
3+
4+
#extension GL_EXT_shader_16bit_storage: require
5+
6+
#include "common.h"
7+
8+
// defines for buffer fill pipeline
9+
#define NBL_GLSL_BARYCENTRIC_VERT_POS_OUTPUT_LOC 1
10+
#define NBL_GLSL_BARYCENTRIC_VERT_PROVOKINGPOS_OUTPUT_LOC 2
11+
#define NBL_GLSL_BARYCENTRIC_FRAG_POS_INPUT_LOC NBL_GLSL_BARYCENTRIC_VERT_POS_OUTPUT_LOC
12+
#define NBL_GLSL_BARYCENTRIC_FRAG_PROVOKINGPOS_INPUT_LOC NBL_GLSL_BARYCENTRIC_VERT_PROVOKINGPOS_OUTPUT_LOC
13+
14+
#include <nbl/builtin/glsl/virtual_geometry/virtual_attribute.glsl>
15+
struct BatchInstanceData
16+
{
17+
vec3 Ka;
18+
uint firstIndex;
19+
vec3 Kd;
20+
nbl_glsl_VG_VirtualAttributePacked_t vAttrPos;
21+
vec3 Ks;
22+
nbl_glsl_VG_VirtualAttributePacked_t vAttrUV;
23+
vec3 Ke;
24+
nbl_glsl_VG_VirtualAttributePacked_t vAttrNormal;
25+
uvec2 map_Ka_data;
26+
uvec2 map_Kd_data;
27+
uvec2 map_Ks_data;
28+
uvec2 map_Ns_data;
29+
uvec2 map_d_data;
30+
uvec2 map_bump_data;
31+
float Ns;
32+
float d;
33+
float Ni;
34+
uint extra; //flags copied from MTL metadata
35+
};
36+
37+
layout(set = 1, binding = 0, std430) readonly buffer BatchInstanceBuffer
38+
{
39+
BatchInstanceData batchInstanceData[];
40+
};
41+
42+
// non-global descriptors
43+
#include <nbl/builtin/glsl/utils/common.glsl>
44+
layout(set = 2, binding = 0, row_major, std140) uniform UBO
45+
{
46+
nbl_glsl_SBasicViewParameters params;
47+
} CamData;
48+
49+
// functions
50+
#include <nbl/builtin/glsl/virtual_geometry/virtual_attribute_fetch.glsl>
51+
vec3 nbl_glsl_fetchVtxPos(in uint vtxID, in uint drawGUID)
52+
{
53+
nbl_glsl_VG_VirtualAttributePacked_t va = batchInstanceData[drawGUID].vAttrPos;
54+
return nbl_glsl_VG_attribFetch_RGB32_SFLOAT(va,vtxID);
55+
}
56+
57+
vec2 nbl_glsl_fetchVtxUV(in uint vtxID, in uint drawGUID)
58+
{
59+
nbl_glsl_VG_VirtualAttributePacked_t va = batchInstanceData[drawGUID].vAttrUV;
60+
return nbl_glsl_VG_attribFetch_RG32_SFLOAT(va,vtxID);
61+
}
62+
63+
vec3 nbl_glsl_fetchVtxNormal(in uint vtxID, in uint drawGUID)
64+
{
65+
nbl_glsl_VG_VirtualAttributePacked_t va = batchInstanceData[drawGUID].vAttrNormal;
66+
return normalize(nbl_glsl_VG_attribFetch_RGB10A2_SNORM(va,vtxID).xyz);
67+
}
68+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef _COMMON_H_INCLUDED_
2+
#define _COMMON_H_INCLUDED_
3+
4+
5+
#define PAGE_SZ_LOG2 7
6+
#define PAGE_PADDING 8
7+
8+
#define _NBL_VT_PAGE_TABLE_BINDING 0
9+
#define _NBL_VT_FLOAT_VIEWS_BINDING 1
10+
11+
12+
#define USED_ATTRIBUTES 3
13+
#define MAX_TRIANGLES_IN_BATCH 1024
14+
15+
16+
#define SHADING_WG_SIZE_X 16
17+
#define SHADING_WG_SIZE_Y 16
18+
19+
20+
#endif

0 commit comments

Comments
 (0)