# How do you rotate a vector about all axises? [Material]

Note: Since there is an image limit per post I have included a link to this Google Doc of the same text but with more picture: https://docs.google.com/document/d/1moP5RUAEqWhX31Qv1Vmo8JjWyAG0kZjquWm-NzE7NyQ/edit?usp=sharing

I am trying to make a Black Light effect. This is what I have so far.
The problem with it is that I wanted to be about to rotate about every axis, but don’t know how.

I achieved this by making this in the Post Process material below:

Essentially I’m taking the Scene Color and tinting it to give it a blacklight effect. I then feed that new tinted Scene Color into the B (or “white” area) of a Lerp Node and pipe the original Scene Color into the A (or “black” area). The Alpha is some black and white mask to separate the two.

In this case its a 3D Mask in World Space, below I have a switch that can change between a sphere mask and a more preferable cone mask (so that the effect works more light a flashlight/spotlight).

Below is the maths I am using for getting a cone mask in World Space:

When preview on a cube you can see that it is creating a cone shaped masked for the lerp (being the “white” area).

I have a custom event that gets ran on the Construction Script and Tick to set the location of my BlackLight in World Space and sets it as the value of a vector parameter in a material parameter collection.

The vector called “BlackLightPoint” is then subtracted from the Absolute World Position to give me the location of my BlackLight in the shader and is then piped into the above maths to create the cone mask.

When all these nodes leading to the alpha of that lerp are put into a material function shared by a decal (or other material) I can mask out the opacity of that decal wherever the cone isn’t visible.

The result is the effect below, showing these secret cave paintings that can only be shown by the effect:

The problem that I am having is that since this is a VR project and the device at emits this effect is meant to be held in the players hand, I need to be able to update its rotation on tick the same way I am updating its position.

By using the “RotateAboutWorldAxis_cheap” I can achieve rotating the cone in one axis but not all of them at the same time.

I will set up in the blueprint to get the rotation of the actor on tick, but for the time being and for debugging purposes I have left the x, y, and z rotation of the actor as the scalar parameters “X” “Y” and “Z” respectively.

I have tried almost everything and as far as I can tell this is more of a 3D math problem.
So how do you rotate a vector in 3 axises?
Or how do you rotate or a cone in 3 axises?

Also how change the ‘origin’ of the cone to emit for its peak?
I was able to kind of achieve this by adding the same “Height” parameter used in the cone mask to the R/X channel of the “BlackLightPoint”.

Now it works okay not with any of the rotational math.

So let me know what you guys think or if there is an easier way of going about this I haven’t considered, thanks.

Hi. You can pack an inverse transform (as three FVectors) and apply this transform to an input vector before evaluating cone. Also you can remove blacklight origin (because of containing all required data inside the transform)

To apply the transform inside a material you can use predefined node “Transform3x3Matrix” or “InverseTransformMatrix” depending on your needs. InverseTransform will internally inverse provided transform before applying to a vector.