2
$\begingroup$

So i need a Gradient on a disk to rotate in such a way that it follows the Camera. This is what i got: enter image description here

The Gradient and the blue line towards the Camera. And this is what i want: enter image description here

Now my idea was to use Trig. Since i know the lenght to the Camera and the Y or X depth i can theoretically calculate the relative angle between the disk and the Camera depending on the Location. Like this. enter image description here

However when i go to impliment this angle i get this enter image description here

With these nodes: enter image description here

And i dont see where the problem is. The math is correct, i have the right axis and so on. And i can clearly rotate the Gradient manually. All i do is plug the node setup above into the Input for the Gradient Z Angle. If i do it manually it works, put with the Node set up i get this weird result.

My suspicion is that Blender does the Angle calculation for all pixels of the Disk and thusly arrives at widly differnt angles for each point. Instead of Rotating them all as a group they get rotate individiually.

Now yes i could keyframe this but i would like to have this gradiant track the Camera a bit more precisly. Also i cant rotate the disk, it has to be the shader.

So are there any other ways ? What am i doing work ?

For those wondering why i need this, i am building a Black Hole Shader that tries to impliment all physical effects. This shader graident tracking stuff is to account for Doppler effect. Preview seen below: enter image description here

$\endgroup$

2 Answers 2

3
$\begingroup$

Well here is how I would do it. The Doppler effect fades as the camera becomes more parallel with the disk's normal which I think is accurate.

The key is, the object is flat in the z = 0 plane in object space. Then I take the cross product of the object coordinate position with (0,0,1) which yields a vector representing the rotation of the object. Then I take the dot product of that vector with the camera vector which yields a value that increases when the vector points towards the camera and decreases when pointing away. I use this value to control the hue shift by connecting it to a color ramp and a hue mix node. Fake Doppler Shader Node Tree

$\endgroup$
1
  • 1
    $\begingroup$ Holy hell, my plan was to adress the Z change of Doppler later but you mad man solved 2 issues at once :D Works perfectly ! And it even accounts for camera rotation, so if the camera flips 180 degress the doppler effect flips as well. This is perfect ! :D $\endgroup$
    – ErikHall
    Jan 28, 2022 at 0:52
2
$\begingroup$

Your nodes look like you're trying to get the angle of the sample. You're basically doing this right, but you're not doing any quadrant correction. The sin of 45 degrees is the same as the sin of 135 degrees, so arcsin(sin(135 degrees) = 45 degrees.

If you want the angle to a sample, my preferred method is atan2:

enter image description here

atan2 does the quadrant correction for you (and outputs an angle in radians, ranging from -pi to pi.)

Now, as for creating a gradient that follows the camera, there's more than one thing that can mean, but it sounds like you're after something like:

enter image description here

Notice the object axes. The direction of the gradient follows the camera, but remains centered on the object.

$\endgroup$
1
  • $\begingroup$ Thank you very much for the answer ! Your implimintation seems to give the exact result i was looking for as well. I went with the one of the other answer but it helps a lot to understand what the issue was, so thank you a lot for that ! $\endgroup$
    – ErikHall
    Jan 28, 2022 at 1:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .