--- ray/src/util/genBSDF.pl 2015/03/25 22:50:48 2.54 +++ ray/src/util/genBSDF.pl 2015/04/02 17:42:46 2.57 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genBSDF.pl,v 2.54 2015/03/25 22:50:48 greg Exp $ +# RCSid $Id: genBSDF.pl,v 2.57 2015/04/02 17:42:46 greg Exp $ # # Compute BSDF based on geometry and material description # @@ -9,7 +9,7 @@ use strict; my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); use File::Temp qw/ :mktemp /; sub userror { - print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-W][-t{3|4} Nlog2][-r \"ropts\"][-f \"x=string;y=string\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}C][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n"; + print STDERR "Usage: genBSDF [-n Nproc][-c Nsamp][-W][-t{3|4} Nlog2][-r \"ropts\"][-s \"x=string;y=string\"][-dim xmin xmax ymin ymax zmin zmax][{+|-}C][{+|-}f][{+|-}b][{+|-}mgf][{+|-}geom units] [input ..]\n"; exit 1; } my ($td,$radscn,$mgfscn,$octree,$fsender,$bsender,$receivers,$facedat,$behinddat,$rmtmp); @@ -104,12 +104,15 @@ while ($#ARGV >= 0) { } elsif ("$ARGV[0]" eq "-t") { # Use value < 0 for rttree_reduce bypass $pctcull = $ARGV[1]; + if ($pctcull >= 100) { + die "Illegal -t culling percentage, must be < 100\n"; + } shift @ARGV; } elsif ("$ARGV[0]" =~ /^-t[34]$/) { $tensortree = substr($ARGV[0], 2, 1); $ttlog2 = $ARGV[1]; shift @ARGV; - } elsif ("$ARGV[0]" eq "-f") { + } elsif ("$ARGV[0]" eq "-s") { $wrapper .= " -f \"$ARGV[1]\""; shift @ARGV; } elsif ("$ARGV[0]" eq "-W") { @@ -171,16 +174,18 @@ if ( $geout ) { $wrapper .= " -g $mgfscn"; } # Create receiver & sender surfaces (rectangular) +my $FEPS = 1e-5; my $nx = int(sqrt($nsamp*($dim[1]-$dim[0])/($dim[3]-$dim[2])) + 1); my $ny = int($nsamp/$nx + 1); $nsamp = $nx * $ny; my $ns = 2**$ttlog2; open(RADSCN, "> $receivers"); -print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=sc$ns\n" : "h=kf\n"); -print RADSCN '#@rfluxmtx ' . "u=Y o=$facedat\n\n"; +print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=-sc$ns\n" : "h=-kf\n"); +print RADSCN '#@rfluxmtx ' . "u=-Y o=$facedat\n\n"; print RADSCN "void glow receiver_face\n0\n0\n4 1 1 1 0\n\n"; print RADSCN "receiver_face source f_receiver\n0\n0\n4 0 0 1 180\n\n"; -print RADSCN '#@rfluxmtx ' . "u=Y o=$behinddat\n\n"; +print RADSCN '#@rfluxmtx ' . ($tensortree ? "h=+sc$ns\n" : "h=+kf\n"); +print RADSCN '#@rfluxmtx ' . "u=-Y o=$behinddat\n\n"; print RADSCN "void glow receiver_behind\n0\n0\n4 1 1 1 0\n\n"; print RADSCN "receiver_behind source b_receiver\n0\n0\n4 0 0 -1 180\n"; close RADSCN; @@ -188,20 +193,20 @@ close RADSCN; $rfluxmtx .= " -n $nproc -c $nsamp"; if ( $tensortree != 3 ) { # Isotropic tensor tree is exception open (RADSCN, "> $fsender"); - print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n"); + print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=-sc$ns\n\n" : "h=-kf\n\n"); print RADSCN "void polygon fwd_sender\n0\n0\n12\n"; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[4]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[4]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[4]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[4]; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[4]-$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[4]-$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[4]-$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[4]-$FEPS; close RADSCN; open (RADSCN, "> $bsender"); - print RADSCN '#@rfluxmtx u=Y ' . ($tensortree ? "h=sc$ns\n\n" : "h=kf\n\n"); - print RADSCN "void polygon fwd_sender\n0\n0\n12\n"; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[2], $dim[5]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[2], $dim[5]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[1], $dim[3], $dim[5]; - printf RADSCN "\t%f\t%f\t%f\n", $dim[0], $dim[3], $dim[5]; + print RADSCN '#@rfluxmtx u=-Y ' . ($tensortree ? "h=+sc$ns\n\n" : "h=+kf\n\n"); + print RADSCN "void polygon bwd_sender\n0\n0\n12\n"; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[2], $dim[5]+$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[2], $dim[5]+$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[1], $dim[3], $dim[5]+$FEPS; + printf RADSCN "\t%e\t%e\t%e\n", $dim[0], $dim[3], $dim[5]+$FEPS; close RADSCN; } # Calculate CIE (u',v') from Radiance RGB: @@ -355,7 +360,7 @@ sub ttree_comp { if ($pctcull >= 0) { my $avg = ( "$typ" =~ /^r[fb]/ ) ? " -a" : ""; my $pcull = ("$spec" eq "Visible") ? $pctcull : - (100 - (100-$pctcull)/3) ; + (100 - (100-$pctcull)*.25) ; if ($windoz) { $cmd = "rcollate -ho -oc 1 $src | " . $cmd . @@ -450,11 +455,11 @@ sub matrix_comp { my $dest = shift; my $cmd = "rmtxop -fa -t"; if ("$spec" eq "Visible") { - $cmd .= " -c 0.265 0.670 0.065"; + $cmd .= " -c 0.2651 0.6701 0.0648"; } elsif ("$spec" eq "CIE-X") { - $cmd .= " -c 0.514 0.324 0.162"; + $cmd .= " -c 0.5141 0.3239 0.1620"; } elsif ("$spec" eq "CIE-Z") { - $cmd .= " -c 0.024 0.123 0.853"; + $cmd .= " -c 0.0241 0.1229 0.8530"; } $cmd .= " $src | rcollate -ho -oc 145"; # print STDERR "Running: $cmd\n";