Rainbow

Started by bigben, February 26, 2008, 06:50:49 PM

Previous topic - Next topic

bigben

Hi All

I've been a bit busy lately but I've managed to still do a bit with TG. While having a break from sorting out my displacements for 90m SRTM terrains I've been working on a rainbow "model". I've actually had two models in mind. I started with my second idea as it was the simplest to construct but it didn't work  :(  I have my suspicions as to why (possibly a glitch with get camera that I experienced withmy population masking tests) so I'll revisit this next.

The image below is a proof of concept of my first model. The rainbow is deliberately too wide... that will be addressed later.  The result is very encouraging as the variation in lighting is really nice. 

The final model will consist of 4 duplicate cloud nodes (1 for rain, 3 for the rainbow), a single cloud density shader and four masks. If I get my second model working, it will provide realistic rainbow placement for animations where a cloud layer is used to simulate falling rain (or flying above clouds). The only thing it won't be able to handle accurately is losing the rainbow in the shadow of a cloud, but other than that it has a lot of potential. It can easily be expanded to produce a complete rainbow as well as sun dogs with a little tweaking.

monks

Very cool! It'd be interesting to see how this will look with all the bells and whistles on- could be sublime!

monks

dhavalmistry

cool bigben....is this all procedural??...based on your explanation...my guess is it IS procedural, but would like more explanation on this one...looks promising...keep up....
"His blood-terragen level is 99.99%...he is definitely drunk on Terragen!"

rcallicotte

So this is Disney World.  Can we live here?

bigben

#4
Both models are entirely procedural. This example is a relatively crude model and requires some manual hacking of settings to position accurately.

The second model I was working on might require a single hack as a workaround to a specific problem, but this may be remedied with the next update. The second model will be nerdishly accurate.

Construction of this model:
The basis of this model is a spherical gradient from 0-1 at a set distance from a specified point with a fixed width. The sphere is then sliced perepndicular to the camera to produce a torus-like shape (I used my terrain blending mask, but a couple of distance shaders would have done the trick)

This is then fed into 5 colour adjust shaders, 1 for each change in RGB values to make up the spectrum (2 red, 2 green, 1 blue). These are then combined to make 3 shaders representing the RGB values of the rainbow.

An additional colour adjust node sets the entire width of the rainbow to 1. This is used as a blending shader for the cloud density shader. The density shader is then fed into 3 surface shaders (as a child), using the R,G,B shaders above as blending shaders.

A cloud layer is then created for the rain and duplicated. In this case I just have the rainbow without additional rain, so there are 3 cloud layers. The colour of the cloud layers are set to red, green and blue, using the corresponding surface shader as a density fractal.

[attachthumb=#1]

This shows you the construction of this model. No rocket science here, just some crude (but creative) masking  ;)

The bottom 2/3 (what to do with the 0-1 gradient) of this is pretty much sorted  and is common to both models. There are a couple of extra bits left from previewing the result on the terrain as it's quicker to preview as a surface layer.

What's next

The second model will actually use the position of the sun to produce a conical mask spreading out from the camera. This will remove the need to manually position the centre of the sphere and then slice the sphere.

The rest is basically all thanks to the volumetric cloud model in TG2, and with some finetuning should produce some very realistic looking rainbows.

Both models should easily slip into an existing scene that uses clouds to simulate rainfall.

bigben

#5
Turns out I didn't have a clue what I was doing with the second model  ;)  Back on track now after a quick refresher course...  http://en.wikipedia.org/wiki/Dot_product

Here's the 0-1 gradient applied to a surface shader (now with the correct angles).  A second rainbow can be added by duplicating the network from the inclusion of the inner radius down. I'll construct the rest of the network next and from there the next thing to do will be to calculate the coordinates of a point opposite the sun using the camera position, sun heading and sun altittude.

At the moment this is manually calculated by turning the camera away from the sun, adding a sphere and then copying the coordinates of the sphere. Need a bit more refreshing of my math to find the simplest solution  ;) This will remove the need for any manual input for the rainbow!

I have a couple of higher quality renders of the first model still running including a close up of one end of the rainbow. Still on the pre-render  :-\

Matt

Quote from: bigben on February 26, 2008, 06:50:49 PM
The only thing it won't be able to handle accurately is losing the rainbow in the shadow of a cloud

If I understood your explanation correctly you're using 3 coloured clouds to simulate the red, green and blue parts of the rainbow. In that case it should darken automatically when it falls into shadow. The only problem is that it's also illuminated by other lights, not just the sunlight. If the only lights in the scene are a single Sunlight and Enviro Light, then all you need to is tell the rainbow clouds not to respond to Enviro Light. In the cloud layer's lighting tab you could set "Enviro light" to 0.

Matt
Just because milk is white doesn't mean that clouds are made of milk.

ghotir

Quote from: Matt on February 27, 2008, 08:16:12 AM

If I understood your explanation correctly you're using 3 coloured clouds to simulate the red, green and blue parts of the rainbow. In that case it should darken automatically...

Then wouldn't he have dark clouds instead of colored clouds.  It needs to go transparent when it is shadow.  That is what rainbows do. 


bigben

#8
Yes the rainbow will darken when in shadow but it should disappear. How much it darkens will remain to be seen but any darkening will help to keep it looking realistic. Having envirolight settings for individual cloud nodess as you mentioned has been very handy and should help a bit.

Adding a secondary rainbow and Alexander's band (http://en.wikipedia.org/wiki/Alexander%27s_band) which will help to make it loook even more realistic. I've also been tossing up whether to slightly lighten the first few degrees inside the primary rainbow.

bigben

#9
The high quality renders of v1 are finally onto the rainbow. I'll post partial renders when there's enough to see.  I found a typo on one of the shaders which affected the red.

Below is a preview render of a double rainbow (another productive train ride to work, and as luck would have it there was a double rainbow outside for reference :) ). The combined RGB channels from the rainbow masks were simply added to a build colour node and applied to the terrain.

I had to reorder the masking sequence a bit as the existing sequence resulted in the area outside of the rainbow being purple which is OK when your masking a single rainbow, but screws things up when you add two rainbows together.

The even widths of the colour bands didn't look natural. Looking at the reference images the red end of the spectrum has wider bands. Rather than recalculate new values for the gradient values I simply added a colour adjust to the initial 0-1 gradient and then adjusted the gamma.  I also have to widen the violet band a little. Once I get the rainbow looking nice I'll recalculate the gradient steps for a minor efficiency improvement.

The secondary rainbow uses a separate set of colour adjust shaders to create the RGB gradients, with the black and white values being reversed from the primary rainbow (1 - primary value). Each channel is then multiplied by a darkening factor (0.3 in this image) to reduce its intensity.

I'll construct the extra bells and whistles tonight and then review the masking to try and find the simplest method. This will be a good test for boolean nodes ;)

The render times are long, but not as long as I had expected from some of my earlier cloud masking tests and it looks really cool which more than makes up for it. I will share the TGD eventually but I would at least like the chance to get one good image out of it first ;)

bigben

Here's a partial render of the end of the rainbow. The gap where yellow should be is the result of the typo I made. but the way the intensity changes depending on the background is sweeeeet.

The fall off at the red edge is partly due to the fact that I've used a rectangular mask to slice the rainbow, resulting in less cloud being visible at the edges. With the second model this isn't be a problem as the mask is projected radially from the camera.

Cyber-Angel

The only thing I'd say is that in nature the inner secondary bow tends to be much fainter than the primary outer bow and you are correct in your image of you secondary bow that the colors are reversed: nice experiments.  ;D

Regards to you.

Cyber-Angel     

bigben

I agree that it should be fainter. Luckily I built in a tweaking mechanism via a constant scalar. This could also be used to fade in the secondary rainbow during an animation...

There will also be a need to restrict the thickness of the rainbow with a distance shader (from the camera) or the build up over distance will result in a fairly solid rainbow.

The other bells and whistles tat I'll be adding will be a lightening of the rain inside the primary and outside the secondary rainbows, a darkening between the primary and secondary rainbow, and perhaps a single supernumerary.

Matt

Quote from: ghotir on February 27, 2008, 10:37:51 AM
Then wouldn't he have dark clouds instead of colored clouds.  It needs to go transparent when it is shadow.  That is what rainbows do. 

Ah... true. The cloud would need to be rendered additively for that to work. But an interesting trick you might try is to make the RGB colours much brighter and reduce the density. For example use a colour intensity of 100, and then divide your current density value by 100. That will make it almost entirely additive 8)  If that's not enough to make the shadowed regions invisible, use a larger factor.
Just because milk is white doesn't mean that clouds are made of milk.

Oshyan

#14
I just want to say this is really cool and the results are surprisingly good. Go Ben! :)

- Oshyan