     vec3 wiW_sun = sampleSunDir(rnd);
     float sunPdf = 1.0; // convenient to decouple total sun power from its angular size
     float sunWeight = sunPower * sunPdf;
-
     float skyPdf;
     vec3 wiW_sky = sampleSphere(rnd, skyPdf);
     float skyWeight = skyPower * skyPdf;
-
     float sunProb = clamp(max(sunWeight, DENOM_TOLERANCE) / max(skyWeight+sunWeight, DENOM_TOLERANCE), 0.0, 1.0);
     bool chooseSun = (rand(rnd) <= sunProb);
     if (chooseSun)


#endif // HAS_GEOMETRY

////////////////////////////////////////////////////////////////////////////////
// Light sampling
////////////////////////////////////////////////////////////////////////////////

vec3 environmentRadianceXYZ(in vec3 dir)
{
    float phi = atan(dir.x, dir.z) + M_PI + M_PI*envMapRotation/180.0;
    phi -= 2.0*M_PI*floor(phi/(2.0*M_PI)); // wrap phi to [0, 2*pi]
    float theta = acos(dir.y);             // theta in [0, pi]
    float u = phi/(2.0*M_PI);
    float v = theta/M_PI;
    vec3 XYZ;
    if (haveEnvMap)
    {
        vec3 RGB = texture(envMap, vec2(u,v)).rgb;
        RGB *= skyPower;
        XYZ = rgbToXyz(RGB);
    }
    else
    {
        XYZ = skyPower * vec3(1.0);
    }
    return XYZ;
}

float environmentRadiance(in vec3 dir, in vec3 XYZ)
{
    vec3 XYZ_sky = environmentRadianceXYZ(dir);
    vec3 XYZ_spec = xyz_to_spectrum(XYZ_sky); // convert to radiance at the given wavelength
    return dot(XYZ, XYZ_spec);
}



        // If ray was absorbed by the volume, terminate
        if (absorb) break;
        if (volHits == __MAX_SCATTERS__) hit = false;
#endif // HAS_VOLUME

        // If this ray didn't scatter and missed all geometry, add environment light term and terminate path
