Skip to content

Commit 071bb8f

Browse files
authored
GTAONode: Add comments to TSL. (#31676)
1 parent da169d5 commit 071bb8f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

examples/jsm/tsl/display/GTAONode.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ class GTAONode extends TempNode {
323323

324324
const ao = float( 0 ).toVar();
325325

326+
// Each iteration analyzes one vertical "slice" of the 3D space around the fragment.
327+
326328
Loop( { start: int( 0 ), end: DIRECTIONS, type: 'int', condition: '<' }, ( { i } ) => {
327329

328330
const angle = float( i ).div( float( DIRECTIONS ) ).mul( PI ).toVar();
@@ -337,10 +339,14 @@ class GTAONode extends TempNode {
337339
const tangentToNormalInSlice = cross( normalInSlice, sliceBitangent ).toVar();
338340
const cosHorizons = vec2( dot( viewDir, tangentToNormalInSlice ), dot( viewDir, tangentToNormalInSlice.negate() ) ).toVar();
339341

342+
// For each slice, the inner loop performs ray marching to find the horizons.
343+
340344
Loop( { end: STEPS, type: 'int', name: 'j', condition: '<' }, ( { j } ) => {
341345

342346
const sampleViewOffset = sampleDir.xyz.mul( radiusToUse ).mul( sampleDir.w ).mul( pow( div( float( j ).add( 1.0 ), float( STEPS ) ), this.distanceExponent ) );
343347

348+
// The loop marches in two opposite directions (x and y) along the slice's line to find the horizon on both sides.
349+
344350
// x
345351

346352
const sampleScreenPositionX = getScreenPosition( viewPosition.add( sampleViewOffset ), this._cameraProjectionMatrix ).toVar();
@@ -371,6 +377,8 @@ class GTAONode extends TempNode {
371377

372378
} );
373379

380+
// After the horizons are found for a given slice, their contribution to the total occlusion is calculated.
381+
374382
const sinHorizons = sqrt( sub( 1.0, cosHorizons.mul( cosHorizons ) ) ).toVar();
375383
const nx = dot( normalInSlice, sliceTangent );
376384
const ny = dot( normalInSlice, viewDir );

0 commit comments

Comments
 (0)