Skip to content

Commit 95a38b6

Browse files
committed
More mitsuba-related bugfixes
It think something's wrong with specular part of instr_eval_execute(), point lights end up extremely bright in ditt scene
1 parent f2b9e52 commit 95a38b6

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

include/irr/builtin/glsl/sampling/cos_weighted.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
vec3 irr_glsl_projected_hemisphere_generate(in vec2 _sample)
77
{
8-
vec2 p = irr_glsl_concentricMapping(_sample);
8+
vec2 p = irr_glsl_concentricMapping(_sample*0.99999+0.000005);
99

1010
float z = sqrt(max(0.0, 1.0 - p.x*p.x - p.y*p.y));
1111

include/irr/builtin/material_compiler/glsl/common.glsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,8 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
918918
out_microfacet.inner = irr_glsl_calcAnisotropicMicrofacetCache(currInteraction.inner, s);
919919
finalizeMicrofacet(out_microfacet);
920920

921-
rem = albedo*irr_glsl_oren_nayar_cos_remainder_and_pdf(localPdf, s, currInteraction.inner.isotropic, ax2);
921+
const float NdotL = irr_glsl_conditionalAbsOrMax(is_bsdf, s.NdotL, 0.0);
922+
rem = albedo*irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(localPdf, ax2, dot(currInteraction.inner.isotropic.V.dir, s.L), NdotL, NdotV);
922923
localPdf *= is_bsdf ? 0.5 : 1.0;
923924
} else
924925
#endif
@@ -927,8 +928,8 @@ irr_glsl_LightSample irr_bsdf_cos_generate(in MC_precomputed_t precomp, in instr
927928
{
928929
localPdf = 1.0;
929930

930-
const float TdotV2 = currInteraction.inner.TdotV * currInteraction.inner.TdotV;
931-
const float BdotV2 = currInteraction.inner.BdotV * currInteraction.inner.BdotV;
931+
const float TdotV2 = currInteraction.TdotV2;
932+
const float BdotV2 = currInteraction.BdotV2;
932933
const float NdotV2 = currInteraction.inner.isotropic.NdotV_squared;
933934

934935
const vec3 upperHemisphereLocalV = currInteraction.inner.isotropic.NdotV < 0.0 ? -localV : localV;

include/irr/builtin/shaders/loaders/mitsuba/instance_data_struct.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct InstanceData
1111
vec3 normalMatrixRow2;
1212
uint _padding;//not needed
1313
uvec2 emissive;
14+
float determinant;
1415
uint front_prefetch_count;
1516
uint front_nprecomp_count;
1617
uint front_genchoice_count;

include/irr/ext/MitsubaLoader/CMitsubaLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class CMitsubaLoader : public asset::IAssetLoader
5353
};
5454
} normalMat;
5555
uint64_t emissive;//uvec2, rgb19e7
56+
float determinant;
5657
uint32_t front_prefetch_count;
5758
uint32_t front_nprecomp_count;
5859
uint32_t front_genchoice_count;

src/irr/asset/material_compiler/CMaterialCompilerGLSLBackendCommon.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace material_compiler
2929
coat->eta = coat_blend->eta;
3030
coat->ndf = coat_blend->ndf;
3131
coat->shadowing = coat_blend->shadowing;
32+
coat->thin = false;
3233
}
3334
cache->insert({ coat_blend, coat });
3435

src/irr/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void main()
284284
mat2 dUV = mat2(dFdx(UV),dFdy(UV));
285285
286286
// "The sign of this computation is negated when the value of GL_CLIP_ORIGIN (the clip volume origin, set with glClipControl) is GL_UPPER_LEFT."
287-
const bool front = !gl_FrontFacing;
287+
const bool front = (!gl_FrontFacing) != (InstData.data[InstanceIndex].determinant < 0.0);
288288
MC_precomputed_t precomp = precomputeData(front);
289289
#ifdef TEX_PREFETCH_STREAM
290290
runTexPrefetchStream(getTexPrefetchStream(precomp), UV, dUV);
@@ -1704,6 +1704,7 @@ inline core::smart_refctd_ptr<asset::ICPUDescriptorSet> CMitsubaLoader::createDS
17041704
SInstanceData instData;
17051705

17061706
instData.tform = inst.tform;
1707+
instData.determinant = instData.tform.getPseudoDeterminant().x;
17071708
instData.tform.getSub3x3InverseTranspose(instData.normalMat.normalMatrix);
17081709
instData.emissive = core::rgb32f_to_rgb19e7(emissive.pointer);
17091710

src/irr/ext/MitsubaLoader/CMitsubaMaterialCompilerFrontend.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,14 @@ auto CMitsubaMaterialCompilerFrontend::compileToIRTree(asset::material_compiler:
417417
if (bsdf->type == IR::CBSDFNode::ET_MICROFACET_DIELECTRIC)
418418
{
419419
auto* dielectric = static_cast<const IR::CMicrofacetDielectricBSDFNode*>(bsdf);
420-
if (!dielectric->thin) // do not copy thin dielectrics
421-
{
422-
auto* copy = static_cast<IR::CMicrofacetDielectricBSDFNode*>(ir->copyNode(front));
420+
auto* copy = static_cast<IR::CMicrofacetDielectricBSDFNode*>(ir->copyNode(front));
421+
if (!copy->thin) //we're always outside in case of thin dielectric
423422
copy->eta = IRNode::color_t(1.f) / copy->eta;
424423

425-
return copy;
426-
}
424+
return copy;
427425
}
426+
else if (bsdf->type == IR::CBSDFNode::ET_MICROFACET_DIFFTRANS)
427+
return ir->copyNode(front);
428428
}
429429
[[fallthrough]]; // intentional
430430
default:

0 commit comments

Comments
 (0)