Skip to content

Commit 65874e4

Browse files
fix nasty little bug
1 parent 1e1f887 commit 65874e4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ vec3 nbl_computeLighting(inout nbl_glsl_AnisotropicViewSurfaceInteraction out_in
5858
{
5959
nbl_glsl_xoroshiro64star_state_t scramble_start_state = textureLod(scramblebuf,gl_FragCoord.xy/VIEWPORT_SZ,0).rg;
6060
61-
material = nbl_glsl_MC_material_data_t_getOriented(InstData.data[InstanceIndex].material,precomp.frontface);
6261
vec3 emissive = nbl_glsl_MC_oriented_material_t_getEmissive(material);
6362
6463
vec3 color = vec3(0.0);
@@ -84,11 +83,12 @@ vec3 nbl_computeLighting(inout nbl_glsl_AnisotropicViewSurfaceInteraction out_in
8483
for (int i = 0; i < LIGHT_COUNT; ++i)
8584
{
8685
SLight l = lights[i];
87-
vec3 L = l.position-WorldPos;
86+
const vec3 L = l.position-WorldPos;
87+
const float d2 = dot(L,L);
8888
const float intensityScale = LIGHT_INTENSITY_SCALE;//ehh might want to render to hdr fbo and do tonemapping
8989
nbl_glsl_LightSample _sample;
90-
_sample.L = L;
91-
color += nbl_bsdf_cos_eval(_sample,out_interaction, dUV)*l.intensity*intensityScale / dot(L,L);
90+
_sample.L = L*inversesqrt(d2);
91+
color += nbl_bsdf_cos_eval(_sample,out_interaction, dUV)*l.intensity*intensityScale/d2;
9292
}
9393
9494
return color+emissive;

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ vec3 nbl_computeLighting(inout nbl_glsl_IsotropicViewSurfaceInteraction out_inte
221221
out_interaction = nbl_glsl_calcSurfaceInteraction(campos,WorldPos,normalize(Normal),mat2x3(dFdx(WorldPos),dFdy(WorldPos)));
222222
223223
nbl_glsl_LightSample _sample = nbl_glsl_createLightSample(precomp.V,1.0,precomp.N);
224-
return nbl_glsl_MC_oriented_material_t_getEmissive(material)+nbl_bsdf_cos_eval(_sample,out_interaction,dummy_dUV)/dot(params.L,params.L);
224+
return nbl_glsl_MC_oriented_material_t_getEmissive(material)+nbl_bsdf_cos_eval(_sample,out_interaction,dummy_dUV)/dot(interaction.V.dir,interaction.V.dir);
225225
}
226226
#endif
227227

0 commit comments

Comments
 (0)