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

File Contents

# Content
1 { RCSid $Id: reinhartb.cal,v 2.6 2015/03/27 18:58:06 greg Exp $ }
2 {
3 Compute Reinhart high-density sky patch bin (rbin)
4
5 RHS - right-handed system?
6 JTR - bin jitter/mixing amount
7 MF - Subdivision value (usually a power of two)
8 Dx,Dy,Dz - Incident direction (normalized, towards surface face)
9 rNx,rNy,rNz - Surface normal (normalized, away from surface)
10 Ux,Uy,Uz - Up direction vector (does not need to be normalized)
11
12 Modified from reinhart.cal
13
14 July 2014 G. Ward
15 }
16 { Useful factors and functions }
17 DEGREE` : PI/180;
18 mod`(n,d) : n - floor(n/d)*d;
19 Asin(x) : if(x-1, PI/2, if(-1-x, -PI/2, asin(x))) / DEGREE;
20 Atan2(y,x) : mod( atan2(y,x)/DEGREE, 360);
21
22 { Default to Tregenza sky }
23 MF = 1;
24 { Set to -1 for left-handed coordinate system }
25 RHS = 1;
26 { Sharp bin boundaries by default }
27 JTR = 0;
28 { Default axis orientation (+Y == north) }
29 rNx = 0; rNy = 0; rNz = -1;
30 Ux = 0; Uy = 1; Uz = 0;
31 { Compute oriented axis angles }
32 inc_dz = -Dx*rNx-Dy*rNy-Dz*rNz;
33 inc_rx = -RHS*(Dx*(Uy*rNz-Uz*rNy) + Dy*(Uz*rNx-Ux*rNz) + Dz*(Ux*rNy-Uy*rNx));
34 inc_ry = Dx*Ux+Dy*Uy+Dz*Uz + inc_dz*(rNx*Ux+rNy*Uy+rNz*Uz);
35
36 r_alt = Asin(inc_dz);
37 r_azi = Atan2(inc_rx,inc_ry);
38 { Number of patches per row }
39 tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);
40 TNR : tnaz(0);
41 rnaz(r) = if(r-(MF*TNR-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1));
42
43 alpha = 90/(MF*TNR + .5); { Separation between rows in degrees }
44
45 raccum(r) = if(r-.5, rnaz(r-1) + raccum(r-1), 0);
46 { Random perturbation for final bin # }
47 jtr1 = JTR*(.5 - rand(1.958*Dx - 5.386*Dy - 3.772*Dz));
48 jtr2 = JTR*(.5 - rand(-6.334*Dx - 2.165*Dy + 7.953*Dz));
49
50 r_row0 = floor(r_alt/alpha);
51 r_row = if(JTR, min(max(0,floor(r_alt/alpha + jtr1)),MF*TNR), r_row0);
52
53 r_inc0 = 360/rnaz(r_row0);
54 r_inc = 360/rnaz(r_row);
55
56 r_adj = .5*r_inc + if(JTR, jtr2*min(r_inc,r_inc0), 0);
57
58 r_azn = floor( mod(r_azi+r_adj, 360) / r_inc );
59
60 { Final bin value, -1 for "ground" }
61 rbin = if(r_alt, raccum(r_row) + r_azn, -1);
62
63 Nrbins = raccum(MF*TNR+1); { total number of bins }