Skip to content

Commit 134550d

Browse files
allow for environment lights (constant for now, IBL later)
1 parent f14559a commit 134550d

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ vec3 rand3d(inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint _samp
8585
return vec3(seqVal)*uintBitsToFloat(0x2f800004u);
8686
}
8787

88-
bool gen_sample_ray(
88+
void gen_sample_ray(
8989
out float maxT, out vec3 direction, out vec3 throughput,
9090
inout nbl_glsl_xoroshiro64star_state_t scramble_state, in uint sampleID,
9191
in nbl_glsl_MC_precomputed_t precomp, in nbl_glsl_MC_instr_stream_t gcs, in nbl_glsl_MC_instr_stream_t rnps
@@ -101,8 +101,6 @@ bool gen_sample_ray(
101101
throughput /= float(staticViewData.samplesPerPixelPerDispatch);
102102

103103
direction = s.L;
104-
105-
return any(greaterThan(throughput,vec3(FLT_MIN)));
106104
}
107105

108106
void main()
@@ -122,6 +120,7 @@ void main()
122120
nbl_glsl_MC_precomputed_t precomputed;
123121

124122
const bool nonBackgroudPixel = revdepth>0.0;
123+
vec3 emissive = staticViewData.envmapBaseColor;
125124
if (nonBackgroudPixel)
126125
{
127126
// vis buffer read
@@ -154,7 +153,6 @@ void main()
154153
}
155154

156155
// decode vis buffer
157-
vec3 emissive = vec3(0.0,0.0,0.0);
158156
{
159157
const uint objectID = visBuffer[0]&0x7fffffffu;
160158
const uint triangleID = visBuffer[1];
@@ -184,18 +182,18 @@ void main()
184182
nbl_glsl_MC_runNormalPrecompStream(nbl_glsl_MC_oriented_material_t_getNormalPrecompStream(material), dUVdScreen, precomputed);
185183
#endif
186184
}
185+
}
187186

188-
//
189-
if (any(greaterThan(emissive,vec3(FLT_MIN))))
187+
//
188+
if (any(greaterThan(emissive,vec3(FLT_MIN))))
189+
{
190+
vec3 acc = emissive;
191+
if (pc.cummon.rcpFramesDispatched<1.0)
190192
{
191-
vec3 acc = emissive;
192-
if (pc.cummon.rcpFramesDispatched<1.0)
193-
{
194-
acc /= float(pc.cummon.framesDispatched-1u);
195-
acc += fetchAccumulation(pixelCoord);
196-
}
197-
storeAccumulation(acc,pixelCoord);
193+
acc /= float(pc.cummon.framesDispatched-1u);
194+
acc += fetchAccumulation(pixelCoord);
198195
}
196+
storeAccumulation(acc,pixelCoord);
199197
}
200198
#ifdef USE_OPTIX_DENOISER
201199
// TODO: translate normal into float16_t buff
@@ -205,19 +203,18 @@ void main()
205203
{
206204
vec3 direction;
207205
float maxT;
208-
vec4 throughput;
209-
throughput.a = -1.0; // -1 needs to be there to ensure no backface culling on rays
206+
vec4 throughput = vec4(0.0,0.0,0.0,-1.0); // -1 needs to be there to ensure no backface culling on rays
210207

211-
bool validRay = false;
212208
if (nonBackgroudPixel)
213209
{
214210
nbl_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
215211
const uint sampleID = pc.cummon.samplesComputedPerPixel+i;
216-
validRay = gen_sample_ray(maxT,direction,throughput.rgb,scramble_state,sampleID,precomputed,gcs,rnps);
212+
gen_sample_ray(maxT,direction,throughput.rgb,scramble_state,sampleID,precomputed,gcs,rnps);
217213
}
218214

219215
// TODO: repack rays in smem for coalescing, or optimize this somehow
220216
const uint realOutputID = outputID+i;
217+
const bool validRay = any(greaterThan(throughput.rgb,vec3(FLT_MIN)));
221218
if (validRay)
222219
{
223220
const float err = 1.0/256.0; // TODO: improve ray offsets
@@ -226,15 +223,15 @@ void main()
226223
rays[realOutputID].direction = direction;
227224
rays[realOutputID].mask = -1;
228225
rays[realOutputID]._active = 1;
229-
rays[realOutputID].backfaceCulling = int(packHalf2x16(throughput.ab));
230-
rays[realOutputID].useless_padding = int(packHalf2x16(throughput.gr));
231226
}
232227
else
233228
{
234229
rays[realOutputID].maxT = 0.0;
235230
rays[realOutputID].mask = 0;
236231
rays[realOutputID]._active = 0;
237232
}
233+
rays[realOutputID].backfaceCulling = int(packHalf2x16(throughput.ab));
234+
rays[realOutputID].useless_padding = int(packHalf2x16(throughput.gr));
238235
}
239236
}
240237
}

examples_tests/22.RaytracedAO/resolve.comp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@ void main()
2626
const uint rayID = baseID+i;
2727
nbl_glsl_ext_RadeonRays_Intersection hit = hits[rayID];
2828

29-
// actually got a hit
30-
if (hit.shapeid<0)
31-
continue;
32-
3329
const vec3 thoughput = vec3(unpackHalf2x16(rays[rayID].useless_padding).yx,unpackHalf2x16(rays[rayID].backfaceCulling).yx);
34-
35-
const bool frontface = true; // TODO: how to determine frontface easily from radeon rays!? barycentrics? ray direction vs. oriented cross product?
36-
nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(InstData.data[hit.shapeid].material,frontface);
37-
color += nbl_glsl_MC_oriented_material_t_getEmissive(material)*thoughput;
30+
// init to miss color
31+
vec3 emissive = staticViewData.envmapBaseColor;
32+
// actually got a hit
33+
if (hit.shapeid>=0)
34+
{
35+
const bool frontface = true; // TODO: how to determine frontface easily from radeon rays!? barycentrics? ray direction vs. oriented cross product?
36+
37+
// hit buffer needs clearing
38+
hits[rayID].shapeid = -1;
3839

39-
// hit buffer needs clearing
40-
hits[rayID].shapeid = -1;
40+
nbl_glsl_MC_oriented_material_t material = nbl_glsl_MC_material_data_t_getOriented(InstData.data[hit.shapeid].material,frontface);
41+
emissive = nbl_glsl_MC_oriented_material_t_getEmissive(material);
42+
}
43+
color += emissive*thoughput;
4144
}
4245
if (pc.cummon.rcpFramesDispatched<1.0)
4346
acc += (color-acc)*pc.cummon.rcpFramesDispatched;

0 commit comments

Comments
 (0)