4
\$\begingroup\$

I'm attempting to achieve slightly more realistic ambient lighting in outdoor scenes using the sky cubemap.

When rendering an object, I first calculate the direct lighting contribution using standard phong diffuse and specular shading from each light source. In outdoor scenes, this is usually a directional light used to model light from the sun.

I then add in the indirect diffuse lighting contribution by sampling a high mip level of the sky cubemap at the normal to the surface. However, it recently occurred to me that, since my sky cubemaps contain the sun, I am actually including the contribution from the sun twice! I'm introducing a directional light to model the sun in the direct lighting stage, then introducing further lighting from the skybox itself.

My question is this: Should I modify my sky cubemaps so that they don't include the sun, or should I just remove the directional light instead?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Does the sunlight cast shadows? \$\endgroup\$
    – GuyRT
    Jun 16, 2014 at 13:25
  • \$\begingroup\$ Yes, the directional light casts shadows. The sky doesn't though, unless you count ambient occlusion. \$\endgroup\$
    – a5681419
    Jun 16, 2014 at 18:01
  • 2
    \$\begingroup\$ It all depends what you're trying to achieve - if you're only sampling the cubemap in the direction of the surface normal, you're not really getting a diffuse component. It'll be more of a reverse-active-camo effect. To model true diffuse, you need to sample and integrate the hemisphere about the normal. If you're talking specular, then you want to sample at the camera vector reflected by the tangent plane. Either way, it won't really matter whether you remove the sun from the cubemap since the sun's luminance magnitude is usually much higher than the rest of the sky. \$\endgroup\$
    – MooseBoys
    Jun 17, 2014 at 7:57
  • 1
    \$\begingroup\$ "if you're only sampling the cubemap in the direction of the surface normal, you're not really getting a diffuse component. It'll be more of a reverse-active-camo effect. To model true diffuse, you need to sample and integrate the hemisphere about the normal." I could be wrong, but isn't sampling at a lower mip level basically doing that? \$\endgroup\$
    – a5681419
    Jun 17, 2014 at 17:22

1 Answer 1

2
\$\begingroup\$

MooseBoys is right when he says

integrate the hemisphere about the normal

And to some extend you are also right when you say that a low mipmap is doing that, but not 100% mathematically correct.

What you need to have physically speaking, is a convolution with a cosine lobe in linear space. What you get with the mipmap sampling, is a convolution with a box window in gamma space.

Now, iI'm not saying it will give completely different results, its a good way to approximate the physically accurate model, with hardware support and ease of implementation ! You can keep it this way if you want. If you want super crazy physically correct precision, then I suggest you download AMD CubeMapGen modified by Sebastien Lagarde, and check the GUI box "irradiance", then you can export the result as .dds and instead of sampling the mipmap you can sample the irradiance map.

Now, you need to take the Sun OFF your skycube before you generate the irradiance map, because you WILL, like you feared, apply the sun 2 times !
To do that, just down-tone the sun corolla area to a brightness that has similar values with the surrounding (e.g. manually with Gimp). Its enough. Physically speaking, a sun as a directional light should get values of about 20/25, with an exposure of 1, it would simply saturate everything in an SDR renderer. If you have a range-compressor tonemapper you could get away with this kind of values. If you have an SDR renderer, you want to pre-tone-map manually the intensity of your directional light, to something near 1 so that you don't saturate things. But in that case, the contribution from your irradiance map will be unusually high, it would make sense to premultiply it with the same down-tone filter after its baked by cubemapgen. (again, in a full HDR pipeline, you care not about those things, its handled in real time).

EDIT: Here is the values we find in a classic HDR sky map:
http://oi60.tinypic.com/14smys3.jpg

\$\endgroup\$
2
  • \$\begingroup\$ For a much faster alternative to CubeMapGen, see cmft - cubemap filtering tool \$\endgroup\$
    – msell
    Oct 9, 2014 at 5:03
  • \$\begingroup\$ nice. its actually still slow if I refer to the perf charts. but very good links for people who are building their pipeline. the modified cubemap gen uses spherical harmonics to filter the map therefore beats cmft. (multiplication in frequency space is equivalent to convolution in dimensional space, but much faster) \$\endgroup\$
    – v.oddou
    Oct 9, 2014 at 5:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .