Saturday, April 14, 2012

mia_physicalsky and haze


A while ago I learned from one of "Zaps Mentalray Tips" that the mia_physicalsky haze parameter could be used to make clouds in the sky by connecting a file texture to it. Since then I have experimented with this technique and discovered some limitations and some solutions to those limitations.
sky_hazeWithVisDist_mentalrayTexture.jpg

I am assuming that you already know how to set up the mia_physicalsky environment. In my examples I am using the mia_photographic tone mapper in place of the default mia_exposure_simple. I have set the rgb_unit_conversion to 0.318 so we get the correct brightness for mia_photographic. I set the horizon height to -3 and the horizon blur to 1 so it looks like we are way above the ground. I made the ground color a bit blue instead of the default grey.
mia_physicalskyAE1.jpg
With no haze mapping I get this
sky_start.jpg
Next I found an image of some clouds (small version shown here)
clouds.jpg
I loaded this image into a standard maya fileTexture node (with the usual place2dTexture node) and used the luminance value of the image to control the haze parameter of mia_physicalsky. The following image shows the hypershade connections.
hypershade_fileTexture01.jpg
I used a multiplyDivide node so that I could multiply the luminance (in this case by a factor of 9) to control the density of the clouds. Here is the result
sky_hazeClouds_mayaFileTexture.jpg
Notice how I have not used any projection nodes like envSphere or mib_lookup_spherical. In fact when you hook up the fileTexture as I have shown here, the mia_physicalsky treats it as if it is mapped onto a hemisphere with the bottom of the fileTexture at the horizon and the top pinched in at the zenith.
If my cloud image map was a nice 360 degree panoramic one it would be perfect. But it is not. So to get it to fit nicely in the camera view I used the place2dTexture repeatUV and offset parameters (with a bit of trial and error to find the correct values).
So now I have clouds in the sky, but I also want the athmosphere to reduce the visibility of the distant objects. This can be achieved using the visibility distance parameter in mia_physicalsky (which requires that mia_physicalsky is used as a lens shader as well as the usual environment shader).
Here is a render with visibility distance = 100
sky_hazeWithVisDist2_mayaFileTexture.jpg
It doesnt look too bad, but if you look carefully you will notice it added to the cloud reflections which is not what I want. If I lower the visibility distance the problem becomes more obvious.
sky_hazeWithVisDist_mayaFileTexture.jpg
One way to solve this problem is to create another mia_physicalsky node. The first one is used for the environment shader and has its visibility distance = 0. The second is used for the lens shader. In the lens shader mia_physicalsky the haze parameter is left unmapped and set to zero and has a visibility distance value to give the athmospheric effect you desire. Here is a snapshot of my 2nd mia_physicalsky attributes where I tweeked the look a bit. Remember it is only affecting the look of the visibility distance effect.
mia_physicalskyAE2.jpg
And here is the render
sky_hazeWithVisDist3_mayaFileTexture.jpg
As you can see there are no extra reflections. Its a good solution, but now the clouds are always behind my objects. The depth muting effect is just a simple color. I wanted to see if I could get the actual clouds to partially obscure the objects.
Here is what I came up with. Instead of using the maya fileTexture I switched to a mentalrayTexture node. But that meant I no longer had the place2dTexture node for positioning my image. Well it turns out you can do the same thing with a few extra mentalray nodes.
Here is the hypershade network
mib_texture_filter_lookup.jpg
And here are the attribute editor snapshots of each node
mib_texture_filter_lookup_AE.jpg
mib_texture_vector_AE.jpg
mentalrayTexture_AE.jpg
mib_texture_remap_AE.jpg
The important one is the mib_texture_remap (shown above) where I have highlighted in orange the parameters that behave like the ones in the maya place2dTexture node. These are the numbers you change to reposition the file texture within the sky sphere.
So if I put all that together I get a network like this
hazeSetup_hypershade.jpg
I have used 2 different outputs from the multiplyDivide node to connect my cloud luminance to the haze of both mia_physicalskys so that I can control the density of the lens shader clouds independantly of the environment shader.
Here is a render
sky_hazeWithVisDist_mentalrayTexture2.jpg
I'm not getting the exagerated reflections that I got with the maya fileTexture and the clouds partially obscure the objects - but it is not very convincing! I guess this is a limitation of using the haze parameter for clouds and it is not a replacement for true volumetric clouds.
After a bit more tweeking I settled for this
sky_hazeWithVisDist_mentalrayTexture.jpg
The effect of the lens shader clouds is subtle, but I think that I would use this technique in a scene with objects fading off into the distance.
If you want a look at my set up you can download this example scene and the cloud image map I used.
BY david | mentalray

No comments:

Post a Comment