ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/util/klems_quarter.cal
Revision: 1.7
Committed: Fri Nov 14 23:51:42 2025 UTC (2 days, 16 hours ago) by greg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +25 -18 lines
Log Message:
feat(rfluxmtx,rxfluxmtx): Added bin sample jittering for smoother visual results

File Contents

# Content
1 { RCSid $Id: klems_quarter.cal,v 1.6 2022/07/14 02:52:02 greg Exp $ }
2 {
3 Compute interior bin for quarter Klems BSDF basis (0-40)
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 kqpola(r) : select(r, 9, 27, 45, 63, 90);
15 KQAPS : kqpola(3) - kqpola(2);
16 kqnaz(r) : select(r, 1, 8, 12, 12, 8);
17 kqaccum(r) : if(r-.5, kqnaz(r) + kqaccum(r-1), 0);
18 kqfindrow(r, pol) : if(r-kqpola(0)+.5, r,
19 if(pol-kqpola(r), kqfindrow(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 kqbin2(pol,azi) =
29 select(kqfindrow(1, pol),
30 kazn(azi,360/kqnaz(1)),
31 kqaccum(1) + kazn(azi,360/kqnaz(2)),
32 kqaccum(2) + kazn(azi,360/kqnaz(3)),
33 kqaccum(3) + kazn(azi,360/kqnaz(4)),
34 kqaccum(4) + kazn(azi,360/kqnaz(5))
35 );
36
37 kqbin1(zv,yv,xv) = if(zv, kqbin2(min(max(0, Acos(zv) + KQAPS*kjtr(1)), 90),
38 atan2(yv,xv)/DEGREE),
39 -1);
40
41 kqbin(Nx,Ny,Nz,Ux,Uy,Uz) = kqbin1(-Dx*Nx-Dy*Ny-Dz*Nz,
42 -Dx*Ux-Dy*Uy-Dz*Uz + (Nx*Dx+Ny*Dy+Nz*Dz)*(Nx*Ux+Ny*Uy+Nz*Uz),
43 -RHS*(Dx*(Uy*Nz-Uz*Ny) + Dy*(Uz*Nx-Ux*Nz) + Dz*(Ux*Ny-Uy*Nx)));
44
45 Nkqbins : kqaccum(kqnaz(0)); { Number of bins for one elevation }