@@ -145,83 +145,16 @@ class GTAONode extends TempNode {
145145
146146 depth . greaterThanEqual ( 1.0 ) . discard ( ) ;
147147
148- const viewPosition = getViewPosition ( uvNode , depth ) ;
149- const viewNormal = this . normalNode . rgb . normalize ( ) ;
150-
151- const radiusToUse = this . radius ;
152-
153- const noiseResolution = textureSize ( this . noiseNode , 0 ) ;
154- let noiseUv = vec2 ( uvNode . x , uvNode . y . oneMinus ( ) ) ;
155- noiseUv = noiseUv . mul ( this . resolution . div ( noiseResolution ) ) ;
156- const noiseTexel = sampleNoise ( noiseUv ) ;
157- const randomVec = noiseTexel . xyz . mul ( 2.0 ) . sub ( 1.0 ) ;
158- const tangent = vec3 ( randomVec . xy , 0.0 ) . normalize ( ) ;
159- const bitangent = vec3 ( tangent . y . mul ( - 1.0 ) , tangent . x , 0.0 ) ;
160- const kernelMatrix = mat3 ( tangent , bitangent , vec3 ( 0.0 , 0.0 , 1.0 ) ) ;
161-
162- const DIRECTIONS = this . SAMPLES . lessThan ( 30 ) . cond ( 3 , 5 ) ;
163- const STEPS = add ( this . SAMPLES , DIRECTIONS . sub ( 1 ) ) . div ( DIRECTIONS ) ;
164-
165148 let ao = float ( 0 ) . toVar ( ) ;
166149
167- loop ( { start : int ( 0 ) , end : DIRECTIONS , type : 'int' , condition : '<' } , ( { i } ) => {
168-
169- const angle = float ( i ) . div ( float ( DIRECTIONS ) ) . mul ( PI ) ;
170- const sampleDir = vec4 ( cos ( angle ) , sin ( angle ) , 0. , add ( 0.5 , mul ( 0.5 , noiseTexel . w ) ) ) ;
171- sampleDir . xyz = normalize ( kernelMatrix . mul ( sampleDir . xyz ) ) ;
172-
173- const viewDir = normalize ( viewPosition . xyz . negate ( ) ) ;
174- const sliceBitangent = normalize ( cross ( sampleDir . xyz , viewDir ) ) ;
175- const sliceTangent = cross ( sliceBitangent , viewDir ) ;
176- const normalInSlice = normalize ( viewNormal . sub ( sliceBitangent . mul ( dot ( viewNormal , sliceBitangent ) ) ) ) ;
177-
178- const tangentToNormalInSlice = cross ( normalInSlice , sliceBitangent ) ;
179- const cosHorizons = vec2 ( dot ( viewDir , tangentToNormalInSlice ) , dot ( viewDir , tangentToNormalInSlice . negate ( ) ) ) . toVar ( ) ;
180-
181- loop ( { end : STEPS , type : 'int' , name : 'j' , condition : '<' } , ( { j } ) => {
182-
183- const sampleViewOffset = sampleDir . xyz . mul ( radiusToUse ) . mul ( sampleDir . w ) . mul ( pow ( div ( float ( j ) . add ( 1.0 ) , float ( STEPS ) ) , this . distanceExponent ) ) ;
184-
185- // x
186-
187- let sampleSceneUvDepth = getSceneUvAndDepth ( viewPosition . add ( sampleViewOffset ) ) ;
188- let sampleSceneViewPosition = getViewPosition ( sampleSceneUvDepth . xy , sampleSceneUvDepth . z ) ;
189- let viewDelta = sampleSceneViewPosition . sub ( viewPosition ) ;
190-
191- If ( abs ( viewDelta . z ) . lessThan ( this . thickness ) , ( ) => {
192-
193- const sampleCosHorizon = viewDir . dot ( viewDelta . normalize ( ) ) ;
194- cosHorizons . x . addAssign ( max ( 0 , mul ( sampleCosHorizon . sub ( cosHorizons . x ) , mix ( 1.0 , float ( 2.0 ) . div ( float ( j ) . add ( 2 ) ) , this . distanceFallOff ) ) ) ) ;
195-
196- } ) ;
197-
198- // y
199-
200- sampleSceneUvDepth = getSceneUvAndDepth ( viewPosition . sub ( sampleViewOffset ) ) ;
201- sampleSceneViewPosition = getViewPosition ( sampleSceneUvDepth . xy , sampleSceneUvDepth . z ) ;
202- viewDelta = sampleSceneViewPosition . sub ( viewPosition ) ;
203-
204- If ( abs ( viewDelta . z ) . lessThan ( this . thickness ) , ( ) => {
205-
206- const sampleCosHorizon = viewDir . dot ( viewDelta . normalize ( ) ) ;
207- cosHorizons . y . addAssign ( max ( 0 , mul ( sampleCosHorizon . sub ( cosHorizons . y ) , mix ( 1.0 , float ( 2.0 ) . div ( float ( j ) . add ( 2 ) ) , this . distanceFallOff ) ) ) ) ;
208-
209- } ) ;
210-
211- } ) ;
150+ loop ( { start : int ( 0 ) , end : int ( 3 ) , type : 'int' , condition : '<' } , ( { i } ) => {
212151
213- const sinHorizons = sqrt ( sub ( 1.0 , cosHorizons . mul ( cosHorizons ) ) ) ;
214- const nx = dot ( normalInSlice , sliceTangent ) ;
215- const ny = dot ( normalInSlice , viewDir ) ;
216- const nxb = mul ( 0.5 , acos ( cosHorizons . y ) . sub ( acos ( cosHorizons . x ) ) . add ( sinHorizons . x . mul ( cosHorizons . x ) . sub ( sinHorizons . y . mul ( cosHorizons . y ) ) ) ) ;
217- const nyb = mul ( 0.5 , sub ( 2.0 , cosHorizons . x . mul ( cosHorizons . x ) ) . sub ( cosHorizons . y . mul ( cosHorizons . y ) ) ) ;
218- const occlusion = nx . mul ( nxb ) . add ( ny . mul ( nyb ) ) ;
219- ao . addAssign ( occlusion ) ;
152+ const angle = float ( i ) . div ( float ( 3 ) ) . mul ( PI ) ;
153+ ao . addAssign ( cos ( angle ) ) ;
220154
221155 } ) ;
222156
223- ao = clamp ( ao . div ( DIRECTIONS ) , 0 , 1 ) ;
224- ao = pow ( ao , this . scale ) ;
157+ ao = clamp ( ao . div ( 3 ) , 0 , 1 ) ;
225158
226159 return vec4 ( vec3 ( ao ) , 1.0 ) ;
227160
0 commit comments