| 66 |
|
The following forumulas compute Shirley-Chiu bin "scbin" based on: |
| 67 |
|
|
| 68 |
|
RHS - right-handed system (-1 for left-handed coords) |
| 69 |
+ |
JTR - bin jitter/mixing amount (0 for sharp boundaries) |
| 70 |
|
Dx,Dy,Dz - Incident direction (normalized, towards surface front) |
| 71 |
|
rNx,rNy,rNz - Surface normal (normalized, away from surface) |
| 72 |
|
Ux,Uy,Uz - Up direction vector (does not need to be normalized) |
| 75 |
|
ordered with the "up" direction changing fastest. |
| 76 |
|
} |
| 77 |
|
RHS = 1; |
| 78 |
+ |
JTR = 0; |
| 79 |
|
{ Compute oriented axis values } |
| 80 |
|
inc_dz = -Dx*rNx-Dy*rNy-Dz*rNz; |
| 81 |
|
inc_rx = -RHS*(Dx*(Uy*rNz-Uz*rNy) + Dy*(Uz*rNx-Ux*rNz) + Dz*(Ux*rNy-Uy*rNx)); |
| 85 |
|
{ Pass to formulas in first section } |
| 86 |
|
in_disk_x = inc_rx*inc_radf; |
| 87 |
|
in_disk_y = -inc_ry*inc_radf; |
| 88 |
+ |
{ Random perturbation for final bin # } |
| 89 |
+ |
jtr1 = JTR*(.5 - rand(1.958*Dx - 5.386*Dy - 3.772*Dz)); |
| 90 |
+ |
jtr2 = JTR*(.5 - rand(-6.334*Dx - 2.165*Dy + 7.953*Dz)); |
| 91 |
+ |
|
| 92 |
+ |
yndx = if(JTR, min(max(0,floor(out_square_x*SCdim + jtr1)),SCdim-1), |
| 93 |
+ |
floor(out_square_x*SCdim)); |
| 94 |
+ |
xndx = if(JTR, min(max(0,floor(out_square_y*SCdim + jtr2)),SCdim-1), |
| 95 |
+ |
floor(out_square_y*SCdim)); |
| 96 |
|
{ Compute final bin (-1 if behind surface) } |
| 97 |
< |
scbin = if(inc_dz, |
| 88 |
< |
floor(out_square_x*SCdim)*SCdim + floor(out_square_y*SCdim), |
| 89 |
< |
-1); |
| 97 |
> |
scbin = if(inc_dz, yndx*SCdim + xndx, -1); |