--- ray/src/util/genBSDF.pl 2018/04/17 18:11:17 2.79 +++ ray/src/util/genBSDF.pl 2023/09/22 18:01:32 2.90 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genBSDF.pl,v 2.79 2018/04/17 18:11:17 greg Exp $ +# RCSid $Id: genBSDF.pl,v 2.90 2023/09/22 18:01:32 greg Exp $ # # Compute BSDF based on geometry and material description # @@ -13,7 +13,7 @@ sub userror { exit 1; } my ($td,$radscn,$mgfscn,$octree,$fsender,$bsender,$receivers,$facedat,$behinddat,$rmtmp); -my ($tf,$rf,$tb,$rb,$tfx,$rfx,$tbx,$rbx,$tfz,$rfz,$tbz,$rbz,$cph); +my ($tf,$rf,$tb,$rb,$tfx,$rfx,$tbx,$rbx,$tfz,$rfz,$tbz,$rbz); my ($curphase, $recovery); if ($#ARGV == 1 && "$ARGV[0]" =~ /^-rec/) { $td = $ARGV[1]; @@ -57,7 +57,6 @@ if ($windoz) { $rfz = "$td\\rfz.dat"; $tbz = "$td\\tbz.dat"; $rbz = "$td\\rbz.dat"; - $cph = "$td\\phase.txt"; $rmtmp = "rd /S /Q $td"; } else { $radscn = "$td/device.rad"; @@ -80,7 +79,6 @@ if ($windoz) { $rfz = "$td/rfz.dat"; $tbz = "$td/tbz.dat"; $rbz = "$td/rbz.dat"; - $cph = "$td/phase.txt"; $rmtmp = "rm -rf $td"; } my @savedARGV = @ARGV; @@ -189,8 +187,9 @@ $wrapper .= " -g $mgfscn" if ( $geout ); my $CIEuv = 'Xi=.5141*Ri+.3239*Gi+.1620*Bi;' . 'Yi=.2651*Ri+.6701*Gi+.0648*Bi;' . 'Zi=.0241*Ri+.1229*Gi+.8530*Bi;' . - 'den=Xi+15*Yi+3*Zi+1e-9;' . - 'uprime=4*Xi/den;vprime=9*Yi/den;' ; + 'den=Xi+15*Yi+3*Zi;' . + 'uprime=if(Yi,4*Xi/den,4/19);' . + 'vprime=if(Yi,9*Yi/den,9/19);' ; my $FEPS = 1e-5; my $ns = 2**$ttlog2; my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + 1); @@ -204,7 +203,7 @@ if ( !defined $recovery ) { } close MYAVH; # Generate octree - system "oconv -w -f $radscn > $octree"; + system "oconv -w $radscn > $octree"; die "Could not compile scene\n" if ( $? ); # Add MGF description if requested if ( $geout ) { @@ -212,6 +211,7 @@ if ( !defined $recovery ) { printf MGFSCN "xf -t %.6f %.6f 0\n", -($dim[0]+$dim[1])/2, -($dim[2]+$dim[3])/2; close MGFSCN; if ( $mgfin ) { + die "+mgf requires input file with +geom\n" if ($#ARGV < 0); system qq{mgfilt "#,o,xf,c,cxy,cspec,cmix,m,sides,rd,td,rs,ts,ir,v,p,n,f,fh,sph,cyl,cone,prism,ring,torus" @ARGV >> $mgfscn}; } else { system "rad2mgf $radscn >> $mgfscn"; @@ -322,7 +322,11 @@ sub do_ttree_dir { qq{| rcalc -e "r1=rand(.8681*recno-.673892)" } . qq{-e "r2=rand(-5.37138*recno+67.1737811)" } . qq{-e "r3=rand(+3.17603772*recno+83.766771)" } . - qq{-e "Dx=1-2*(\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)" } . + qq{-e "r4=rand(-1.5839226*recno-59.82712)" } . + qq{-e "odds(n):if(.5*n-floor(.5*n)-.25,-1,1)"} . + qq{-e "Dx=1-(\$1+r1)/$ns2" } . + qq{-e "Dy=min(1/$ns,sqrt(1-Dx*Dx))*odds(\$1)*r2" } . + qq{-e "Dz=sqrt(1-Dx*Dx-Dy*Dy)" } . qq{-e "xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]" } . qq{-e "yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]" } . qq{-e "zp=$dim[5-$forw]" -e "myDz=Dz*($forw*2-1)" } . @@ -334,9 +338,13 @@ sub do_ttree_dir { qq{| rcalc -e 'r1=rand(.8681*recno-.673892)' } . qq{-e 'r2=rand(-5.37138*recno+67.1737811)' } . qq{-e 'r3=rand(+3.17603772*recno+83.766771)' } . - qq{-e 'Dx=1-2*(\$1+r1)/$ns;Dy:0;Dz=sqrt(1-Dx*Dx)' } . - qq{-e 'xp=(\$3+r2)*(($dim[1]-$dim[0])/$nx)+$dim[0]' } . - qq{-e 'yp=(\$2+r3)*(($dim[3]-$dim[2])/$ny)+$dim[2]' } . + qq{-e 'r4=rand(-1.5839226*recno-59.82712)' } . + qq{-e 'odds(n):if(.5*n-floor(.5*n)-.25,-1,1)' } . + qq{-e 'Dx=1-(\$1+r1)/$ns2' } . + qq{-e 'Dy=min(1/$ns,sqrt(1-Dx*Dx))*odds(\$1)*r2' } . + qq{-e 'Dz=sqrt(1-Dx*Dx-Dy*Dy)' } . + qq{-e 'xp=(\$3+r3)*(($dim[1]-$dim[0])/$nx)+$dim[0]' } . + qq{-e 'yp=(\$2+r4)*(($dim[3]-$dim[2])/$ny)+$dim[2]' } . qq{-e 'zp=$dim[5-$forw]' -e 'myDz=Dz*($forw*2-1)' } . qq{-e '\$1=xp-Dx;\$2=yp-Dy;\$3=zp-myDz' } . qq{-e '\$4=Dx;\$5=Dy;\$6=myDz' -of } . @@ -427,7 +435,7 @@ sub ttree_comp { } } if ($pctcull >= 0) { - my $avg = ( $dorecip && "$typ" =~ /^r[fb]/ ) ? " -a" : ""; + my $avg = ( $dorecip && ( $tensortree == 3 || "$typ" =~ /^r[fb]/ ) ) ? " -a" : ""; my $pcull = ("$spec" eq "Visible") ? $pctcull : (100 - (100-$pctcull)*.25) ; if ($windoz) {