orig/compamb.csh
author Axel Jacobs <axel@jaloxa.eu>
Mon, 14 Apr 2014 22:21:17 +0100
changeset 73 87fa3132a136
parent 0 0aa115157c9c
permissions -rw-r--r--
New IES test file with spaces in file name
axel@0
     1
#!/bin/csh -f
axel@0
     2
# RCSid: $Id: compamb.csh,v 3.7 2008/08/25 04:50:32 greg Exp $
axel@0
     3
#
axel@0
     4
# Compute best ambient value for a scene and append to rad input file
axel@0
     5
#
axel@0
     6
while ( $#argv > 1 )
axel@0
     7
	switch ( $argv[1] )
axel@0
     8
	case -e:
axel@0
     9
		set doexpos
axel@0
    10
		breaksw
axel@0
    11
	case -c:
axel@0
    12
		set docolor
axel@0
    13
		breaksw
axel@0
    14
	default:
axel@0
    15
		goto userr
axel@0
    16
	endsw
axel@0
    17
	shift argv
axel@0
    18
end
axel@0
    19
userr:
axel@0
    20
if ( $#argv != 1 ) then
axel@0
    21
	echo Usage: $0 [-e][-c] rad_input_file
axel@0
    22
	exit 1
axel@0
    23
endif
axel@0
    24
onintr quit
axel@0
    25
set td=`mktemp -d /tmp/ca.XXXXXX`
axel@0
    26
set tf=$td/compamb
axel@0
    27
set oct=`rad -w -s -e -v 0 $argv[1] QUA=High AMB=$tf.amb OPT=$tf.opt | sed -n 's/^OCTREE= //p'`
axel@0
    28
rad -n -s -V $argv[1] \
axel@0
    29
	| rpict @$tf.opt -av 0 0 0 -aw 16 -dv- -S 1 -x 16 -y 16 -ps 1 $oct \
axel@0
    30
	| ra_rgbe - '\!pvalue -h -H -d' > $tf.dat
axel@0
    31
echo \# Rad input file modified by $0 `date` >> $argv[1]
axel@0
    32
if ( $?doexpos ) then
axel@0
    33
	(echo -n 'EXPOSURE= '; \
axel@0
    34
		total -u $tf.dat | rcalc -e '$1=2/(.265*$1+.670*$2+.065*$3)') \
axel@0
    35
		>> $argv[1]
axel@0
    36
endif
axel@0
    37
lookamb -h -d $tf.amb | rcalc -e '$1=$10;$2=$11;$3=$12' >> $tf.dat
axel@0
    38
set lavg=`rcalc -e '$1=lum;lum=.265*$1+.670*$2+.065*$3;cond=lum-1e-5' $tf.dat | total -m -p`
axel@0
    39
if ( $?docolor ) then
axel@0
    40
	set cavg=(`total -m $tf.dat`)
axel@0
    41
	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'`)
axel@0
    42
else
axel@0
    43
	set av=($lavg $lavg $lavg)
axel@0
    44
endif
axel@0
    45
echo "render= -av $av" >> $argv[1]
axel@0
    46
quit:
axel@0
    47
exec rm -r $td