| 11 | 
  | 
my $nprocs = 1; | 
| 12 | 
  | 
# rtrace options and the associated number of arguments | 
| 13 | 
  | 
my %rtraceC = ('-dt',1, '-dc',1, '-dj',1, '-ds',1, '-dr',1, '-dp',1, | 
| 14 | 
< | 
                '-ss',1, '-st',1, '-e',1, '-am',1, | 
| 14 | 
> | 
                '-ss',1, '-st',1, '-e',1, '-am',1, '-P',1, '-PP',1, | 
| 15 | 
  | 
                '-ab',1, '-af',1, '-ai',1, '-aI',1, '-ae',1, '-aE',1, | 
| 16 | 
  | 
                '-av',3, '-aw',1, '-aa',1, '-ar',1, '-ad',1, '-as',1, | 
| 17 | 
< | 
                '-me',3, '-ma',3, '-mg',1, '-ms',1, '-lr',1, '-lw',1); | 
| 17 | 
> | 
                '-me',3, '-ma',3, '-mg',1, '-ms',1, '-lr',1, '-lw',1, | 
| 18 | 
> | 
                '-ap',2, '-am',1, '-ac',1, '-aC',1, | 
| 19 | 
> | 
                '-cs',1, '-cw',2, '-pc',8, '-pXYZ',0); | 
| 20 | 
  | 
# boolean rtrace options | 
| 21 | 
< | 
my @boolO = ('-w', '-bv', '-dv', '-i', '-u'); | 
| 21 | 
> | 
my @boolO = ('-w', '-bv', '-dv', '-i', '-u', '-co'); | 
| 22 | 
  | 
# view options and the associated number of arguments | 
| 23 | 
  | 
my %vwraysC = ('-vf',1, '-vtv',0, '-vtl',0, '-vth',0, '-vta',0, '-vts',0, '-vtc',0, | 
| 24 | 
  | 
                '-x',1, '-y',1, '-vp',3, '-vd',3, '-vu',3, '-vh',1, '-vv',1, | 
| 25 | 
< | 
                '-vo',1, '-va',1, '-vs',1, '-vl',1, '-pa',1, '-pj',1); | 
| 25 | 
> | 
                '-vo',1, '-va',1, '-vs',1, '-vl',1, '-pa',1, '-pj',1, '-pd',1); | 
| 26 | 
  | 
# options we need to silently ignore | 
| 27 | 
< | 
my %ignoreC = ('-t',1, '-ps',1, '-pt',1, '-pm',1, '-pd',1); | 
| 27 | 
> | 
my %ignoreC = ('-t',1, '-ps',1, '-pt',1, '-pm',1,); | 
| 28 | 
  | 
# Starting options for rtrace (rpict values) | 
| 29 | 
  | 
my @rtraceA = split(' ', 'rtrace -u- -dt .05 -dc .5 -ds .25 -dr 1 ' . | 
| 30 | 
< | 
                                '-aa .2 -ar 64 -ad 512 -as 128 -lr 7 -lw 1e-03'); | 
| 31 | 
< | 
my @vwraysA = ('vwrays', '-ff', '-pj', '.67'); | 
| 30 | 
> | 
                                '-aa .2 -ar 64 -ad 512 -as 128 -lr 7 -lw 1e-04'); | 
| 31 | 
> | 
my @vwraysA = ('vwrays', '-pj', '.67'); | 
| 32 | 
  | 
my @vwrightA = ('vwright', '-vtv'); | 
| 33 | 
< | 
my @rpictA = ('rpict'); | 
| 33 | 
> | 
my @rpictA = ('rpict', '-ps', '1'); | 
| 34 | 
> | 
my @pvalueA = ('pvalue', '-r'); | 
| 35 | 
  | 
my $outpatt = '^-o[vrxlLRXnNsmM]+'; | 
| 36 | 
  | 
my $refDepth = ""; | 
| 37 | 
  | 
my $irrad = 0; | 
| 38 | 
+ | 
my $specout = 0; | 
| 39 | 
+ | 
my $ncsamp = 3; | 
| 40 | 
+ | 
my $persist = 0; | 
| 41 | 
+ | 
my $ambounce = 0; | 
| 42 | 
+ | 
my $ambcache = 1; | 
| 43 | 
+ | 
my $ambfile; | 
| 44 | 
  | 
my $outlyr; | 
| 45 | 
  | 
my $outdir; | 
| 46 | 
  | 
my $outpic; | 
| 49 | 
  | 
while ($#ARGV >= 0 && "$ARGV[0]" =~ /^[-\@]/) { | 
| 50 | 
  | 
        # Check for file inclusion | 
| 51 | 
  | 
        if ("$ARGV[0]" =~ /^\@/) { | 
| 52 | 
< | 
                open my $handle, '<', substr($ARGV[0], 1); | 
| 52 | 
> | 
                open my $handle, '<', substr($ARGV[0], 1) or die "No file for $ARGV[0]\n"; | 
| 53 | 
  | 
                shift @ARGV; | 
| 54 | 
  | 
                chomp(my @args = <$handle>); | 
| 55 | 
  | 
                close $handle; | 
| 63 | 
  | 
                                $irrad = ! $irrad; | 
| 64 | 
  | 
                        } elsif ("$ARGV[0]" =~ /^-i[-+01tfynTFYN]/) { | 
| 65 | 
  | 
                                $irrad = ("$ARGV[0]" =~ /^-i[+1tyTY]/); | 
| 66 | 
+ | 
                        } elsif ("$ARGV[0]" eq '-co') { | 
| 67 | 
+ | 
                                $specout = ! $specout; | 
| 68 | 
+ | 
                        } elsif ("$ARGV[0]" =~ /^-co[-+01tfynTFYN]/) { | 
| 69 | 
+ | 
                                $specout = ("$ARGV[0]" =~ /^-co[+1tyTY]/); | 
| 70 | 
  | 
                        } | 
| 71 | 
< | 
                        push @rtraceA, $ARGV[0]; | 
| 72 | 
< | 
                        push @rpictA, shift(@ARGV); | 
| 71 | 
> | 
                        push(@rpictA, $ARGV[0]) if ("$ARGV[0]" !~ /^-co/); | 
| 72 | 
> | 
                        push @rtraceA, shift(@ARGV); | 
| 73 | 
  | 
                        next OPTION; | 
| 74 | 
  | 
                } | 
| 75 | 
  | 
        } | 
| 88 | 
  | 
        } | 
| 89 | 
  | 
        # Check rtrace options | 
| 90 | 
  | 
        if (defined $rtraceC{$ARGV[0]}) { | 
| 91 | 
+ | 
                if ("$ARGV[0]" =~ /^-PP?$/) { | 
| 92 | 
+ | 
                        $persist = 1; | 
| 93 | 
+ | 
                } elsif ("$ARGV[0]" eq '-ab') { | 
| 94 | 
+ | 
                        $ambounce = $ARGV[1]; | 
| 95 | 
+ | 
                } elsif ("$ARGV[0]" eq '-aa') { | 
| 96 | 
+ | 
                        $ambcache = ($ARGV[1] > 0.0); | 
| 97 | 
+ | 
                } elsif ("$ARGV[0]" eq '-af') { | 
| 98 | 
+ | 
                        $ambfile = "$ARGV[1]"; | 
| 99 | 
+ | 
                } elsif ("$ARGV[0]" eq '-pXYZ') { | 
| 100 | 
+ | 
                        push @pvalueA, $ARGV[0]; | 
| 101 | 
+ | 
                        $specout = 0; | 
| 102 | 
+ | 
                } elsif ("$ARGV[0]" eq '-pc') { | 
| 103 | 
+ | 
                        push @pvalueA, '-p'; | 
| 104 | 
+ | 
                        push @pvalueA, @ARGV[1..8]; | 
| 105 | 
+ | 
                        $specout = 0; | 
| 106 | 
+ | 
                } elsif ("$ARGV[0]" eq '-cs') { | 
| 107 | 
+ | 
                        $ncsamp = $ARGV[1]; | 
| 108 | 
+ | 
                } | 
| 109 | 
  | 
                push @rtraceA, $ARGV[0]; | 
| 110 | 
  | 
                push @rpictA, shift(@ARGV); | 
| 111 | 
  | 
                for (my $i = $rtraceC{$rpictA[-1]}; $i-- > 0; ) { | 
| 145 | 
  | 
        } | 
| 146 | 
  | 
} | 
| 147 | 
  | 
die "Number of processes must be positive" if ($nprocs <= 0); | 
| 148 | 
+ | 
if ($specout) { | 
| 149 | 
+ | 
        $specout = ($ncsamp > 3); | 
| 150 | 
+ | 
} | 
| 151 | 
  | 
if (defined $outdir) {          # check conflicting options | 
| 152 | 
  | 
        die "Options -o and -o* are mutually exclusive\n" if (defined $outpic); | 
| 153 | 
  | 
        die "Options -z and -o* are mutually exclusive\n" if (defined $outzbf); | 
| 158 | 
  | 
} | 
| 159 | 
  | 
##################################################################### | 
| 160 | 
  | 
##### May as well run rpict? | 
| 161 | 
< | 
if ($nprocs == 1 && !defined($outdir)) { | 
| 161 | 
> | 
if ($specout == 0 && $nprocs == 1 && $persist == 0 && !defined($outdir)) { | 
| 162 | 
  | 
        push(@rpictA, $ARGV[0]) if ($#ARGV == 0); | 
| 163 | 
  | 
        exec @rpictA ; | 
| 164 | 
  | 
} | 
| 170 | 
  | 
chomp $view; | 
| 171 | 
  | 
my @res = split(/\s/, `@vwraysA -d`); | 
| 172 | 
  | 
##################################################################### | 
| 173 | 
+ | 
##### Resort pixels to reduce ambient cache collisions? | 
| 174 | 
+ | 
if ($nprocs > 1 && $ambounce > 0 && $ambcache && defined($ambfile)) { | 
| 175 | 
+ | 
        if ($specout == 0 && !defined($outzbf) && !defined($outdir)) { | 
| 176 | 
+ | 
                # Straight picture output, so just shuffle sample order | 
| 177 | 
+ | 
                system "cnt -s $res[1] $res[3] > /tmp/ord$$.txt"; | 
| 178 | 
+ | 
                die "cnt error\n" if ( $? ); | 
| 179 | 
+ | 
                system "@vwraysA -ff -i < /tmp/ord$$.txt " . | 
| 180 | 
+ | 
                        "| @rtraceA -ffa -ov '$oct' > /tmp/pix$$.txt"; | 
| 181 | 
+ | 
                die "Error running rtrace\n" if ( $? ); | 
| 182 | 
+ | 
                system "( getinfo < /tmp/pix$$.txt | getinfo -r NCOMP " . | 
| 183 | 
+ | 
                        "| getinfo -a 'VIEW=$view'; " . | 
| 184 | 
+ | 
                        "getinfo - < /tmp/pix$$.txt | rlam /tmp/ord$$.txt - " . | 
| 185 | 
+ | 
                        "| sort -k2rn -k1n ) | @pvalueA -Y $res[3] +X $res[1]"; | 
| 186 | 
+ | 
                die "rlam error\n" if ( $? ); | 
| 187 | 
+ | 
                unlink ("/tmp/ord$$.txt", "/tmp/pix$$.txt"); | 
| 188 | 
+ | 
                exit 0; | 
| 189 | 
+ | 
        } | 
| 190 | 
+ | 
        # Else randomize overture calculation to prime ambient cache | 
| 191 | 
+ | 
        my @ores = (int($res[1]/6), int($res[3]/6)); | 
| 192 | 
+ | 
        print STDERR "Running $ores[0] by $ores[1] overture calculation " . | 
| 193 | 
+ | 
                        "to populate '$ambfile'...\n"; | 
| 194 | 
+ | 
        system "cnt -s @ores | @vwraysA -i -ff -x $ores[0] -y $ores[1] -pj 0 " . | 
| 195 | 
+ | 
                "| @rtraceA -ff -ov -pY '$oct' > /dev/null"; | 
| 196 | 
+ | 
        die "Failure running overture\n" if ( $? ); | 
| 197 | 
+ | 
        print STDERR "Finished overture.\n"; | 
| 198 | 
+ | 
} | 
| 199 | 
+ | 
##################################################################### | 
| 200 | 
  | 
##### Generating picture with depth buffer? | 
| 201 | 
  | 
if (defined $outzbf) { | 
| 202 | 
< | 
        exec "@vwraysA | @rtraceA -fff -olv @res $oct | " . | 
| 203 | 
< | 
                "rsplit -ih -iH -f -of $outzbf -oh -oH -of3 - | " . | 
| 204 | 
< | 
                "pvalue -r -df | getinfo -a 'VIEW=$view'"; | 
| 202 | 
> | 
        my $picvt = $specout ? 'rcomb -fc -' : "@pvalueA -df"; | 
| 203 | 
> | 
        exec "@vwraysA -ff | @rtraceA -fff -olv @res '$oct' | " . | 
| 204 | 
> | 
                "rsplit -ih -iH -f -of '$outzbf' -oh -oH -of$ncsamp - | " . | 
| 205 | 
> | 
                $picvt . " | getinfo -a 'VIEW=$view'"; | 
| 206 | 
  | 
} | 
| 207 | 
  | 
##################################################################### | 
| 208 | 
  | 
##### Base case with output picture only? | 
| 209 | 
  | 
if (! defined $outdir) { | 
| 210 | 
< | 
        exec "@vwraysA | @rtraceA -ffc @res $oct | getinfo -a 'VIEW=$view'"; | 
| 210 | 
> | 
        exec "@vwraysA -ff | @rtraceA -ffc @res '$oct' | getinfo -a 'VIEW=$view'"; | 
| 211 | 
  | 
} | 
| 212 | 
  | 
##################################################################### | 
| 213 | 
  | 
##### Layered image output case | 
| 229 | 
  | 
); | 
| 230 | 
  | 
# Arguments for rsplit based on output file type | 
| 231 | 
  | 
my %rcodeC = ( | 
| 232 | 
< | 
        '.hdr', ['-of3', '!pvalue -r -df -u'], | 
| 232 | 
> | 
        '.hdr', ['-of3', "!@pvalueA -df -u"], | 
| 233 | 
> | 
        '.hsr', ["-of$ncsamp", '!rcomb -fc -'], | 
| 234 | 
  | 
        '.dpt', ['-of', "!rcode_depth$refDepth -ff"], | 
| 235 | 
  | 
        '.nrm', ['-of3', '!rcode_norm -ff'], | 
| 236 | 
  | 
        '.idx', ['-oa', '!rcode_ident "-t       "'] | 
| 237 | 
  | 
); | 
| 238 | 
+ | 
if ($specout) {         # adjust actions for -co+ option | 
| 239 | 
+ | 
        $rtoutC{'v'} = 'radiance.hsr'; | 
| 240 | 
+ | 
        $rtoutC{'r'} = 'r_refl.hsr'; | 
| 241 | 
+ | 
        $rtoutC{'x'} = 'r_unrefl.hsr'; | 
| 242 | 
+ | 
} | 
| 243 | 
  | 
if ($irrad) {           # adjust actions for -i+ option | 
| 244 | 
< | 
        $rtoutC{'v'} = 'irradiance.hdr'; | 
| 244 | 
> | 
        $rtoutC{'v'} = $specout ? 'irradiance.hsr' : 'irradiance.hdr'; | 
| 245 | 
  | 
        delete $rtoutC{'r'}; | 
| 246 | 
  | 
        delete $rtoutC{'x'}; | 
| 247 | 
  | 
        delete $rtoutC{'R'}; | 
| 254 | 
  | 
foreach my $oval (split //, $outlyr) { | 
| 255 | 
  | 
        die "Duplicate or unsupported type '$oval' in -o$outlyr\n" | 
| 256 | 
  | 
                                        if (!defined $rtoutC{$oval}); | 
| 257 | 
+ | 
        my $outfile = "$outdir/$rtoutC{$oval}"; | 
| 258 | 
+ | 
        die "File '$outfile' already exists\n" if (-e $outfile); | 
| 259 | 
  | 
        my ($otyp) = ($rtoutC{$oval} =~ /(\.[^.]+)$/); | 
| 260 | 
  | 
        push @rsplitA, $rcodeC{$otyp}[0]; | 
| 261 | 
< | 
        push @rsplitA, qq{'$rcodeC{$otyp}[1] > "$outdir/$rtoutC{$oval}"'}; | 
| 261 | 
> | 
        push @rsplitA, qq{'$rcodeC{$otyp}[1] > "$outfile"'}; | 
| 262 | 
  | 
        delete $rtoutC{$oval}; | 
| 263 | 
  | 
} | 
| 264 | 
  | 
                        # call rtrace + rsplit | 
| 265 | 
< | 
exec "@vwraysA | @rtraceA -fff @res $oct | getinfo -a 'VIEW=$view' | @rsplitA"; | 
| 265 | 
> | 
exec "@vwraysA -ff | @rtraceA -fff @res '$oct' | getinfo -a 'VIEW=$view' | @rsplitA"; |