Skip to content

Commit 8b3baeb

Browse files
world space position is not needed for the material compiler, only derivatives of the position
1 parent c2ff831 commit 8b3baeb

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

include/nbl/builtin/glsl/bxdf/common.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mat2x4 nbl_glsl_applyScreenSpaceChainRule4D3(in mat3x4 dFdG, in mat2x3 dGdScreen
134134
return dFdG*dGdScreen;
135135
}
136136

137-
nbl_glsl_IsotropicViewSurfaceInteraction nbl_glsl_calcSurfaceInteractionFromViewVector(in vec3 _View, in vec3 _SurfacePos, in vec3 _Normal, in mat2x3 dpd_)
137+
nbl_glsl_IsotropicViewSurfaceInteraction nbl_glsl_calcSurfaceInteractionFromViewVector(in vec3 _View, in vec3 _Normal, in mat2x3 dpd_)
138138
{
139139
nbl_glsl_IsotropicViewSurfaceInteraction interaction;
140140
interaction.V.dir = _View;
@@ -152,7 +152,7 @@ nbl_glsl_IsotropicViewSurfaceInteraction nbl_glsl_calcSurfaceInteractionFromView
152152
nbl_glsl_IsotropicViewSurfaceInteraction nbl_glsl_calcSurfaceInteraction(in vec3 _CamPos, in vec3 _SurfacePos, in vec3 _Normal, in mat2x3 dpd_)
153153
{
154154
vec3 V = _CamPos - _SurfacePos;
155-
return nbl_glsl_calcSurfaceInteractionFromViewVector(V, _SurfacePos, _Normal, dpd_);
155+
return nbl_glsl_calcSurfaceInteractionFromViewVector(V, _Normal, dpd_);
156156
}
157157

158158
nbl_glsl_AnisotropicViewSurfaceInteraction nbl_glsl_calcAnisotropicInteraction(in nbl_glsl_IsotropicViewSurfaceInteraction isotropic, in vec3 T, in vec3 B)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <nbl/builtin/glsl/material_compiler/common_declarations.glsl>
55

66
#ifndef _NBL_USER_PROVIDED_MATERIAL_COMPILER_GLSL_BACKEND_FUNCTIONS_
7-
#error "You need to define 'vec3 nbl_glsl_MC_getNormalizedWorldSpaceV()', 'vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()' , 'nbl_glsl_MC_getWorldSpacePosition()', 'mat2x3 nbl_glsl_MC_getdPos(in vec3 p)' functions above"
7+
#error "You need to define 'vec3 nbl_glsl_MC_getNormalizedWorldSpaceV()', 'vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()', 'mat2x3 nbl_glsl_MC_getdPos()' functions above"
88
#endif
99

1010
#include <nbl/builtin/glsl/math/functions.glsl>
@@ -16,7 +16,6 @@ nbl_glsl_MC_precomputed_t nbl_glsl_MC_precomputeData(in bool frontface)
1616
p.N = nbl_glsl_MC_getNormalizedWorldSpaceN();
1717
p.V = nbl_glsl_MC_getNormalizedWorldSpaceV();
1818
p.frontface = frontface;
19-
p.pos = nbl_glsl_MC_getWorldSpacePosition();
2019

2120
return p;
2221
}
@@ -339,21 +338,21 @@ mat2x4 nbl_glsl_MC_instr_fetchSrcRegs(in nbl_glsl_MC_instr_t i)
339338
return nbl_glsl_MC_instr_fetchSrcRegs(i, r);
340339
}
341340

342-
void nbl_glsl_MC_setCurrInteraction(in vec3 N, in vec3 V, in vec3 pos)
341+
void nbl_glsl_MC_setCurrInteraction(in vec3 N, in vec3 V)
343342
{
344-
mat2x3 dp = nbl_glsl_MC_getdPos(pos);
345-
nbl_glsl_IsotropicViewSurfaceInteraction interaction = nbl_glsl_calcSurfaceInteractionFromViewVector(V, pos, N, dp);
343+
mat2x3 dp = nbl_glsl_MC_getdPos();
344+
nbl_glsl_IsotropicViewSurfaceInteraction interaction = nbl_glsl_calcSurfaceInteractionFromViewVector(V, N, dp);
346345
currInteraction.inner = nbl_glsl_calcAnisotropicInteraction(interaction);
347346
nbl_glsl_MC_finalizeInteraction(currInteraction);
348347
}
349348
void nbl_glsl_MC_setCurrInteraction(in nbl_glsl_MC_precomputed_t precomp)
350349
{
351-
nbl_glsl_MC_setCurrInteraction(precomp.frontface ? precomp.N : -precomp.N, precomp.V, precomp.pos);
350+
nbl_glsl_MC_setCurrInteraction(precomp.frontface ? precomp.N : -precomp.N, precomp.V);
352351
}
353352
void nbl_glsl_MC_updateCurrInteraction(in nbl_glsl_MC_precomputed_t precomp, in vec3 N)
354353
{
355354
// precomputed normals already have correct orientation
356-
nbl_glsl_MC_setCurrInteraction(N, precomp.V, precomp.pos);
355+
nbl_glsl_MC_setCurrInteraction(N, precomp.V);
357356
}
358357

359358
//clamping alpha to min MIN_ALPHA because we're using microfacet BxDFs for deltas as well (and NDFs often end up NaN when given alpha=0) because of less deivergence

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ struct nbl_glsl_MC_precomputed_t
4040
{
4141
vec3 N;
4242
vec3 V;
43-
vec3 pos;
4443
bool frontface;
4544
};
4645

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,9 @@ vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
9898
{
9999
return normalize(Normal);
100100
}
101-
vec3 nbl_glsl_MC_getWorldSpacePosition()
101+
mat2x3 nbl_glsl_MC_getdPos()
102102
{
103-
return WorldPos;
104-
}
105-
mat2x3 nbl_glsl_MC_getdPos(in vec3 p)
106-
{
107-
return mat2x3(dFdx(p), dFdy(p));
103+
return mat2x3(dFdx(WorldPos), dFdy(WorldPos));
108104
}
109105
#define _NBL_USER_PROVIDED_MATERIAL_COMPILER_GLSL_BACKEND_FUNCTIONS_
110106
)";

0 commit comments

Comments
 (0)