Procedural rainbow

Started by bigben, July 26, 2012, 05:45:41 PM

Previous topic - Next topic

bigben

Got sick of my little test renders so it was time to zoom out and take a look at a bigger render.  Nothing fancy with some random rocks thrown in.  I'm getting pretty happy with this, just a little more tweaking of the secondary rainbow and some odd lightening between the rainbow on the right hand side.  There should be nothing between the rainbows based on the mask values. It may not be too much of an issue as the model will still need to be included in a cloud that is simulating the rain, whereas here there is no "rain" around the rainbow.

Detail 0.75, AA8, render time 8hrs

FrankB

The rainbow looks good! How does it work, in principle?

Frank

bigben

#2
Hi Frank.

Just solved another part of the puzzle, which will help explain how it works...
The lightened area on the right I complained about is actually the darkened rainbow obscuring the cloud behind so rather than looking at my mask I should have been looking at the cloud settings.
[attach=1]

So on to how it "works"

The lighting effect is created by setting the cloud colour to a primary or secondary colour and then increasing the colour number to something extremely high (the latter restricts this to using only white, red, green, blue, cyan, magenta and yellow). In conjunction with this, you need to use a very low cloud density, with a balance between the colour value and cloud density controlling the brightness. The other key setting is turn GI on the cloud off.
[attach=2][attach=3]

The intensity of the rendered colour then depends on the amount of light striking the cloud. When there is no light, there is no colour, just a "blank" cloud.  With a very low density then, take away the colour and the cloud practically disappears which is what a rainbow is supposed to do.

The rainbow then, is made up of 7 cloud layers, using all of the available colours, with masks to control the distribution and overlaps to mix the colours. 

The masks use some simple trigonometry. I create a vector from the camera pointing in the opposite direction of the sun and a vector from the camera to get(position) and calculate the angle between the two vectors. Colour adjust shaders set the boundaries using the desired angles in degrees which removes a lot of the brain strain.  So you effectively have a conical mask with the camera at the apex.  The good thing about this is that the rainbow is always at a realistic position and can be animated quite easily as you only have to enter the altitude and heading of the sun.

There are a few other complications with limiting the depth of the rainbow and maintaining an adequate minimum density for smooth gradation of colour across the rainbow, but that's the crux of it.  There is an earlier TGD you can explore in this post:
http://www.planetside.co.uk/forums/index.php?topic=14805.msg144346#msg144346

FrankB

Ingenious! Thank you for the extensive explanation, much appreciated!

best regards
Frank

TheBadger

Very vivid! I am looking forward to seeing you use it in an image you planned for a rainbow from the start.
It has been eaten.

mogn

If only TG2 had  blue node "convert HSL to RGB" you could build your gradient, by converting the 40-42 range
to 0..360, keeping the Saturation and Lightning constant.
I could make the converting, but even a simple task of extraction x, y or z from a vertor given an index 0, 1 or 2,
takes nine nodes (I always deny to use conditionals).