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 weeks, 3 days 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

# User Rev Content
1 greg 2.7 { RCSid $Id: reinhartb.cal,v 2.6 2015/03/27 18:58:06 greg Exp $ }
2 greg 2.1 {
3     Compute Reinhart high-density sky patch bin (rbin)
4    
5 greg 2.7 RHS - right-handed system?
6     JTR - bin jitter/mixing amount
7 greg 2.1 MF - Subdivision value (usually a power of two)
8     Dx,Dy,Dz - Incident direction (normalized, towards surface face)
9 greg 2.3 rNx,rNy,rNz - Surface normal (normalized, away from surface)
10 greg 2.1 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 greg 2.7 DEGREE` : PI/180;
18     mod`(n,d) : n - floor(n/d)*d;
19 greg 2.2 Asin(x) : if(x-1, PI/2, if(-1-x, -PI/2, asin(x))) / DEGREE;
20 greg 2.7 Atan2(y,x) : mod( atan2(y,x)/DEGREE, 360);
21 greg 2.1
22     { Default to Tregenza sky }
23     MF = 1;
24 greg 2.6 { Set to -1 for left-handed coordinate system }
25     RHS = 1;
26 greg 2.7 { Sharp bin boundaries by default }
27     JTR = 0;
28 greg 2.1 { Default axis orientation (+Y == north) }
29 greg 2.5 rNx = 0; rNy = 0; rNz = -1;
30 greg 2.1 Ux = 0; Uy = 1; Uz = 0;
31     { Compute oriented axis angles }
32 greg 2.3 inc_dz = -Dx*rNx-Dy*rNy-Dz*rNz;
33 greg 2.6 inc_rx = -RHS*(Dx*(Uy*rNz-Uz*rNy) + Dy*(Uz*rNx-Ux*rNz) + Dz*(Ux*rNy-Uy*rNx));
34 greg 2.5 inc_ry = Dx*Ux+Dy*Uy+Dz*Uz + inc_dz*(rNx*Ux+rNy*Uy+rNz*Uz);
35 greg 2.1
36 greg 2.4 r_alt = Asin(inc_dz);
37 greg 2.2 r_azi = Atan2(inc_rx,inc_ry);
38 greg 2.1 { Number of patches per row }
39     tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6);
40 greg 2.7 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 greg 2.1
45     raccum(r) = if(r-.5, rnaz(r-1) + raccum(r-1), 0);
46 greg 2.7 { 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 greg 2.1
50 greg 2.7 r_row0 = floor(r_alt/alpha);
51     r_row = if(JTR, min(max(0,floor(r_alt/alpha + jtr1)),MF*TNR), r_row0);
52 greg 2.1
53 greg 2.7 r_inc0 = 360/rnaz(r_row0);
54 greg 2.1 r_inc = 360/rnaz(r_row);
55    
56 greg 2.7 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 greg 2.1
60     { Final bin value, -1 for "ground" }
61 greg 2.7 rbin = if(r_alt, raccum(r_row) + r_azn, -1);
62 greg 2.1
63 greg 2.7 Nrbins = raccum(MF*TNR+1); { total number of bins }