Skip to content

Commit 8bc1b66

Browse files
committed
Resolved last comments in mat compiler
1 parent c656613 commit 8bc1b66

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,12 @@ void instr_eval_and_pdf_execute(in instr_t instr, in MC_precomputed_t precomp, i
572572
#if defined(OP_DIFFUSE) || defined(OP_DIFFTRANS)
573573
if (op_isDiffuse(op))
574574
{
575-
eval = albedo * irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(pdf, a2, s.VdotL, NdotL, NdotV);
576-
pdf *= is_bsdf ? 0.5 : 1.0;
577-
eval *= pdf;
575+
if (NdotL > FLT_MIN)
576+
{
577+
eval = albedo * irr_glsl_oren_nayar_cos_remainder_and_pdf_wo_clamps(pdf, a2, s.VdotL, NdotL, NdotV);
578+
pdf *= is_bsdf ? 0.5 : 1.0;
579+
eval *= pdf;
580+
}
578581
}
579582
else
580583
#endif

include/irr/builtin/material_compiler/glsl/rasterization/impl.glsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ void instr_eval_execute(in instr_t instr, in MC_precomputed_t precomp, inout irr
77
{
88
const uint op = instr_getOpcode(instr);
99
const bool is_bxdf = op_isBXDF(op);
10-
const bool is_bsdf = !op_isBRDF(op); //note it actually tells if op is BSDF or BUMPMAP or SET_GEOM_NORMAL (divergence reasons)
10+
const bool is_bsdf = !op_isBRDF(op); //note: true for everything besides BRDF ops (combiners, SET_GEOM_NORMAL and BUMPMAP too)
1111
const float cosFactor = irr_glsl_conditionalAbsOrMax(is_bsdf, s.NdotL, 0.0);
1212
const float NdotV = irr_glsl_conditionalAbsOrMax(is_bsdf, currInteraction.inner.isotropic.NdotV, 0.0);
13-
bool is_valid = (NdotV > FLT_MIN);
14-
const bool positiveCosFactor = cosFactor > FLT_MIN && is_valid;
13+
const bool positiveCosFactors = (cosFactor > FLT_MIN) && (NdotV > FLT_MIN);
1514
const bool is_bxdf_or_combiner = op_isBXDForCoatOrBlend(op);
1615

1716
uvec3 regs = instr_decodeRegisters(instr);
@@ -21,7 +20,7 @@ void instr_eval_execute(in instr_t instr, in MC_precomputed_t precomp, inout irr
2120
MC_microfacet_t microfacet;
2221
bsdf_data_t bsdf_data;
2322

24-
const bool run = !skip && positiveCosFactor;
23+
const bool run = !skip && positiveCosFactors;
2524

2625
if (run && is_bxdf_or_combiner)
2726
{
@@ -39,6 +38,7 @@ void instr_eval_execute(in instr_t instr, in MC_precomputed_t precomp, inout irr
3938
const float rcp_eta = 1.0 / eta;
4039

4140
bool refraction = false;
41+
bool is_valid = true;
4242
#ifdef OP_DIELECTRIC
4343
if (op == OP_DIELECTRIC && irr_glsl_isTransmissionPath(currInteraction.inner.isotropic.NdotV, s.NdotL))
4444
{
@@ -54,12 +54,12 @@ void instr_eval_execute(in instr_t instr, in MC_precomputed_t precomp, inout irr
5454

5555
const vec3 albedo = params_getReflectance(params);
5656
const float a = params_getAlpha(params);
57-
const float a2 = a * a;
57+
const float a2 = a*a;
5858

5959
#if defined(OP_DIFFUSE) || defined(OP_DIFFTRANS)
6060
if (op_isDiffuse(op))
6161
{
62-
result = albedo * irr_glsl_oren_nayar_cos_eval(s, currInteraction.inner.isotropic, a2);
62+
result = albedo * (is_bsdf ? 0.5 : 1.0) * irr_glsl_oren_nayar_cos_eval_wo_clamps(a2, s.VdotL, cosFactor, NdotV);
6363
}
6464
else
6565
#endif

0 commit comments

Comments
 (0)