@@ -76,7 +76,7 @@ fn main(@builtin(global_invocation_id) GlobalInvocationID: vec3u, @builtin(workg
7676 var pointPrev : PointAttri ;
7777
7878
79- let globalPreId = vec2f (GlobalInvocationID . xy ) + 0 .5 - primaryTri . motionVec ;
79+ let globalPreId = vec2f (GlobalInvocationID . xy ) + 0 .5 - primaryTri . motionVec * vec2f ( screen_size ) ;
8080 let launchPreIndex = select (- 1 , i32 (globalPreId . y ) * i32 (screen_size . x ) + i32 (globalPreId . x ), all (globalPreId >= vec2f (0 .0 )) && all (globalPreId < vec2f (screen_size )));
8181 let shadingPoint : vec3f = pointInfo . pos ;
8282
@@ -125,41 +125,43 @@ fn main(@builtin(global_invocation_id) GlobalInvocationID: vec3u, @builtin(workg
125125 }
126126
127127 // indirect illumination
128- if ENABLE_GI {
129- let sampleVec : vec4f = samplingHemisphere ();
130- // let sampleVec: vec4f = vec4f(0.0, 0.0, 1.0, 1.0);
131- let wi : vec3f = normalize (generateTBN (pointInfo . normalGeo ) * sampleVec . xyz );
132- let tracePdf = max (0 .001 , sampleVec . w );
133- if dot (wi , pointInfo . normalGeo ) >= 0 . {
134- let rayInfo : RayInfo = traceRay (pointInfo . pos , wi );
135- if rayInfo . isHit == 1 {
136- let triangle : PrimaryHitInfo = PrimaryHitInfo (rayInfo . hitAttribute , rayInfo . PrimitiveIndex , vec2f (0 ));
137- let pointSampleInfo : PointInfo = unpackTriangleIndirect (triangle , wi );
138- let samplePoint = pointSampleInfo . pos ;
128+ // if ENABLE_GI {
129+ // let sampleVec: vec4f = samplingHemisphere();
130+ // // let sampleVec: vec4f = vec4f(0.0, 0.0, 1.0, 1.0);
131+ // let wi: vec3f = normalize(generateTBN(pointInfo.normalGeo) * sampleVec.xyz);
132+ // let tracePdf = max(0.01 , sampleVec.w);
133+ // if dot(wi, pointInfo.normalGeo) >= 0. {
134+ // let rayInfo: RayInfo = traceRay(pointInfo.pos, wi);
135+ // if rayInfo.isHit == 1 {
136+ // let triangle: PrimaryHitInfo = PrimaryHitInfo(rayInfo.hitAttribute, rayInfo.PrimitiveIndex, vec2f(0));
137+ // let pointSampleInfo: PointInfo = unpackTriangleIndirect(triangle, wi);
138+ // let samplePoint = pointSampleInfo.pos;
139139
140- light = sampleLight ();
141- let lightPdf = sampleLightProb (light );
142- wo = light . position - samplePoint ;
143- dist = length (wo );
144- wo = normalize (wo );
145- // check the visibility from sample point to light
146- if dot (wo , pointSampleInfo . normalShading ) > 0 .0 && dot (wo , pointSampleInfo . normalGeo ) > 0 .0 {
147- if ! traceShadowRay (samplePoint , wo , dist ) {
148- let geometryTerm = light . color * light . intensity / (dist * dist );
149- let bsdf = BSDF (pointSampleInfo , wo , - wi );
150- let Lo = bsdf * geometryTerm / lightPdf ;
151- updateReservoirGI (& reservoirCurGI , pointInfo . pos , pointInfo . normalShading , pointSampleInfo . pos , pointSampleInfo . normalShading , luminance (Lo ) / tracePdf , Lo , light . id );
152- }
153- }
154- }
155- }
156- reservoirCurGI . M = 1 ;
157- }
140+ // light = sampleLight();
141+ // let lightPdf = sampleLightProb(light);
142+ // wo = light.position - samplePoint;
143+ // dist = length(wo);
144+ // wo = normalize(wo);
145+ // // check the visibility from sample point to light
146+ // if dot(wo, pointSampleInfo.normalShading) > 0.0 && dot(wo, pointSampleInfo.normalGeo) > 0.0 {
147+ // if !traceShadowRay(samplePoint, wo, dist) {
148+ // let geometryTerm = light.color * light.intensity / (dist * dist);
149+ // let bsdf = BSDF(pointSampleInfo, wo, -wi);
150+ // let Lo = bsdf * geometryTerm / lightPdf;
151+ // updateReservoirGI(&reservoirCurGI, pointInfo.pos, pointInfo.normalShading, pointSampleInfo.pos, pointSampleInfo.normalShading, luminance(Lo) / tracePdf, Lo, light.id);
152+ // }
153+ // }
154+ // }
155+ // }
156+ // reservoirCurGI.M = 1;
157+ // }
158158
159159 // temperal reuse
160160
161- let depth = distance (shadingPoint , origin );
162- if distance (shadingPoint , pointPrev . pos ) < 0 .1 * depth && dot (pointInfo . normalShading , pointPrev . normalShading ) > 0 .9 {
161+ // plane distance
162+ let posDiff = pointPrev . pos - pointInfo . pos ;
163+ let planeDist = abs (dot (posDiff , pointInfo . normalShading ));
164+ if dot (pointInfo . normalShading , pointPrev . normalShading ) > 0 .5 && planeDist < 0 .05 {
163165 if reservoirPrevDI . W > 0 .0 {
164166 const capped = 8u ;
165167 reservoirPrevDI . M = min (reservoirPrevDI . M , capped * reservoirCurDI . M );
@@ -177,27 +179,30 @@ fn main(@builtin(global_invocation_id) GlobalInvocationID: vec3u, @builtin(workg
177179 }
178180 }
179181 if ENABLE_GI {
180- reservoirPrevGI . M = min (reservoirPrevGI . M , 30 );
181- wo = reservoirPrevGI . xs - shadingPoint ;
182- dist = length (wo );
183- wo = normalize (wo );
182+ if reservoirPrevGI . W > 0 .0 {
183+ reservoirPrevGI . M = min (reservoirPrevGI . M , 20 );
184+ wo = reservoirPrevGI . xs - shadingPoint ;
185+ dist = length (wo );
186+ wo = normalize (wo );
184187
185- var flag = true ;
186- if f32 (_seed & 0x7fffffff ) / f32 (0x80000000 ) < 1 . / 8 . {
188+ var flag = true ;
189+ if f32 (_seed & 0x7fffffff ) / f32 (0x80000000 ) < 1 . / 8 . {
187190 // check visibility from light to sample point
188- light = getLight (reservoirPrevGI . lightId );
189- let dir = light . position - reservoirPrevGI . xs ;
190- let dist = length (dir );
191- let wo = normalize (dir );
192- if traceShadowRay (reservoirPrevGI . xs , wo , dist ) {
193- flag = false ;
191+ light = getLight (reservoirPrevGI . lightId );
192+ let dir = light . position - reservoirPrevGI . xs ;
193+ let dist = length (dir );
194+ let wo = normalize (dir );
195+ if traceShadowRay (reservoirPrevGI . xs , wo , dist ) {
196+ flag = false ;
197+ }
194198 }
195- }
196- if flag && dot ( wo , pointInfo . normalShading ) > 0 .0 && dot ( wo , pointInfo . normalGeo ) > 0 .0 {
197- pHat = luminance (reservoirPrevGI . Lo );
198- reservoirPrevGI . w_sum = pHat * reservoirPrevGI . W * f32 (reservoirPrevGI . M );
199+ if flag && dot ( wo , pointInfo . normalShading ) > 0 .0 && dot ( wo , pointInfo . normalGeo ) > 0 .0 {
200+ pHat = luminance ( reservoirPrevGI . Lo );
201+ // pHat = luminance(reservoirPrevGI.Lo) / Jacobian(pointInfo.pos, reservoirPrevGI );
202+ reservoirPrevGI . w_sum = pHat * reservoirPrevGI . W * f32 (reservoirPrevGI . M );
199203
200- combineReservoirsGI (& reservoirCurGI , reservoirPrevGI );
204+ combineReservoirsGI (& reservoirCurGI , reservoirPrevGI );
205+ }
201206 }
202207 }
203208 }
0 commit comments