@@ -114,21 +114,32 @@ vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
114114 return normalizedN;
115115}
116116
117+
118+ bool has_world_transform(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
119+ {
120+ return true;
121+ }
122+
117123#include < nbl/ builtin/ glsl/ barycentric/ utils.glsl>
118124mat2x3 dPdBary;
119- vec3 load_positions(in uvec3 indices , in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
125+ vec3 load_positions(out vec3 geomDenormal , in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData, in uvec3 indices )
120126{
121127 mat3 positions = mat3 (
122128 nbl_glsl_fetchVtxPos(indices[0 ],batchInstanceData),
123129 nbl_glsl_fetchVtxPos(indices[1 ],batchInstanceData),
124130 nbl_glsl_fetchVtxPos(indices[2 ],batchInstanceData)
125131 );
126- const mat4x3 tform = batchInstanceData.tform;
127- positions = mat3 (tform)* positions;
132+ const bool tform = has_world_transform(batchInstanceData);
133+ if (tform)
134+ positions = mat3 (batchInstanceData.tform)* positions;
128135 //
129136 for (int i= 0 ; i< 2 ; i++ )
130137 dPdBary[i] = positions[i]- positions[2 ];
131- return positions[2 ]+ tform[3 ];
138+ geomDenormal = cross (dPdBary[0 ],dPdBary[1 ]);
139+ //
140+ if (tform)
141+ positions[2 ] += batchInstanceData.tform[3 ];
142+ return positions[2 ];
132143}
133144
134145#ifdef TEX_PREFETCH_STREAM
@@ -146,7 +157,8 @@ mat2 nbl_glsl_perturbNormal_dUVdSomething()
146157#include < nbl/ builtin/ glsl/ material_compiler/ common.glsl>
147158
148159nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
149- in vec2 compactBary, in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData,
160+ in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData,
161+ in uvec3 indices, in vec2 compactBary, in vec3 geomDenormal,
150162 in nbl_glsl_MC_oriented_material_t material,
151163 in uvec2 outPixelLocation, in uint vertex_depth_mod_2
152164#ifdef TEX_PREFETCH_STREAM
@@ -161,31 +173,42 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
161173 nbl_glsl_fetchVtxUV(indices[1 ],batchInstanceData),
162174 nbl_glsl_fetchVtxUV(indices[2 ],batchInstanceData)
163175 );
176+
164177 const nbl_glsl_MC_instr_stream_t tps = nbl_glsl_MC_oriented_material_t_getTexPrefetchStream(material);
165- #endif
166- // only needed for continuing
167- const mat3 normals = mat3 (
168- nbl_glsl_fetchVtxNormal(indices[0 ],batchInstanceData),
169- nbl_glsl_fetchVtxNormal(indices[1 ],batchInstanceData),
170- nbl_glsl_fetchVtxNormal(indices[2 ],batchInstanceData)
171- );
172178
173- #ifdef TEX_PREFETCH_STREAM
174179 dUVdBary = mat2 (uvs[0 ]- uvs[2 ],uvs[1 ]- uvs[2 ]);
175180 const vec2 UV = dUVdBary* compactBary+ uvs[2 ];
176181 const mat2 dUVdScreen = nbl_glsl_applyChainRule2D(dUVdBary,dBarydScreen);
177182 nbl_glsl_MC_runTexPrefetchStream(tps,UV,dUVdScreen);
178183 #endif
179- // not needed for NEE unless doing Area or Projected Solid Angle Sampling
180- const vec3 normal = normals* nbl_glsl_barycentric_expand(compactBary);
184+ // the rest is always only needed for continuing
181185
182- // init scramble while waiting for getting the instance's normal matrix
186+ // init scramble
183187 const nbl_glsl_xoroshiro64star_state_t scramble_start_state = imageLoad(scramblebuf,ivec3 (outPixelLocation,1u/* vertex_depth_mod_2*/ )).rg;
184188
185189 // while waiting for the scramble state
186- normalizedN.x = dot (batchInstanceData.normalMatrixRow0,normal);
187- normalizedN.y = dot (batchInstanceData.normalMatrixRow1,normal);
188- normalizedN.z = dot (batchInstanceData.normalMatrixRow2,normal);
190+ const bool needsSmoothNormals = false;
191+ if (needsSmoothNormals)
192+ {
193+ const mat3 normals = mat3 (
194+ nbl_glsl_fetchVtxNormal(indices[0 ],batchInstanceData),
195+ nbl_glsl_fetchVtxNormal(indices[1 ],batchInstanceData),
196+ nbl_glsl_fetchVtxNormal(indices[2 ],batchInstanceData)
197+ );
198+
199+ // not needed for NEE unless doing Area or Projected Solid Angle Sampling
200+ normalizedN = normals* nbl_glsl_barycentric_expand(compactBary);
201+ if (has_world_transform(batchInstanceData))
202+ {
203+ normalizedN = vec3 (
204+ dot (batchInstanceData.normalMatrixRow0,normalizedN),
205+ dot (batchInstanceData.normalMatrixRow1,normalizedN),
206+ dot (batchInstanceData.normalMatrixRow2,normalizedN)
207+ );
208+ }
209+ }
210+ else
211+ normalizedN = geomDenormal;
189212 normalizedN = normalize (normalizedN);
190213
191214 return scramble_start_state;
0 commit comments