Radiance-general digest, Vol 1 #22 - 2 msgs

Ron wrote:

I would like to recover the surface normals of the surfaces visible in
every pixel of a Radiance scene. In other words, I want to trace the
initial ray cast for each pixel, and find the surface normal of the first
surface that ray hits. I figured out that I could do this using rtrace
-on, if I feed rtrace the rays corresponding to each pixel in my
image. Is there an easy way to compute all of these rays automatically
using an existing Radiance program, or will I need to write a special .cal
file for rcalc? I have the feeling that some Radiance gurus could
accomplish this task in one or two lines.

vwrays.1 (3.73 KB)

vwrays.c (5.19 KB)

···

------------
There are two solutions to this problem. As you say, it is a very handy
thing to be able to do, so I wrote a C program to do just that. It is
part of the Unix distribution I've been working on and plan to release
as soon as I figure out how. In the meantime, I am attaching the C file
and manual page to this message, which are fairly short. The nice thing
about this solution is that it will work with any Radiance view type,
and will generate the exact rays corresponding to the center of each
pixel. (If you want an absolute guarantee that these correspond to
the pixels sampled with rpict, you will need to set the -pj 0 option
in your rendering.)

The second solution is to apply the following .cal script with rcalc,
which works only for perspective views, found in ray/lib/lib:

{
  proj.cal - calculate image projection vector
}
        { View Point }
VPx = 0; VPy = 0; VPz = 0;
        { View Up }
VUx = 0; VUy = 0; VUz = 1;
        { View Direction }
VDx = 0; VDy = 1; VDz = 0;
        { View Horizontal and Vertical angles }
VH = 45; VV = 45;
        { X and Y resolution }
X = 512; Y = 512;
        { Projected Direction (computed) }
PDx = NVDx + h*IHx + v*IVx;
PDy = NVDy + h*IHy + v*IVy;
PDz = NVDz + h*IHz + v*IVz;
h = x - (X-1)/2; v = y - (Y-1)/2;
        { Normalized View Direction }
NVDx = VDx/VDl; NVDy = VDy/VDl; NVDz = VDz/VDl;
VDl = sqrt(VDx*VDx + VDy*VDy + VDz*VDz);
        { Increment Horizontal }
IHx = IHF*NTIHx; IHy = IHF*NTIHy; IHz = IHF*NTIHz;
NTIHx = TIHx/TIHl; NTIHy = TIHy/TIHl; NTIHz = TIHz/TIHl;
TIHx = VDy*VUz-VDz*VUy; TIHy = VDz*VUx-VDx*VUz; TIHz = VDx*VUy-VDy*VUx;
TIHl = sqrt(TIHx*TIHx + TIHy*TIHy + TIHz*TIHz);
IHF = 2*tan(PI/180/2*VH)/X;
        { Increment Vertical }
IVx = IVF*(NTIHy*NVDz-NTIHz*NVDy);
IVy = IVF*(NTIHz*NVDx-NTIHx*NVDz);
IVz = IVF*(NTIHx*NVDy-NTIHy*NVDx);
IVF = 2*tan(PI/180/2*VV)/Y;

PI = 3.14159265358979323846

--------------
The horizontal and vertical increment vectors get added to a unit
direction vector to get the final view direction computed in PDx,
PDy, and PDz. The view point (origin) remains the same for a
perspective view. An example application of the above file with
a specific view origin, direction, and angle might be:

cnt 512 512 | rcalc -f proj.cal -e 'VPx=15.3;VPy=10.1;VPz=-3.3;' \
  -e 'VDx=.394;VDy=-.731;VDz=-.053;' \
  -e 'VH=30;VV=30;' -e '$1=VPx;$2=VPy;$3=VPz;' \
  -e '$4=PDx;$5=PDy;$6=PDz;' | rtrace [rtrace options]

Hope this helps.
-Greg