Skip to content

Commit 778c582

Browse files
prepare for brand new optimizations (unified pre-transformed BLAS, no normal attribute for meshes that don't need it)
1 parent 2ddc284 commit 778c582

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

examples_tests/22.RaytracedAO/closestHit.comp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ void main()
6868
const uvec3 indices = get_triangle_indices(batchInstanceData,triangleID);
6969

7070
// positions
71-
const vec3 lastVxPos = load_positions(indices,batchInstanceData);
72-
const vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
73-
const bool frontfacing = bool((batchInstanceData.determinantSignBit^floatBitsToUint(dot(geomNormal,normalizedV)))&0x80000000u);
71+
vec3 geomDenormal;
72+
const vec3 lastVxPos = load_positions(geomDenormal,batchInstanceData,indices);
73+
const bool frontfacing = bool((batchInstanceData.determinantSignBit^floatBitsToUint(dot(geomDenormal,normalizedV)))&0x80000000u);
7474

7575
// get material
7676
const nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(batchInstanceData.material,frontfacing);
@@ -82,7 +82,9 @@ void main()
8282
// if we ever support spatially varying emissive, we'll need to hoist barycentric computation and UV fetching to the position fetching
8383
const vec2 compactBary = vec2(1.f-intersection.uvwt.x-intersection.uvwt.y,intersection.uvwt.x); // radeon rays is a special boy
8484

85-
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(compactBary,indices,batchInstanceData,material,outPixelLocation,vertex_depth
85+
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(
86+
batchInstanceData,indices,compactBary,geomDenormal,
87+
material,outPixelLocation,vertex_depth
8688
#ifdef TEX_PREFETCH_STREAM
8789
,mat2(0.0) // TODO: Covariance Rendering
8890
#endif

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ void main()
5454

5555
const uint vertex_depth_mod_2 = 0x1u;
5656
// load vertex data
57-
const vec3 lastVxPos = load_positions(indices,batchInstanceData);
58-
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(compactBary,indices,batchInstanceData,material,outPixelLocation,vertex_depth_mod_2
57+
vec3 geomDenormal;
58+
const vec3 lastVxPos = load_positions(geomDenormal,batchInstanceData,indices);
59+
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(
60+
batchInstanceData,indices,compactBary,geomDenormal,
61+
material,outPixelLocation,vertex_depth_mod_2
5962
#ifdef TEX_PREFETCH_STREAM
6063
,dBarydScreen
6164
#endif

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
118124
mat2x3 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

148159
nbl_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;

examples_tests/22.RaytracedAO/raytraceCommon.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ struct SLight
7373
#endif
7474

7575
mat4x3 obb; // needs row_major qualifier
76+
/** TODO new and improved
77+
mat2x3 obb_base;
78+
uvec2 radianceRemainder;
79+
vec3 offset;
80+
float obb_height;
81+
**/
7682
};
7783

7884

0 commit comments

Comments
 (0)