@@ -323,6 +323,8 @@ class GTAONode extends TempNode {
323
323
324
324
const ao = float ( 0 ) . toVar ( ) ;
325
325
326
+ // Each iteration analyzes one vertical "slice" of the 3D space around the fragment.
327
+
326
328
Loop ( { start : int ( 0 ) , end : DIRECTIONS , type : 'int' , condition : '<' } , ( { i } ) => {
327
329
328
330
const angle = float ( i ) . div ( float ( DIRECTIONS ) ) . mul ( PI ) . toVar ( ) ;
@@ -337,10 +339,14 @@ class GTAONode extends TempNode {
337
339
const tangentToNormalInSlice = cross ( normalInSlice , sliceBitangent ) . toVar ( ) ;
338
340
const cosHorizons = vec2 ( dot ( viewDir , tangentToNormalInSlice ) , dot ( viewDir , tangentToNormalInSlice . negate ( ) ) ) . toVar ( ) ;
339
341
342
+ // For each slice, the inner loop performs ray marching to find the horizons.
343
+
340
344
Loop ( { end : STEPS , type : 'int' , name : 'j' , condition : '<' } , ( { j } ) => {
341
345
342
346
const sampleViewOffset = sampleDir . xyz . mul ( radiusToUse ) . mul ( sampleDir . w ) . mul ( pow ( div ( float ( j ) . add ( 1.0 ) , float ( STEPS ) ) , this . distanceExponent ) ) ;
343
347
348
+ // The loop marches in two opposite directions (x and y) along the slice's line to find the horizon on both sides.
349
+
344
350
// x
345
351
346
352
const sampleScreenPositionX = getScreenPosition ( viewPosition . add ( sampleViewOffset ) , this . _cameraProjectionMatrix ) . toVar ( ) ;
@@ -371,6 +377,8 @@ class GTAONode extends TempNode {
371
377
372
378
} ) ;
373
379
380
+ // After the horizons are found for a given slice, their contribution to the total occlusion is calculated.
381
+
374
382
const sinHorizons = sqrt ( sub ( 1.0 , cosHorizons . mul ( cosHorizons ) ) ) . toVar ( ) ;
375
383
const nx = dot ( normalInSlice , sliceTangent ) ;
376
384
const ny = dot ( normalInSlice , viewDir ) ;
0 commit comments