## Angle from a reference vector

Started by bigben, July 10, 2017, 10:46:58 pm

#### bigben

##### July 10, 2017, 10:46:58 pmLast Edit: July 10, 2017, 11:18:13 pm by bigben
Here's a function I use for creating masks at specific angles around a reference vector by comparing it with a vector from a reference point to get(position).  The output is in degrees to make it easier to work with.

Reference point: e.g. the location of the render camera or the center of an object/planet
Reference vector: Line between 2 points or derived from the heading/altitude of an object/light e.g. the position of the sun.

To create a mask, just feed it into a colour adjust node and set the black and white levels to the required angles.
For example I'm currently using it to mask a spherical image map used for simulating city lights on the Earth. Reference point is the centre of the planet, reference vector is derived from the position of the sun (I negate it for simplicity).  This allows the lights to be hidden on the daylight side as a mask and fading in the lights towards the night side of the planet by multiplying the mask with the luminance of the lights so that the lights start of dim and fade up to full intensity after 2-3 degrees.

Animation: The mask can be animated easily by duplicating the animation of the reference point/reference vector where applicable.  This is easy when the camera is the reference point as you just need a get(camera position) node

I've also included a clip to convert Heading/Altitude to a vector... e.g. to convert the sun's position to a vector for use in the above clip. They're both the same functionally. The TGD shows the basic usage of both combined.

#### Dune

##### July 11, 2017, 03:34:51 am #1
Higher level TG calculative work. Thanks a lot, Ben, this might come in handy one day.

#### bigben

##### July 11, 2017, 04:34:09 am #2 Last Edit: July 11, 2017, 04:38:05 am by bigben
It's the basis for my procedural rainbow test.
Import a rocket with Z-up and you can use X rotation for altitude, y-rotation for heading and have a conical mask extend out the back of the rocket... or constrain a dust cloud behind a moving object... fake spotlight beam using a cloud...  you never know when it'll come in handy

#### cyphyr

##### July 11, 2017, 05:15:51 am #3
Very useful indeed. I shall investigate later
www.richardfraser.co.uk
/|\

Ryzen 9 3900X @3.79Ghz, 64Gb (TG4 benchmark 6:20)
i7 5930K @3.5Ghz, 32Gb (TG4 benchmark 13.44)

#### bigben

##### July 11, 2017, 09:20:28 am #4
Eye ball with displaced lens using 2 spheres

#### Dune

Cool!

##### July 11, 2017, 09:40:38 am #6

Nice and thanks for sharing.

#### bobbystahr

##### July 12, 2017, 07:38:17 pm #7
thanks for the shares and cool technique on the eyeball. nice t have you posting again. I sense a learning curve in BobbyWorld.
something borrowed,
something Blue.
Ring out the Old.
Bring in the New
Bobby Stahr, Paracosmologist

#### bigben

##### July 12, 2017, 10:19:06 pm #8
Quite possibly Bobby...  refreshing my memory from my old notes, but my best notes are here in the forum.  Reading an old post and wishing I'd included an screengrab of this or that, or a clip... so I'll be posting a bit more detail for my own reference in future

#### bobbystahr

##### July 13, 2017, 01:22:09 am #9
Quote from: bigben on July 12, 2017, 10:19:06 pm
Quite possibly Bobby...  refreshing my memory from my old notes, but my best notes are here in the forum.  Reading an old post and wishing I'd included an screengrab of this or that, or a clip... so I'll be posting a bit more detail for my own reference in future

Forums are often the best archve.
something borrowed,
something Blue.
Ring out the Old.
Bring in the New
Bobby Stahr, Paracosmologist

#### luvsmuzik

##### July 13, 2017, 09:37:42 am #10
Hi. Thanks for this share! I have read many of your posts in the archives through the years. Joined the forum last year.

I tried this tgd hoping to get similar results but perhaps I did something wrong. Does this lighting effect work using the nebula and stars tgc? I did not change any values in the sun position or other nodes.
I added a higher atmo to the planet and masked that with a PF. I seem to be getting the reverse shading effect that you show here.
I tried changing the color adjust settings...many ways, and no luck there either.
I also tried the altitude node....getting a bright pink stripe on the planet...

I posted my results in image sharing:
http://www.planetside.co.uk/forums/index.php/topic,23363.msg236432.html#msg236432

#### bigben

##### July 13, 2017, 12:01:10 pm #11
Answered in your image post but I'll add a little here as well. Assuming the sun is in the same position as the clip and those settings don't need adjusting...

There are a few ways to reverse the mask if the mask seems to be affecting the wrong side.
2. Insert a Negate vector before the INPUT Reference vector
3. multiply the Heading and Altitude numbers by -1
4. Subtract the Black level and White level values from 180 in the final Colour Adjust node

Values for the colour adjust node range from 0 (pointing along the reference vector) to 180 (pointing in the opposite direction to the reference vector)

#### luvsmuzik

##### July 13, 2017, 12:38:35 pm #12
Quote from: bigben on July 13, 2017, 12:01:10 pm
Answered in your image post but I'll add a little here as well. Assuming the sun is in the same position as the clip and those settings don't need adjusted.

Thanks! Trying any and all...

#### Ariel DK

##### July 15, 2017, 12:42:00 pm #13
I almost missed this topic. as an idea, it's also useful for recreate the Ionosphere
Hmmm, what version of Terragen does God use?

#### bobbystahr

##### July 15, 2017, 01:24:11 pm #14
Quote from: Ariel DK on July 15, 2017, 12:42:00 pm
I almost missed this topic. as an idea, it's also useful for recreate the Ionosphere

Good find
something borrowed,
something Blue.
Ring out the Old.
Bring in the New
Bobby Stahr, Paracosmologist