| 1 |
{ RCSid $Id: klems_half.cal,v 1.5 2022/07/14 02:52:02 greg Exp $ }
|
| 2 |
{
|
| 3 |
Compute interior bin for half Klems BSDF basis (0-72)
|
| 4 |
Returns -1 for wrong-side rays
|
| 5 |
|
| 6 |
Modified from klems_full.cal
|
| 7 |
|
| 8 |
7/18/2014 G. Ward
|
| 9 |
}
|
| 10 |
DEGREE` : PI/180;
|
| 11 |
mod`(n,d) : n - floor(n/d)*d;
|
| 12 |
Acos(x) : if(x-1, 0, if(-1-x, PI, acos(x))) / DEGREE;
|
| 13 |
|
| 14 |
khpola(r) : select(r, 6.5, 19.5, 32.5, 45.5, 58.5, 71.5, 90);
|
| 15 |
KHAPS : khpola(3) - khpola(2);
|
| 16 |
khnaz(r) : select(r, 1, 8, 12, 16, 20, 12, 8);
|
| 17 |
khaccum(r) : if(r-.5, khnaz(r) + khaccum(r-1), 0);
|
| 18 |
khfindrow(r, pol) : if(r-khpola(0)+.5, r,
|
| 19 |
if(pol-khpola(r), khfindrow(r+1, pol), r) );
|
| 20 |
|
| 21 |
RHS = 1; { Set to -1 for left-handed system }
|
| 22 |
JTR = 0; { Sharp bin boundaries by default }
|
| 23 |
{ Uniform perturbation function }
|
| 24 |
kjtr(n) = if(JTR, JTR*(.5 - rand(n*(9.54*Dx - 5.11*Dy + 1.37*Dz - 6.71))), 0);
|
| 25 |
|
| 26 |
kazn(azi,inc) = floor( mod(azi + inc*(.5+kjtr(2)), 360) / inc );
|
| 27 |
|
| 28 |
khbin2(pol,azi) =
|
| 29 |
select(khfindrow(1, pol),
|
| 30 |
kazn(azi,360/khnaz(1)),
|
| 31 |
khaccum(1) + kazn(azi,360/khnaz(2)),
|
| 32 |
khaccum(2) + kazn(azi,360/khnaz(3)),
|
| 33 |
khaccum(3) + kazn(azi,360/khnaz(4)),
|
| 34 |
khaccum(4) + kazn(azi,360/khnaz(5)),
|
| 35 |
khaccum(5) + kazn(azi,360/khnaz(6)),
|
| 36 |
khaccum(6) + kazn(azi,360/khnaz(7))
|
| 37 |
);
|
| 38 |
|
| 39 |
khbin1(zv,yv,xv) = if(zv, khbin2(min(max(0, Acos(zv) + KHAPS*kjtr(1)), 90),
|
| 40 |
atan2(yv,xv)/DEGREE),
|
| 41 |
-1);
|
| 42 |
|
| 43 |
khbin(Nx,Ny,Nz,Ux,Uy,Uz) = khbin1(-Dx*Nx-Dy*Ny-Dz*Nz,
|
| 44 |
-Dx*Ux-Dy*Uy-Dz*Uz + (Nx*Dx+Ny*Dy+Nz*Dz)*(Nx*Ux+Ny*Uy+Nz*Uz),
|
| 45 |
-RHS*(Dx*(Uy*Nz-Uz*Ny) + Dy*(Uz*Nx-Ux*Nz) + Dz*(Ux*Ny-Uy*Nx)));
|
| 46 |
|
| 47 |
Nkhbins : khaccum(khnaz(0)); { Number of bins for one elevation }
|