Skip to content

Commit b9d03d4

Browse files
have to read position in raygen anyway, so stop reconstructing it
1 parent c8a5df8 commit b9d03d4

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Renderer::Renderer(IVideoDriver* _driver, IAssetManager* _assetManager, scene::I
5353
m_prevView(), m_sceneBound(FLT_MAX,FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX,-FLT_MAX),
5454
m_maxRaysPerDispatch(0), m_framesDispatched(0u),
5555
m_staticViewData{{0.f,0.f,0.f},0u,{0.f,0.f},{0.f,0.f},{0u,0u},0u,0u},
56-
m_raytraceCommonData{core::matrix4SIMD(),core::matrix3x4SIMD(),0,0,0},
56+
m_raytraceCommonData{core::matrix3x4SIMD(),vec3(),0,0,0},
5757
m_indirectDrawBuffers{nullptr},m_cullPushConstants{core::matrix4SIMD(),1.f,0u,0u,0u},m_cullWorkGroups(0u),
5858
m_raygenWorkGroups{0u,0u},m_visibilityBuffer(nullptr),m_colorBuffer(nullptr)
5959
{
@@ -1102,7 +1102,7 @@ void Renderer::deinit()
11021102
m_indirectDrawBuffers[1] = m_indirectDrawBuffers[0] = nullptr;
11031103
m_indexBuffer = nullptr;
11041104

1105-
m_raytraceCommonData = {core::matrix4SIMD(),core::matrix3x4SIMD(),0,0,0,0u};
1105+
m_raytraceCommonData = {core::matrix3x4SIMD(),vec3(),0,0,0,0u};
11061106
m_staticViewData = {{0.f,0.f,0.f},0u,{0.f,0.f},{0.f,0.f},{0u,0u},0u,0u};
11071107
m_framesDispatched = 0u;
11081108
m_maxRaysPerDispatch = 0u;
@@ -1229,10 +1229,12 @@ void Renderer::render(nbl::ITimer* timer)
12291229
m_cullPushConstants.currentCommandBufferIx ^= 0x01u;
12301230

12311231
// prepare camera data for raytracing
1232-
modifiedViewProj.getInverseTransform(m_raytraceCommonData.inverseMVP);
1232+
core::matrix4SIMD inverseMVP;
1233+
modifiedViewProj.getInverseTransform(inverseMVP);
12331234
const auto cameraPosition = core::vectorSIMDf().set(camera->getAbsolutePosition());
12341235
for (auto i=0u; i<3u; i++)
1235-
m_raytraceCommonData.ndcToV.rows[i] = m_raytraceCommonData.inverseMVP.rows[3]*cameraPosition[i]-m_raytraceCommonData.inverseMVP.rows[i];
1236+
m_raytraceCommonData.ndcToV.rows[i] = inverseMVP.rows[3]*cameraPosition[i]-inverseMVP.rows[i];
1237+
//m_raytraceCommonData.camPos = ;
12361238
}
12371239
// path trace
12381240
m_raytraceCommonData.depth = 0u;

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ void main()
3737
const uvec4 visBuffer = texelFetch(frontFacingTriangleIDDrawID_unorm16Bary_dBarydScreenHalf2x2,ivec2(outPixelLocation),0);
3838

3939
// unproject (TODO: redo)
40-
vec3 hitWorldPos;
4140
{
4241
const vec3 NDC = vec3(vec2(outPixelLocation)*staticViewData.rcpPixelSize+staticViewData.rcpHalfPixelSize,1.0-revdepth);
43-
44-
const vec4 tmp = nbl_glsl_pseudoMul4x4with3x1(pc.cummon.inverseMVP,NDC);
45-
hitWorldPos = tmp.xyz/tmp.w;
4642

4743
const vec3 V = nbl_glsl_pseudoMul3x4with3x1(pc.cummon.ndcToV,NDC);
4844
normalizedV = normalize(V);
@@ -68,12 +64,14 @@ void main()
6864

6965
const uint vertex_depth_mod_2 = 0x1u;
7066
// load vertex data
71-
load_positions(indices,batchInstanceData);
67+
const vec3 last_vx_pos = load_positions(indices,batchInstanceData);
7268
const nbl_glsl_xoroshiro64star_state_t scramble_start_state = load_aux_vertex_attrs(compactBary,indices,batchInstanceData,material,outPixelLocation,vertex_depth_mod_2
7369
#ifdef TEX_PREFETCH_STREAM
7470
,dBarydScreen
7571
#endif
7672
);
73+
74+
const vec3 hitWorldPos = dPdBary*compactBary.xy+last_vx_pos;
7775

7876
// generate rays
7977
const uint sampleID = bitfieldExtract(pc.cummon.samplesComputed_depth,0,16);

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,17 @@ for (uint i=1u; i!=vertex_depth; i++)
261261
// set up dispatch indirect
262262
atomicMax(traceIndirect[vertex_depth_mod_2_inv].params.num_groups_x,(baseOutputID+raysToAllocate-1u)/WORKGROUP_SIZE+1u);
263263

264+
// TODO: improve ray offset (maybe using smooth normal wouldn't be a sin)
265+
const vec3 absGeomNormal = abs(geomNormal);
266+
geomNormal /= max(max(absGeomNormal.x,absGeomNormal.y),absGeomNormal.z);
264267
uint offset = 0u;
265268
for (uint i=0u; i<maxRaysToGen; i++)
266269
if (maxT[i]!=0.f)
267270
{
268271
nbl_glsl_ext_RadeonRays_ray newRay;
269-
// TODO: improve ray offsets
270-
const float err = 1.f/96.f;
271-
newRay.origin = origin+/*geomNormal/max(max(geomNormal.x,geomNormal.y),geomNormal.z)*sign(dot(geomNormal,direction[i]))*/direction[i]*err;
272+
newRay.origin = origin+uintBitsToFloat(floatBitsToUint(direction[i])^floatBitsToUint(dot(geomNormal,direction[i]))&0x80000000u)/96.f;
272273
newRay.maxT = maxT[i];
273-
newRay.direction = direction[i]; // normalize after ? (doesn't non-uniform scale screw up BxDF eval and generation?)
274+
newRay.direction = direction[i];
274275
newRay.time = packOutPixelLocation(outPixelLocation);
275276
newRay.mask = -1;
276277
newRay._active = 1;

examples_tests/22.RaytracedAO/raytraceCommon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ struct StaticViewData_t
9191

9292
struct RaytraceShaderCommonData_t
9393
{
94-
mat4 inverseMVP;
9594
mat4x3 ndcToV;
95+
vec3 camPos;
9696
float rcpFramesDispatched;
9797
#ifdef __cplusplus
9898
uint16_t samplesComputed;
@@ -102,6 +102,7 @@ struct RaytraceShaderCommonData_t
102102
#endif
103103
uint padding0;
104104
uint padding1;
105+
uint padding2;
105106
};
106107

107108
#endif

0 commit comments

Comments
 (0)