Skip to content

Commit 2f75a8d

Browse files
Merge branch 'master' into erfan_todos
2 parents da4b8c2 + 93fc8bd commit 2f75a8d

File tree

11 files changed

+111
-108
lines changed

11 files changed

+111
-108
lines changed

artifacts/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ add_custom_target(pack_artifact_ditt
3636
COMMAND cmake -E copy ${EXAMPLES_TESTS_PATH}/media/kernels/physical_flare_256.exr ${CMAKE_CURRENT_BINARY_DIR}/Ditt/pack/media/kernels/physical_flare_256.exr
3737
COMMAND cmake -E copy ${EXAMPLES_TESTS_PATH}/media/kernels/physical_flare_512.exr ${CMAKE_CURRENT_BINARY_DIR}/Ditt/pack/media/kernels/physical_flare_512.exr
3838

39+
COMMAND cmake -E copy ${EXAMPLES_TESTS_PATH}/media/mitsuba/staircase2.zip ${CMAKE_CURRENT_BINARY_DIR}/Ditt/pack/media/mitsuba/staircase2.zip
40+
3941
COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/Ditt && cmake -E tar -cvj Ditt.tar.bz2 pack/
4042
)

examples_tests/22.RaytracedAO/closestHit.comp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ void main()
6969
const uvec3 indices = get_triangle_indices(batchInstanceData,triangleID);
7070

7171
// positions
72-
vec3 geomDenormal;
73-
const vec3 lastVxPos = load_positions(geomDenormal,batchInstanceData,indices);
74-
const bool frontfacing = bool((batchInstanceData.determinantSignBit^floatBitsToUint(dot(geomDenormal,normalizedV)))&0x80000000u);
72+
vec3 geomNormal;
73+
const vec3 lastVxPos = load_positions(geomNormal,batchInstanceData,indices);
74+
75+
const bool frontfacing = bool((batchInstanceData.determinantSignBit^floatBitsToUint(dot(normalizedV,geomNormal)))&0x80000000u);
7576

7677
// get material
7778
const nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(batchInstanceData.material,frontfacing);
7879
contrib.color = contrib.albedo = nbl_glsl_MC_oriented_material_t_getEmissive(material);
7980

8081
const uint pathDepth = bitfieldExtract(staticViewData.pathDepth_noRussianRouletteDepth_samplesPerPixelPerDispatch,0,8);
81-
const bool _continue = vertex_depth!=pathDepth && ray.maxT==nbl_glsl_FLT_MAX; // not last vertex and not NEE path
82+
const bool _continue = vertex_depth!=pathDepth && material.genchoice_count!=0u && ray.maxT==nbl_glsl_FLT_MAX; // not last vertex and has a BxDF and not NEE path
8283
if (_continue)
8384
{
8485
// if we ever support spatially varying emissive, we'll need to hoist barycentric computation and UV fetching to the position fetching
@@ -89,7 +90,7 @@ void main()
8990

9091
//
9192
normalizedN = load_normal_and_prefetch_textures(
92-
batchInstanceData,indices,compactBary,geomDenormal,material
93+
batchInstanceData,indices,compactBary,geomNormal,material
9394
#ifdef TEX_PREFETCH_STREAM
9495
,mat2(0.0) // TODO: Covariance Rendering
9596
#endif
@@ -103,10 +104,10 @@ void main()
103104
);
104105
}
105106
else
106-
contrib.worldspaceNormal = normalize(geomDenormal)*nbl_glsl_MC_colorToScalar(contrib.albedo);
107+
contrib.worldspaceNormal = geomNormal*nbl_glsl_MC_colorToScalar(contrib.albedo);
107108
}
108109
else
109-
Contribution_initMiss(contrib);
110+
Contribution_initMiss(contrib,aovThroughputScale);
110111

111112
Contribution_normalizeAoV(contrib);
112113

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,35 +79,41 @@ void main()
7979
// get material while waiting for indices
8080
const nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(batchInstanceData.material,frontfacing);
8181
contrib.color = contrib.albedo = nbl_glsl_MC_oriented_material_t_getEmissive(material);
82-
82+
8383
// load vertex data
84-
vec3 geomDenormal;
85-
const vec3 lastVxPos = load_positions(geomDenormal,batchInstanceData,indices);
86-
87-
// get initial scramble key while waiting for vertex positions
88-
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = texelFetch(scramblebuf,ivec2(outPixelLocation),0).rg;
84+
vec3 geomNormal;
85+
const vec3 lastVxPos = load_positions(geomNormal,batchInstanceData,indices);
8986

90-
//
91-
normalizedN = load_normal_and_prefetch_textures(
92-
batchInstanceData,indices,compactBary,geomDenormal,material
93-
#ifdef TEX_PREFETCH_STREAM
94-
,dBarydScreen
95-
#endif
96-
);
87+
// little optimization for non-twosided materials
88+
if (material.genchoice_count!=0u)
89+
{
90+
// get initial scramble key while waiting for vertex positions
91+
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = texelFetch(scramblebuf,ivec2(outPixelLocation),0).rg;
92+
93+
//
94+
normalizedN = load_normal_and_prefetch_textures(
95+
batchInstanceData,indices,compactBary,geomNormal,material
96+
#ifdef TEX_PREFETCH_STREAM
97+
,dBarydScreen
98+
#endif
99+
);
97100

98-
const vec3 origin = dPdBary*compactBary+lastVxPos;
99-
normalizedV = normalize(pc.cummon.camPos-origin);
101+
const vec3 origin = dPdBary*compactBary+lastVxPos;
102+
normalizedV = normalize(pc.cummon.camPos-origin);
100103

101-
// generate rays
102-
const uint vertex_depth = 1u;
103-
generate_next_rays(
104-
samplesPerPixelPerDispatch,material,frontfacing,vertex_depth,
105-
scramble_start_state,pc.cummon.samplesComputed,outPixelLocation,origin,
106-
vec3(pc.cummon.rcpFramesDispatched),1.f,contrib.albedo,contrib.worldspaceNormal
107-
);
104+
// generate rays
105+
const uint vertex_depth = 1u;
106+
generate_next_rays(
107+
samplesPerPixelPerDispatch,material,frontfacing,vertex_depth,
108+
scramble_start_state,pc.cummon.samplesComputed,outPixelLocation,origin,
109+
vec3(pc.cummon.rcpFramesDispatched),1.f,contrib.albedo,contrib.worldspaceNormal
110+
);
111+
}
112+
else
113+
contrib.worldspaceNormal = geomNormal*nbl_glsl_MC_colorToScalar(contrib.albedo);
108114
}
109115
else
110-
Contribution_initMiss(contrib);
116+
Contribution_initMiss(contrib,1.f);
111117

112118
if (bool(pc.cummon.depth))
113119
{

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ void storeAccumulation(in vec3 color, in uvec3 coord)
7979
}
8080
void storeAccumulation(in vec3 prev, in vec3 delta, in uvec3 coord)
8181
{
82-
if (any(greaterThan(abs(delta),vec3(nbl_glsl_FLT_MIN*16.f))))
83-
storeAccumulation(prev+delta,coord);
82+
const vec3 newVal = prev+delta;
83+
const uvec3 diff = floatBitsToUint(newVal)^floatBitsToUint(prev);
84+
if (bool((diff.x|diff.y|diff.z)&0x7ffffff0u))
85+
storeAccumulation(newVal,coord);
8486
}
8587

8688
vec3 fetchAlbedo(in uvec3 coord)
@@ -152,7 +154,7 @@ bool has_world_transform(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchIns
152154

153155
#include <nbl/builtin/glsl/barycentric/utils.glsl>
154156
mat2x3 dPdBary;
155-
vec3 load_positions(out vec3 geomDenormal, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData, in uvec3 indices)
157+
vec3 load_positions(out vec3 geomNormal, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData, in uvec3 indices)
156158
{
157159
mat3 positions = mat3(
158160
nbl_glsl_fetchVtxPos(indices[0],batchInstanceData),
@@ -165,7 +167,7 @@ vec3 load_positions(out vec3 geomDenormal, in nbl_glsl_ext_Mitsuba_Loader_instan
165167
//
166168
for (int i=0; i<2; i++)
167169
dPdBary[i] = positions[i]-positions[2];
168-
geomDenormal = cross(dPdBary[0],dPdBary[1]);
170+
geomNormal = normalize(cross(dPdBary[0],dPdBary[1]));
169171
//
170172
if (tform)
171173
positions[2] += batchInstanceData.tform[3];
@@ -194,7 +196,7 @@ bool needs_texture_prefetch(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batch
194196

195197
vec3 load_normal_and_prefetch_textures(
196198
in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData,
197-
in uvec3 indices, in vec2 compactBary, in vec3 geomDenormal,
199+
in uvec3 indices, in vec2 compactBary, in vec3 geomNormal,
198200
in nbl_glsl_MC_oriented_material_t material
199201
#ifdef TEX_PREFETCH_STREAM
200202
,in mat2 dBarydScreen
@@ -222,7 +224,6 @@ vec3 load_normal_and_prefetch_textures(
222224
// the rest is always only needed for continuing rays
223225

224226

225-
vec3 normal = geomDenormal;
226227
// while waiting for the scramble state
227228
// TODO: optimize, add loads more flags to control this
228229
const bool needsSmoothNormals = true;
@@ -235,18 +236,20 @@ vec3 load_normal_and_prefetch_textures(
235236
);
236237

237238
// not needed for NEE unless doing Area or Projected Solid Angle Sampling
238-
const vec3 smoothNormal = normals*nbl_glsl_barycentric_expand(compactBary);
239-
// TODO: first check wouldn't be needed if we had `needsSmoothNormals` implemented
240-
if (!isnan(smoothNormal.x) && has_world_transform(batchInstanceData))
239+
vec3 smoothNormal = normals*nbl_glsl_barycentric_expand(compactBary);
240+
if (has_world_transform(batchInstanceData))
241241
{
242-
normal = vec3(
242+
smoothNormal = vec3(
243243
dot(batchInstanceData.normalMatrixRow0,smoothNormal),
244244
dot(batchInstanceData.normalMatrixRow1,smoothNormal),
245245
dot(batchInstanceData.normalMatrixRow2,smoothNormal)
246246
);
247247
}
248+
// TODO: this check wouldn't be needed if we had `needsSmoothNormals` implemented
249+
if (!isnan(smoothNormal.x))
250+
return normalize(smoothNormal);
248251
}
249-
return normalize(normal);
252+
return geomNormal;
250253
}
251254

252255
#include <nbl/builtin/glsl/sampling/quantized_sequence.glsl>
@@ -324,8 +327,8 @@ void generate_next_rays(
324327
worldspaceNormal += result.aov.normal/float(maxRaysToGen);
325328

326329
nextThroughput[i] = prevThroughput*result.quotient;
327-
// do denormalized half floats flush to 0 ?
328-
if (max(max(nextThroughput[i].x,nextThroughput[i].y),nextThroughput[i].z)>=exp2(-14.f))
330+
// TODO: add some sort of factor to this inequality that could account for highest possible emission (direct or indirect) we could encounter
331+
if (max(max(nextThroughput[i].x,nextThroughput[i].y),nextThroughput[i].z)>exp2(-19.f)) // match output mantissa (won't contribute anything afterwards)
329332
{
330333
maxT[i] = nbl_glsl_FLT_MAX;
331334
nextAoVThroughputScale[i] = prevAoVThroughputScale*result.aov.throughputFactor;
@@ -392,11 +395,11 @@ vec2 SampleSphericalMap(vec3 v)
392395
return uv;
393396
}
394397

395-
void Contribution_initMiss(out Contribution contrib)
398+
void Contribution_initMiss(out Contribution contrib, in float aovThroughputScale)
396399
{
397400
vec2 uv = SampleSphericalMap(-normalizedV);
398401
// funny little trick borrowed from things like Progressive Photon Mapping
399-
const float bias = 0.25*sqrt(pc.cummon.rcpFramesDispatched);
402+
const float bias = 0.0625f*(1.f-aovThroughputScale)*pow(pc.cummon.rcpFramesDispatched,0.08f);
400403
contrib.albedo = contrib.color = textureGrad(envMap, uv, vec2(bias*0.5,0.f), vec2(0.f,bias)).rgb;
401404
contrib.worldspaceNormal = normalizedV;
402405
}

examples_tests/39.DenoiserTonemapper/main.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ int main(int argc, char* argv[])
7979
params.Vsync = true;
8080
params.Doublebuffer = true;
8181
params.Stencilbuffer = false;
82-
params.StreamingDownloadBufferSize = 1024*1024*1024; // for 16k images
82+
// TODO: this is a temporary fix for a problem solved in the Vulkan Branch
83+
params.StreamingUploadBufferSize = 1024*1024*1024; // for Color + 2 AoV of 8k images
84+
params.StreamingDownloadBufferSize = core::roundUp(params.StreamingUploadBufferSize/3u,256u); // for output image
8385
auto device = createDeviceEx(params);
8486

8587
if (check_error(!device,"Could not create Irrlicht Device!"))
@@ -1270,8 +1272,17 @@ nbl_glsl_complex nbl_glsl_ext_FFT_getPaddedData(ivec3 coordinate, in uint channe
12701272
uint32_t inImageByteOffset[EII_COUNT];
12711273
{
12721274
asset::ICPUBuffer* buffersToUpload[EII_COUNT];
1275+
size_t inputSize = 0u;
12731276
for (uint32_t j=0u; j<denoiserInputCount; j++)
1277+
{
12741278
buffersToUpload[j] = param.image[j]->getBuffer();
1279+
inputSize += buffersToUpload[j]->getSize();
1280+
}
1281+
if (inputSize>=params.StreamingUploadBufferSize)
1282+
{
1283+
printf("[ERROR] Denoiser Failed, input too large to fit in VRAM, Streaming Denoise not implemented yet!");
1284+
return -1;
1285+
}
12751286
auto gpubuffers = driver->getGPUObjectsFromAssets(buffersToUpload,buffersToUpload+denoiserInputCount,&assetConverter);
12761287

12771288
bool skip = false;

include/nbl/builtin/glsl/material_compiler/common.glsl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,6 @@ nbl_glsl_MC_eval_pdf_aov_t nbl_glsl_MC_instr_bxdf_eval_and_pdf_common(
746746
in uint op, in bool is_not_brdf,
747747
in nbl_glsl_MC_params_t params,
748748
in mat2x3 ior, in mat2x3 ior2,
749-
#if GEN_CHOICE_STREAM>=GEN_CHOICE_WITH_AOV_EXTRACTION
750-
in vec3 normal,
751-
#endif
752749
in float absOrMaxNdotV,
753750
in float absOrMaxNdotL,
754751
in nbl_glsl_LightSample s,
@@ -775,7 +772,7 @@ nbl_glsl_MC_eval_pdf_aov_t nbl_glsl_MC_instr_bxdf_eval_and_pdf_common(
775772
const float a = nbl_glsl_MC_params_getAlpha(params);
776773
const float a2 = a*a;
777774
#if GEN_CHOICE_STREAM>=GEN_CHOICE_WITH_AOV_EXTRACTION
778-
result.aov.normal = normal;
775+
result.aov.normal = currInteraction.inner.isotropic.N;
779776
#endif
780777

781778
#if defined(OP_DIFFUSE) || defined(OP_DIFFTRANS)
@@ -961,9 +958,6 @@ void nbl_glsl_MC_instr_eval_and_pdf_execute(
961958
{
962959
result = nbl_glsl_MC_instr_bxdf_eval_and_pdf_common(
963960
instr,op,is_not_brdf,params,ior,ior2,
964-
#if GEN_CHOICE_STREAM>=GEN_CHOICE_WITH_AOV_EXTRACTION
965-
precomp.N,
966-
#endif
967961
NdotV,NdotL,
968962
s,microfacet,run
969963
);
@@ -1235,7 +1229,7 @@ nbl_glsl_LightSample nbl_bsdf_cos_generate(
12351229
const float ax = nbl_glsl_MC_params_getAlpha(params);
12361230
const float ax2 = ax*ax;
12371231
#if GEN_CHOICE_STREAM>=GEN_CHOICE_WITH_AOV_EXTRACTION
1238-
out_values.aov.normal = precomp.N;
1232+
out_values.aov.normal = currInteraction.inner.isotropic.N;
12391233
#endif
12401234

12411235
// TODO: refactor

include/nbl/builtin/glsl/material_compiler/common_invariant_declarations.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct nbl_glsl_MC_instr_stream_t
3737
// (in case of precomp.NdotV<0.0, currInteraction will be set with -precomp.N)
3838
struct nbl_glsl_MC_precomputed_t
3939
{
40+
// TODO: shadingN and geomN
4041
vec3 N;
4142
vec3 V;
4243
bool frontface;
@@ -82,6 +83,7 @@ void nbl_glsl_MC_finalizeMicrofacet(inout nbl_glsl_MC_microfacet_t mf)
8283
struct nbl_glsl_MC_oriented_material_t
8384
{
8485
uvec2 emissive;
86+
// TODO: derive/define upper bounds for instruction counts and bitpack them!
8587
uint prefetch_offset;
8688
uint prefetch_count;
8789
uint instr_offset;

src/nbl/asset/interchange/CImageLoaderJPG.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,11 @@ bool CImageLoaderJPG::isALoadableFileFormat(system::IFile* _file, const system::
156156
if (!_file)
157157
return false;
158158

159-
int32_t jfif = 0;
160-
159+
uint32_t header = 0;
161160
system::future<size_t> future;
162-
_file->read(future, &jfif, 6, sizeof(uint32_t));
161+
_file->read(future, &header, 6, sizeof(uint32_t));
163162
future.get();
164-
return (jfif == 0x4a464946 || jfif == 0x4649464a || jfif == 0x66697845u || jfif == 0x70747468u); // maybe 0x4a464946 can go
163+
return (header&0x00FFD8FFu)==0x00FFD8FFu;
165164
#endif
166165
}
167166

src/nbl/ext/MitsubaLoader/CElementBSDF.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -725,23 +725,25 @@ bool CElementBSDF::processChildData(IElement* _child, const std::string& name)
725725
//{"albedo", processAlbedo}
726726
};
727727

728-
auto found = SetChildMap.find(name);
729-
if (found==SetChildMap.end())
728+
switch (type)
730729
{
731-
switch (type)
732-
{
733-
case Type::BUMPMAP:
734-
bumpmap.texture = _texture;
735-
break;
736-
default:
737-
_NBL_DEBUG_BREAK_IF(true);
738-
ParserLog::invalidXMLFileStructure("No BSDF can have such property set with name: " + name);
739-
return false;
740-
break;
741-
}
730+
case Type::BUMPMAP:
731+
bumpmap.texture = _texture;
732+
break;
733+
default:
734+
{
735+
auto found = SetChildMap.find(name);
736+
if (found!=SetChildMap.end())
737+
found->second();
738+
else
739+
{
740+
_NBL_DEBUG_BREAK_IF(true);
741+
ParserLog::invalidXMLFileStructure("No BSDF can have such property set with name: " + name);
742+
return false;
743+
}
744+
}
745+
break;
742746
}
743-
else
744-
found->second();
745747

746748
if (error)
747749
return false;

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,10 +967,16 @@ void CMitsubaLoader::cacheTexture(SContext& ctx, uint32_t hierarchyLevel, const
967967
// check if found
968968
auto contentRange = bundle.getContents();
969969
if (contentRange.empty())
970+
{
971+
os::Printer::log("[ERROR] Could Not Find Texture: "+cacheKey,ELL_ERROR);
970972
return;
973+
}
971974
auto asset = contentRange.begin()[0];
972975
if (asset->getAssetType()!=asset::IAsset::ET_IMAGE)
976+
{
977+
os::Printer::log("[ERROR] Loaded an Asset but it wasn't a texture, was E_ASSET_TYPE "+std::to_string(asset->getAssetType()),ELL_ERROR);
973978
return;
979+
}
974980

975981
viewParams.image = core::smart_refctd_ptr_static_cast<asset::ICPUImage>(asset);
976982
}
@@ -1086,12 +1092,6 @@ auto CMitsubaLoader::genBSDFtreeTraversal(SContext& ctx, const CElementBSDF* _bs
10861092
if (const_or_tex.value.type==SPropertyElementData::INVALID)
10871093
cacheTexture(ctx,0u,const_or_tex.texture,semantic);
10881094
};
1089-
auto unrollScales = [](CElementTexture* tex)
1090-
{
1091-
while (tex->type == CElementTexture::SCALE)
1092-
tex = tex->scale.texture;
1093-
return tex;
1094-
};
10951095

10961096
core::stack<const CElementBSDF*> stack;
10971097
stack.push(_bsdf);

0 commit comments

Comments
 (0)