How can I calculate the direct sunlight contribution based on an HDR-based sky?

In previous topic " How can I obtain the sky vectors for a image based sky?", I was able to get the sky vectors with Greg’s help. However, I am wondering how to calculate the direct sunlight contribution. My initial thought was to extract the sun pixels from the sky HDR (as shown in Fig. 1) and map them into sky glow. However, when I used mksource to generate sources for direct calculation, no sources were generated.


Fig.1 extracted sun

my command:
oconv sky2025-01-02_1240.rad > sun2025-01-02_1240.oct
mksource -d 100000000 sun2025-01-02_1240.oct > sun.rad

The mksource command creates sources from bright areas in a captured sky. It is not meant to be applied to a generated sky, which has only the sun, and it is already labeled as a source.

I don’t know what is in your “sky2025-01-02_1240.rad” file, or what you are really hoping to accomplish. The position of the sun is known and produced in the gensky output.

-Greg

Hi Greg,

The sky2025-01-02_1240.rad is a image based sky that only includes the sun, which is shown as below:

void colorpict skyfunc
7 red green blue directSky/2025-01-02_1240.hdr angmap1.cal u v
0
0

skyfunc glow light_probe1 0 0 4 1 1 1 0
light_probe1 source ibl_environment1 0 0 4 0 -1 0 180

The file directSky/2025-01-02_1240.hdr is shown in Fig.1.

I want to calculate the direct sunlight contribution jusk like what is done in five-phase method, the difference is that I use rpict to calcuate it rather than rcontrib.

OK, that makes more sense now that I understand this is in fact a mapped sky.

Your calculation should produce a source for the sun at least. I am not sure what is going wrong, though this is rather an extreme input for a tool that was only tested on natural environment captures.

Can you send me your HDR image? I would like to test this, myself. (I can probably regenerate the image if that is too difficult to send.)

Best,
-Greg

I tried mksource using an image I generated, and it did produce a light source, although it seemed to underestimate the intensitt of the sun by a factor of 2 or so.

I noticed a potential bug on 32-bit machines for the -d setting you used, which I fixed and updated on CVS. The new binaries should be created sometime this weekend from that if you want to give that a try to see if it helps.

I am still not sure that your mapping of the sky is correct – where did you get your formula?

Cheers,
-Greg

Hi Greg,

Thanks for your help!

I upload my HDR image here 2025-01-02_1240.hdr - Google Drive.

My formula for the mapping of sky derived from Paul Debevec’s paper “Image Based Lighting”. However, I have modified it into -Y axis. It seems that it’a a Equi-angular projection.

Well, it’s not actually an equi-angular projection, whose angle is proportional to the distance from the image center. The formula you have is for a light probe, whose angle is twice the arcsin of the distance to the center, I think.

In any case, did you wait for mksource to finish in your initial test? Because my run is still going after 24 hours, on an admittedly slow laptop, but still. I think the -d setting is excessive, and maybe yours just never finished. You may be able to get by with -d 500000 or so, instead. You are trying to see a very small source, admittedly.

I would recomend switching to 180° fisheye captures and the “fisheye.cal” file included with Radiance (below) if you are rendering with the -vta option.

Cheers,
-Greg

{
	Calculate coordinates for a 180 degree fisheye lens.
	Assume view direction is (0,1,0), view up (0,0,1), (1,0,0) right.

	4/30/90
}

fish_Rxz = sqrt(Dx*Dx + Dz*Dz);
fish_Ry = Acos(Dy) / PI;

fish_u = .5 + Dx/fish_Rxz * fish_Ry;
fish_v = .5 + Dz/fish_Rxz * fish_Ry;

Hi Greg,

The modified formula I used is the same with the formula in fisheye.cal.

{
angmap1.cal
Convert from directions in the world \
(Dx, Dy, Dz) into (u,v) \

}

d = sqrt(Dx*Dx + Dz*Dz);

r = if(d, 2*0.159154943*acos(-Dy)/d,0); // 2*0.159154943=1/pi
u = 0.5 - Dx * r;
v = 0.5 + Dz * r;

I also test the fisheye.cal and found the rendering result is the same with my previous.

void colorpict skyfunc
9 red green blue directSky/2025-01-02_1240.hdr fisheye.cal fish_u fish_v -rz 180
0
0

skyfunc glow light_probe1 0 0 4 1 1 1 0
light_probe1 source ibl_environment1 0 0 4 0 -1 0 180

Regarding the mksource, I used -d 500000, it still cannot predouce any source, but the run is finished.
image

However, I think there may be a method that doesn’t use mksource to produce the source, my solution is:

  1. calculating the illuminance of the sky hdr.

  2. Calculating the projected solid angle of the sun


    .

  3. Obtaining the position of the sun in the HDR image and the radiance

  4. Calculating the altitude and amuzith value of the sun
    θ = arctan [(581-400)/(408-400)]=87.46923698°
    φ = ((581-400)^2+(408-400)^2 )^0.5/400 * (pi/2) * 180/pi = 40.76476°
    vectors X = (sinφcosθ, sinφsinθ,cosφ) = (0.028831736, 0.652318028, 0.757396806)

  5. since the center of the image is expected to -Y, X should be rotate 90° round the X axis, then X’ = (-0.028831736, -0.757396806, 0.652318028), the sun vectors should be (-0.028831736, -0.757396806, 0.652318028).

  6. Calculating the luminance of the sun, L = Ev/Ω/179=13135.194/0.00114432/179=64126.27

  7. Calculating the solid angle of the sun


    0.00149208 sr euquals to 2.5° of apex angle
    Finally, the source can be written as:

void light solar
0
0
3 64126 64126  64126 

solar source sun2
0
0
4 -0.028831736 -0.757396806 0.652318028 2.50