Showing posts with label environment. Show all posts
Showing posts with label environment. Show all posts

Wednesday, May 2, 2012

Rayleigh scattering and Mie scattering in Maya


Rayleigh scattering and Mie scattering are the main reasons why the sky is blue and the fog is white.
Depending upon the size of the particles that the sun ray hits, the color and the directionality of the scattering vary.
If the particles are as tiny as air molecules and therefore smaller than the wavelength of the sun ray, the sun ray is scattered into every direction. In this case, the shorter wavelengths like blue and violet start to scatter first. That's why the sky is blue. But when the sun is low in altitude and has to travel the thicker atmosphere, virtually all the blue is scattered already and the remaining red is also scattered. That's why the sunset sky turns red. Therefore, the behavior is spectrally selective.
In contrast, Mie scattering occurs for larger particles like water droplets. In this case, the scattering is directional and not spectrally selective. so Mie scattering creates mainly white color and tend to look like a halo around the sun or the light sources.


These two natural phenomena are implemented in Maya's physical fog.
Here's a render of a terrain with no atmospheric effect at all.


No matter how gigantic the terrain, it's hard to feel the magnitude of it.
I'll add an environment fog node to the scene. By default the environment node resides in the Maya software render settings, under render options
Once you create the node, mental ray will respect it in rendering




When the Physical type is set to Sky, this works as the combination of Rayleigh and Mie scattering.
Fog is Mie and Air is Rayleigh. You can control both individually.
First, I turn off the Fog by setting the Fog Density to zero. With the Air only, below is the result.
It clearly show the blue sky only.


Not only you can see the sky but also the blue-tinted faraway terrain around the horizon.
This is what's called aerial perspective (or atmospheric perspective). This is one of the essential elements that makes the outdoor scenery looks realistic and natural.


Now I turn on the Fog by raising the fog density.



with the addition of the fog, the terrain near the horizon becomes more desaturated.
Since the fog is sensitive to the direction of the sun, there are controls for the sun's position.



At the Sun Azimuth of zero, the sun is in line with the Z axis. Since the current camera is pointing the Z-direction, the following adjustment will reveal the sun.
I adjust the Fog Light Scatter attribute to a lower value like 0.2. This gives the fog scattering more directionality. ( higher value makes the scattering more uniform )


Here's the result. You can see the white halo forming around the sun.



If you use a very small number like 0.01 for the Fog Light Scatter, you may get a sun like shape like below.





This is an extreme case of back-lit fog.


In conclusion, you may want to use the Mental ray's physical sun and sky for the environment solution but it lacks atmospheric effects such as aerial perspective. On the other hand, Maya's physical fog is not an illumination source like MR's physical sun and sky. So these two features are complementary to each other.


 

Do not scale the camera!


There are cases where you shouldn't scale the camera, otherwise you will get artifacts or poor performance.

Case 1:  When you use a mia_env_blur node  to provide with a blurry reflection to a mia material.


This is a highly reflective metal material. I use the mia_envBlur to apply the blurry reflection like the following.

  
And then I scale up the camera by 5 times.


You'll get this pinching point like artifact.
This time, I will scale the camera down by 5 times ( 0.2 ).


Another weird artifact.
So, don't scale up or down your camera when you use mia_envBlur for blurry reflections.
It doesn't matter how much. As soon as you begin changing the scale it will go bad.



Case2:  When you use Optimize for Animations FG mode with View option on.



This time, I use the FG to create this.


I use Optimize for Animation mode with View option on. It gives me a fairly even FG point distribution like below.


So far, so good. But if I scale up the camera, let's say by 10 times.
The FG brightness diminishes by around that much like below.



This has to do with the fact that the View mode uses the camera space to deal with FG points and density. You can compensate the brightness by scaling up the Min/Max pixel value by the same scaling factor that's applied to the camera.

That being said, I'd rather not use a scaled camera.
 

Tuesday, May 1, 2012

lat-long style Environment map creation



 
Rendered using Vue xStream

E-on software's Vue is one good solution for the realistic natural environment creation. I do like the atmosphere and the sky it generates.

If you render the environment in Vue in lat-long style and use it for IBL in Maya, it can be a very efficient environment setup.  Vue provides with an option to export the sky in lat-long style but takes very long time to render since it only utilizes a single cpu thread for this particular task.

So, what I usually do is to create the sky in Maya using the xStream plug-in and render within Maya.
If a panoramic lens shader like latlong_lens shader is available, it will make your life a bit easier. But, if not, you can still render 6 images in cubemap style and transform them into a lat-long format.



Here's the result of the lat-long lens shader. It can directly create spherical type (lat-long) panoramic image from one single camera.


The only problem it has is this shader is not always available, especially for a newly released Maya.
If that is the case, you need to turn to the traditional cubemap method which requires 6 images-top, bottom, front, back, left and right.



You can use one camera and rotate it like above image or can use 6 cameras.
I prefer the latter. 



Here's my camera rig. Note that the naming convention has to be like that.



Each camera must cover exact 90 degrees of field of view in square frame.

Here's the render settings.

 Don't forget to set the framebuffer to 32bit float.


Now, batch render it.







I will stitch these 6 images into one cross-type cubic environment map.
To do this, I use an application called "cube2cross.exe". This takes 6 hdr format images to generate one big cross type hdr map.


I load this in HDRshop.


Using the settings above, I transform the cross type map into lat-long type env map.


This transformed result is basically identical to the one that's rendered through the lat-long lens shader.
Both methods take advantage of using full cpu threads.


The hdr image is now loaded in Maya's IBL. Now it takes virtually no time to render the environment.




Tuesday, April 24, 2012

Optimizing the portal light.

Traditionally, to simulate the illumination that comes through the window, area lights are placed in the window. This method is enhanced by using portal light which obtains its intensity and color from the environment outside the window.
The portal light helps in a great deal reducing Final Gathering's noise and since it's a light source it can cast shadow.


 
 Here's a scene with a room. I have set up an area lights for each window and a portal light is connected to each light.



 This is the spherical environment texture used for IBL as a primary environment for Mental ray in HDR format. It's a very high resolution texture. ( 6250x3125)
Using the default setting, this is the initial render result.