Author Topic: Angle from a reference vector  (Read 1064 times)

Offline bigben

  • Member
  • *
  • Posts: 2129
  • The Long Stranger rides again
    • Tinkering with Terragen
Angle from a reference vector
« on: July 11, 2017, 02:46:58 AM »
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.
« Last Edit: July 11, 2017, 03:18:13 AM by bigben »

Offline Dune

  • Member
  • *
  • Posts: 12818
  • Corkscrew Bird
    • www.ulco-art.nl
Re: Angle from a reference vector
« Reply #1 on: July 11, 2017, 07:34:51 AM »
Higher level TG calculative work. Thanks a lot, Ben, this might come in handy one day.
In case you still haven't seen enough of my work: www.ulco-art.nl

Offline bigben

  • Member
  • *
  • Posts: 2129
  • The Long Stranger rides again
    • Tinkering with Terragen
Re: Angle from a reference vector
« Reply #2 on: July 11, 2017, 08:34:09 AM »
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 ;)

« Last Edit: July 11, 2017, 08:38:05 AM by bigben »

Offline cyphyr

  • Member
  • *
  • Posts: 3585
    • richardfraser
Re: Angle from a reference vector
« Reply #3 on: July 11, 2017, 09:15:51 AM »
Very useful indeed. I shall investigate later
www.richardfraser.co.uk
/|\

i7 5930 @3.5Ghz, 32Gb
i7 2600k @3.4Ghz, 16Gb
i7 980 @3.33Ghz, 16Gb

Offline bigben

  • Member
  • *
  • Posts: 2129
  • The Long Stranger rides again
    • Tinkering with Terragen
Re: Angle from a reference vector
« Reply #4 on: July 11, 2017, 01:20:28 PM »
Eye ball with displaced lens using 2 spheres  ;)

Offline Dune

  • Member
  • *
  • Posts: 12818
  • Corkscrew Bird
    • www.ulco-art.nl
Re: Angle from a reference vector
« Reply #5 on: July 11, 2017, 01:30:18 PM »
Cool!
In case you still haven't seen enough of my work: www.ulco-art.nl

Offline Kadri

  • Member
  • *
  • Posts: 7863
Re: Angle from a reference vector
« Reply #6 on: July 11, 2017, 01:40:38 PM »

Nice and thanks for sharing.

Offline bobbystahr

  • Member
  • *
  • Posts: 8200
  • Turn, and face the Strange Ch Ch Changes...D Bowie
Re: Angle from a reference vector
« Reply #7 on: July 12, 2017, 11:38:17 PM »
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

bobbystahr

Offline bigben

  • Member
  • *
  • Posts: 2129
  • The Long Stranger rides again
    • Tinkering with Terragen
Re: Angle from a reference vector
« Reply #8 on: July 13, 2017, 02:19:06 AM »
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 ;)

Offline bobbystahr

  • Member
  • *
  • Posts: 8200
  • Turn, and face the Strange Ch Ch Changes...D Bowie
Re: Angle from a reference vector
« Reply #9 on: July 13, 2017, 05:22:09 AM »
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

bobbystahr

Offline luvsmuzik

  • Member
  • *
  • Posts: 1592
Re: Angle from a reference vector
« Reply #10 on: July 13, 2017, 01:37:42 PM »
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

Offline bigben

  • Member
  • *
  • Posts: 2129
  • The Long Stranger rides again
    • Tinkering with Terragen
Re: Angle from a reference vector
« Reply #11 on: July 13, 2017, 04: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 adjusting...

There are a few ways to reverse the mask if the mask seems to be affecting the wrong side. 
1. In the node you are masking, check Invert Mask
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) 

Offline luvsmuzik

  • Member
  • *
  • Posts: 1592
Re: Angle from a reference vector
« Reply #12 on: July 13, 2017, 04:38:35 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...

Offline Ariel DK

  • Member
  • *
  • Posts: 229
    • http://arielmultimedia.deviantart.com/
Re: Angle from a reference vector
« Reply #13 on: July 15, 2017, 04:42:00 PM »
I almost missed this topic. as an idea, it's also useful for recreate the Ionosphere
Hmmm, what version of Terragen use god?

Offline bobbystahr

  • Member
  • *
  • Posts: 8200
  • Turn, and face the Strange Ch Ch Changes...D Bowie
Re: Angle from a reference vector
« Reply #14 on: July 15, 2017, 05:24:11 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

bobbystahr