@@ -1361,10 +1361,9 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1361
1361
// path_size = depth;
1362
1362
auto wi = -ray->direction ();
1363
1363
auto it = pipeline ().geometry ()->intersect (ray);
1364
-
1365
1364
// miss
1366
1365
$if (!it->valid ()) {
1367
- $if (photon_id_1d< 1 )
1366
+ $if (photon_id_1d==node<MegakernelPhotonMappingDiff>()-> debug_photon () )
1368
1367
{
1369
1368
device_log (" break it unvalid at size {} id {}" , path_size, photon_id_1d);
1370
1369
device_log (" ray {} {}" , ray->origin (), ray->direction ());
@@ -1373,14 +1372,12 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1373
1372
};
1374
1373
1375
1374
$if (!it->shape ().has_surface ()) {
1376
- $if (photon_id_1d< 1 )
1375
+ $if (photon_id_1d==node<MegakernelPhotonMappingDiff>()-> debug_photon () )
1377
1376
{
1378
1377
device_log (" break it non surface {} " , photon_id_1d);
1379
1378
};
1380
1379
$break ;
1381
1380
};
1382
-
1383
-
1384
1381
// generate uniform samples
1385
1382
auto u_lobe = sampler ()->generate_1d ();
1386
1383
auto u_bsdf = sampler ()->generate_2d ();
@@ -1444,7 +1441,6 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1444
1441
auto grad_b = grad (bary).xy ();
1445
1442
grad_bary += grad_b;
1446
1443
grad_beta += grad (beta_diff);
1447
-
1448
1444
};
1449
1445
count_neighbors+=1 ;
1450
1446
};
@@ -1488,7 +1484,7 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1488
1484
});
1489
1485
beta = zero_if_any_nan (beta);
1490
1486
$if (beta.all ([](auto b) noexcept { return b <= 0 .f ; })) {
1491
- $if (photon_id_1d< 1 )
1487
+ $if (photon_id_1d==node<MegakernelPhotonMappingDiff>()-> debug_photon () )
1492
1488
{
1493
1489
device_log (" break beta negative {}" ,photon_id_1d);
1494
1490
};
@@ -1498,7 +1494,7 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1498
1494
auto q = max (eta_scale, .05f );
1499
1495
$if (depth + 1u >= rr_depth) {
1500
1496
$if (q < rr_threshold & u_rr >= q) {
1501
- $if (photon_id_1d< 1 )
1497
+ $if (photon_id_1d==node<MegakernelPhotonMappingDiff>()-> debug_photon () )
1502
1498
{
1503
1499
device_log (" break rr {}" ,photon_id_1d);
1504
1500
};
@@ -1511,20 +1507,19 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1511
1507
bary_coords[path_size] = it->bary_coord ();
1512
1508
points[path_size] = it->p ();
1513
1509
normals[path_size] = it->ng ();
1514
- // $if(photon_id_1d<1 )
1510
+ // $if(photon_id_1d==node<MegakernelPhotonMappingDiff>()->debug_photon() )
1515
1511
// {
1516
1512
// device_log("adding path size {} id is {}",path_size,photon_id_1d);
1517
1513
// };
1518
1514
path_size = path_size+1u ;
1519
1515
};
1520
- $if (photon_id_1d<1 ){
1521
- device_log (" path size is {} id is {}" ,path_size,photon_id_1d);
1522
- $for (i,path_size)
1523
- {
1524
- device_log (" {} point {} normal {} eta {}, bary {}" ,i, points[i], normals[i], etas[i], bary_coords[i]);
1525
- };
1526
- EPSM_photon (path_size, points, normals, inst_ids, triangle_ids, bary_coords, etas, light_sample, grad_betas, grad_barys, mat_bary, mat_param);
1527
- };
1516
+ // $if(photon_id_1d==node<MegakernelPhotonMappingDiff>()->debug_photon()){
1517
+ // device_log("path size is {} id is {}",path_size,photon_id_1d);
1518
+ // $for(i,path_size)
1519
+ // {
1520
+ // device_log("{} point {} normal {} eta {}, bary {}",i, points[i], normals[i], etas[i], bary_coords[i]);
1521
+ // };
1522
+ // };
1528
1523
// $if(path_size>=2u)
1529
1524
// {
1530
1525
// device_log("path size is {}",path_size);
@@ -1536,20 +1531,16 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1536
1531
// return;
1537
1532
// EPSM_photon(path_size, points, normals, inst_ids, triangle_ids, bary_coords, etas, light_sample, grad_betas, grad_barys, mat_bary, mat_param);
1538
1533
// };
1539
- $if (tot_neighbors> 0 )
1534
+ $if (photon_id_1d<node<MegakernelPhotonMappingDiff>()-> debug_photon () )
1540
1535
{
1541
-
1536
+ $if (path_size>=2 &path_size<=4 ) {
1537
+ EPSM_photon (path_size, points, normals, inst_ids, triangle_ids, bary_coords, etas, light_sample, grad_betas, grad_barys, mat_bary, mat_param);
1538
+ };
1542
1539
};
1543
1540
}
1544
1541
void EPSM_photon (UInt path_size, ArrayFloat3<4 > &points, ArrayFloat3<4 > &normals, ArrayUInt<4 > &inst_ids, ArrayUInt<4 > &triangle_ids, ArrayFloat3<4 > &bary_coords,
1545
1542
ArrayFloat<4 > &etas, LightSampler::Sample &light_sample, ArrayFloat3<4 > grad_beta, ArrayFloat2<4 > grad_bary, ArrayFloat<8 * 8 * 2 > &mat_bary, ArrayFloat3<8 * 4 > &mat_param){
1546
1543
{
1547
- $if (path_size<2 |path_size>4 ) {
1548
- return ;
1549
- };
1550
- // Shared<float> *mat_bary = new Shared<float>(16*16);
1551
- // Shared<float3> *mat_param = new Shared<float3>(32);
1552
-
1553
1544
auto locate = [&](UInt i, UInt j) {
1554
1545
return (i<<4 |j);
1555
1546
};
@@ -1618,8 +1609,11 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1618
1609
tmp[i] -= grad_bary[j][0 ] * mat_bary[locate_adj (j * 2 , i)] + grad_bary[j][1 ] * mat_bary[locate_adj (j * 2 + 1 , i)];
1619
1610
};
1620
1611
};
1621
- $for (i,8 ) {
1622
- device_log (" mat_param {} {} {} {}" ,mat_param[i*4 +0 ],mat_param[i*4 +1 ],mat_param[i*4 +2 ],mat_param[i*4 +3 ]);
1612
+ $if (node<MegakernelPhotonMappingDiff>()->debug ())
1613
+ {
1614
+ $for (i,8 ) {
1615
+ device_log (" mat_param {} {} {} {}" ,mat_param[i*4 +0 ],mat_param[i*4 +1 ],mat_param[i*4 +2 ],mat_param[i*4 +3 ]);
1616
+ };
1623
1617
};
1624
1618
$for (i, n/2 ) {
1625
1619
Float3 grad_vertex = make_float3 (0 .0f ), grad_normal = make_float3 (0 .0f );
@@ -1631,6 +1625,10 @@ class MegakernelPhotonMappingDiffInstance : public DifferentiableIntegrator::Ins
1631
1625
$if (i<n/2 -2 ){
1632
1626
grad_vertex += tmp[i*2 +2 ]*mat_param[((i*2 +2 )<<2 )] + tmp[i*2 +3 ]*mat_param[((i*2 +3 )<<2 )];
1633
1627
};
1628
+ $if (node<MegakernelPhotonMappingDiff>()->debug ())
1629
+ {
1630
+ device_log (" grad_vertex {} grad_normal {}" ,grad_vertex, grad_normal);
1631
+ };
1634
1632
$if (inst_ids[i]==0 )
1635
1633
{
1636
1634
pipeline ().differentiation ()->add_geom_gradients (grad_vertex, grad_normal, bary_coords[i], inst_ids[i], triangle_ids[i]);
0 commit comments