Skip to content

Commit ab189f2

Browse files
One final fix in the MitsubaLoader
Also remove the nasty ieee754 error tracking code from the shaders
1 parent 51d003f commit ab189f2

File tree

4 files changed

+35
-62
lines changed

4 files changed

+35
-62
lines changed

examples_tests/22.RaytracedAO/closestHit.comp

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

7070
// positions
71-
mat2x3 dPdBary_error; vec3 lastVxPos_error;
72-
const vec3 lastVxPos = load_positions(dPdBary_error,lastVxPos_error,indices,batchInstanceData);
71+
const vec3 lastVxPos = load_positions(indices,batchInstanceData);
7372
const vec3 geomNormal = cross(dPdBary[0],dPdBary[1]);
7473
const bool frontfacing = bool((batchInstanceData.determinantSignBit^floatBitsToUint(dot(geomNormal,normalizedV)))&0x80000000u);
7574

@@ -89,13 +88,11 @@ void main()
8988
#endif
9089
);
9190

92-
vec3 origin_error;
93-
const float compactBary_error = nbl_glsl_ieee754_gamma(1u);
94-
const vec3 origin = nbl_glsl_interpolate_with_bounds(origin_error,dPdBary,dPdBary_error,lastVxPos,lastVxPos_error,compactBary,compactBary_error);
95-
91+
const vec3 origin = dPdBary*compactBary+lastVxPos;
92+
9693
generate_next_rays(
9794
MAX_RAYS_GENERATED,material,frontfacing,vertex_depth,scramble_start_state,
98-
sampleID,outPixelLocation,origin,origin_error,throughput
95+
sampleID,outPixelLocation,origin,throughput
9996
);
10097
}
10198
}

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,21 @@ void main()
5454

5555
const uint vertex_depth_mod_2 = 0x1u;
5656
// load vertex data
57-
mat2x3 dPdBary_error; vec3 lastVxPos_error;
58-
const vec3 lastVxPos = load_positions(dPdBary_error,lastVxPos_error,indices,batchInstanceData);
57+
const vec3 lastVxPos = load_positions(indices,batchInstanceData);
5958
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(compactBary,indices,batchInstanceData,material,outPixelLocation,vertex_depth_mod_2
6059
#ifdef TEX_PREFETCH_STREAM
6160
,dBarydScreen
6261
#endif
6362
);
6463

65-
vec3 origin_error;
66-
const float compactBary_error = exp2(-16.f); // UNORM16 being used for storage
67-
const vec3 origin = nbl_glsl_interpolate_with_bounds(origin_error,dPdBary,dPdBary_error,lastVxPos,lastVxPos_error,compactBary,compactBary_error);
64+
const vec3 origin = dPdBary*compactBary+lastVxPos;
6865
normalizedV = normalize(pc.cummon.camPos-origin);
6966

7067
// generate rays
7168
const uint vertex_depth = 1u;
7269
generate_next_rays(
7370
staticViewData.samplesPerPixelPerDispatch,material,frontfacing,vertex_depth,
74-
scramble_start_state,pc.cummon.samplesComputed,outPixelLocation,origin,origin_error,vec3(1.0)
71+
scramble_start_state,pc.cummon.samplesComputed,outPixelLocation,origin,vec3(1.0)
7572
);
7673
}
7774

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,19 @@ vec3 nbl_glsl_MC_getNormalizedWorldSpaceN()
116116

117117
#include <nbl/builtin/glsl/barycentric/utils.glsl>
118118
mat2x3 dPdBary;
119-
vec3 load_positions(out mat2x3 dPdBary_error, out vec3 lastVxPos_error,in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
119+
vec3 load_positions(in uvec3 indices, in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
120120
{
121121
mat3 positions = mat3(
122122
nbl_glsl_fetchVtxPos(indices[0],batchInstanceData),
123123
nbl_glsl_fetchVtxPos(indices[1],batchInstanceData),
124124
nbl_glsl_fetchVtxPos(indices[2],batchInstanceData)
125125
);
126126
const mat4x3 tform = batchInstanceData.tform;
127-
mat3 positions_error;
128-
// when we quantize positions to RGB21_UNORM, change to exp2(-22.f)
129-
const float quantizationError = nbl_glsl_numeric_limits_float_epsilon(1u);
130-
positions = nbl_glsl_mul_with_bounds_wo_gamma(positions_error,mat3(tform),positions,quantizationError);
131-
positions_error *= nbl_glsl_ieee754_gamma(2u);
127+
positions = mat3(tform)*positions;
132128
//
133129
for (int i=0; i<2; i++)
134-
{
135-
dPdBary[i] = nbl_glsl_ieee754_sub_with_bounds_wo_gamma(dPdBary_error[i],positions[i],positions_error[i],positions[2],positions_error[2]);
136-
dPdBary_error[i] *= nbl_glsl_ieee754_gamma(1u);
137-
}
138-
const vec3 lastVx = nbl_glsl_ieee754_add_with_bounds_wo_gamma(lastVxPos_error,positions[2],positions_error[2],tform[3],vec3(0.f));
139-
lastVxPos_error *= nbl_glsl_ieee754_gamma(1u);
140-
return lastVx;
130+
dPdBary[i] = positions[i]-positions[2];
131+
return positions[2]+tform[3];
141132
}
142133

143134
#ifdef TEX_PREFETCH_STREAM
@@ -200,25 +191,6 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
200191
return scramble_start_state;
201192
}
202193

203-
// TODO MOVE to some other header!
204-
vec3 nbl_glsl_interpolate_with_bounds(out vec3 error, in mat2x3 triangleEdges, in mat2x3 triangleEdges_error,
205-
in vec3 origin, in vec3 origin_error, in vec2 compactBary, in float compactBary_error
206-
)
207-
{
208-
vec3 error1;
209-
const vec3 col1 = nbl_glsl_ieee754_mul_with_bounds_wo_gamma(error1,triangleEdges[0],triangleEdges_error[0],compactBary.x,compactBary_error);
210-
error1 *= nbl_glsl_ieee754_gamma(1u);
211-
vec3 error2;
212-
const vec3 col2 = nbl_glsl_ieee754_mul_with_bounds_wo_gamma(error2,triangleEdges[1],triangleEdges_error[1],compactBary.y,compactBary_error);
213-
error2 *= nbl_glsl_ieee754_gamma(1u);
214-
vec3 error3;
215-
vec3 retval = nbl_glsl_ieee754_add_with_bounds_wo_gamma(error3,col1,error1,col2,error2);
216-
error3 *= nbl_glsl_ieee754_gamma(1u);
217-
retval = nbl_glsl_ieee754_add_with_bounds_wo_gamma(error,retval,error3,origin,origin_error);
218-
//error *= nbl_glsl_ieee754_gamma(1u);
219-
error *= nbl_glsl_ieee754_gamma(8u); // cause PBRT says so
220-
return retval;
221-
}
222194
// robust ray origins
223195
vec3 nbl_glsl_robust_ray_origin_impl(in vec3 origin, in vec3 direction, float offset, vec3 normal)
224196
{
@@ -256,7 +228,7 @@ void gen_sample_ray(
256228
void generate_next_rays(
257229
in uint maxRaysToGen, in nbl_glsl_MC_oriented_material_t material, in bool frontfacing, in uint vertex_depth,
258230
in nbl_glsl_xoroshiro64star_state_t scramble_start_state, in uint sampleID, in uvec2 outPixelLocation,
259-
in vec3 origin, vec3 origin_error, in vec3 prevThroughput)
231+
in vec3 origin, in vec3 prevThroughput)
260232
{
261233
// get material streams as well
262234
const nbl_glsl_MC_instr_stream_t gcs = nbl_glsl_MC_oriented_material_t_getGenChoiceStream(material);

src/nbl/ext/MitsubaLoader/CMitsubaLoader.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,16 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
781781
for (auto& meshbuffer : mesh->getMeshBufferVector())
782782
{
783783
auto binding = meshbuffer->getVertexBufferBindings()[UV_ATTRIB_ID];
784-
binding.buffer = core::smart_refctd_ptr_static_cast<ICPUBuffer>(binding.buffer->clone(0u));
785-
meshbuffer->setVertexBufferBinding(std::move(binding),UV_ATTRIB_ID);
786-
core::vectorSIMDf uv;
787-
for (uint32_t i=0u; meshbuffer->getAttribute(uv,UV_ATTRIB_ID,i); i++)
784+
if (binding.buffer)
788785
{
789-
uv.y = -uv.y;
790-
meshbuffer->setAttribute(uv,UV_ATTRIB_ID,i);
786+
binding.buffer = core::smart_refctd_ptr_static_cast<ICPUBuffer>(binding.buffer->clone(0u));
787+
meshbuffer->setVertexBufferBinding(std::move(binding),UV_ATTRIB_ID);
788+
core::vectorSIMDf uv;
789+
for (uint32_t i=0u; meshbuffer->getAttribute(uv,UV_ATTRIB_ID,i); i++)
790+
{
791+
uv.y = -uv.y;
792+
meshbuffer->setAttribute(uv,UV_ATTRIB_ID,i);
793+
}
791794
}
792795
}
793796
}
@@ -807,27 +810,31 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
807810
if (totalVertexCount)
808811
{
809812
constexpr uint32_t hidefRGBSize = 4u;
810-
auto newRGB = core::make_smart_refctd_ptr<asset::ICPUBuffer>(hidefRGBSize*totalVertexCount);
811-
uint32_t* it = reinterpret_cast<uint32_t*>(newRGB->getPointer());
813+
auto newRGBbuff = core::make_smart_refctd_ptr<asset::ICPUBuffer>(hidefRGBSize*totalVertexCount);
812814
newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone(1u));
815+
constexpr uint32_t COLOR_ATTR = 1u;
816+
constexpr uint32_t COLOR_BUF_BINDING = 15u;
817+
uint32_t* newRGB = reinterpret_cast<uint32_t*>(newRGBbuff->getPointer());
818+
uint32_t offset = 0u;
813819
for (auto& meshbuffer : mesh->getMeshBufferVector())
814820
{
815821
core::vectorSIMDf rgb;
816-
for (uint32_t i=0u; meshbuffer->getAttribute(rgb,1u,i); i++,it++)
822+
for (uint32_t i=0u; meshbuffer->getAttribute(rgb,COLOR_ATTR,i); i++,offset++)
817823
{
818824
for (auto i=0; i<3u; i++)
819825
rgb[i] = core::srgb2lin(rgb[i]);
820-
meshbuffer->setAttribute(rgb,it,asset::EF_A2B10G10R10_UNORM_PACK32);
826+
ICPUMeshBuffer::setAttribute(rgb,newRGB+offset,asset::EF_A2B10G10R10_UNORM_PACK32);
821827
}
822-
constexpr uint32_t COLOR_BUF_BINDING = 15u;
823-
auto& vtxParams = meshbuffer->getPipeline()->getVertexInputParams();
824-
vtxParams.attributes[1].format = EF_A2B10G10R10_UNORM_PACK32;
825-
vtxParams.attributes[1].relativeOffset = 0u;
826-
vtxParams.attributes[1].binding = COLOR_BUF_BINDING;
828+
auto newPipeline = core::smart_refctd_ptr_static_cast<ICPURenderpassIndependentPipeline>(meshbuffer->getPipeline()->clone(0u));
829+
auto& vtxParams = newPipeline->getVertexInputParams();
830+
vtxParams.attributes[COLOR_ATTR].format = EF_A2B10G10R10_UNORM_PACK32;
831+
vtxParams.attributes[COLOR_ATTR].relativeOffset = 0u;
832+
vtxParams.attributes[COLOR_ATTR].binding = COLOR_BUF_BINDING;
827833
vtxParams.bindings[COLOR_BUF_BINDING].inputRate = EVIR_PER_VERTEX;
828834
vtxParams.bindings[COLOR_BUF_BINDING].stride = hidefRGBSize;
829835
vtxParams.enabledBindingFlags |= (1u<<COLOR_BUF_BINDING);
830-
meshbuffer->setVertexBufferBinding({0ull,core::smart_refctd_ptr(newRGB)}, COLOR_BUF_BINDING);
836+
meshbuffer->setPipeline(std::move(newPipeline));
837+
meshbuffer->setVertexBufferBinding({offset*hidefRGBSize,core::smart_refctd_ptr(newRGBbuff)},COLOR_BUF_BINDING);
831838
}
832839
}
833840
}

0 commit comments

Comments
 (0)