1 |
#!/bin/csh -f |
2 |
# RCSid: $Id: compamb.csh,v 3.5 2003/02/22 02:07:30 greg Exp $ |
3 |
# |
4 |
# Compute best ambient value for a scene and append to rad input file |
5 |
# |
6 |
while ( $#argv > 1 ) |
7 |
switch ( $argv[1] ) |
8 |
case -e: |
9 |
set doexpos |
10 |
breaksw |
11 |
case -c: |
12 |
set docolor |
13 |
breaksw |
14 |
default: |
15 |
goto userr |
16 |
endsw |
17 |
shift argv |
18 |
end |
19 |
userr: |
20 |
if ( $#argv != 1 ) then |
21 |
echo Usage: $0 [-e][-c] rad_input_file |
22 |
exit 1 |
23 |
endif |
24 |
onintr quit |
25 |
set tf=/tmp/ca$$ |
26 |
set oct=`rad -w -s -e -v 0 $argv[1] QUA=High AMB=$tf.amb OPT=$tf.opt | sed -n 's/^OCTREE= //p'` |
27 |
rad -n -s -V $argv[1] \ |
28 |
| rpict @$tf.opt -av 0 0 0 -aw 16 -dv- -S 1 -x 16 -y 16 -ps 1 $oct \ |
29 |
| ra_rgbe - '\!pvalue -h -H -d' > $tf.dat |
30 |
echo \# Rad input file modified by $0 `date` >> $argv[1] |
31 |
if ( $?doexpos ) then |
32 |
(echo -n 'EXPOSURE= '; \ |
33 |
total -u $tf.dat | rcalc -e '$1=2/(.265*$1+.670*$2+.065*$3)') \ |
34 |
>> $argv[1] |
35 |
endif |
36 |
lookamb -h -d $tf.amb | rcalc -e '$1=$10;$2=$11;$3=$12' >> $tf.dat |
37 |
set lavg=`rcalc -e '$1=lum;lum=.265*$1+.670*$2+.065*$3;cond=lum-1e-5' $tf.dat | total -m -p` |
38 |
if ( $?docolor ) then |
39 |
set cavg=(`total -m $tf.dat`) |
40 |
set av=(`rcalc -n -e "r=$cavg[1];g=$cavg[2];b=$cavg[3];sf=$lavg/(.265*r+.670*g+.065*b)" -e '$1=sf*r;$2=sf*g;$3=sf*b'`) |
41 |
else |
42 |
set av=($lavg $lavg $lavg) |
43 |
endif |
44 |
echo "render= -av $av" >> $argv[1] |
45 |
quit: |
46 |
exec rm -f $tf.{amb,opt,dat} |