If I get what I think you are asking forâŚ the rough algorithm might go like this:

vec3 left = cross(dir, vec3(0,1,0));
vec3 up = cross(left, dir);
float project = sin(angle);
vec3 upperLeft = left * project + up * project;
...continue for other corners.

I could have the cross products flipped, I frequently do thatâŚ I can never remember if we are right handed or left handed until I try it.

Edit: note a spot light pointing directly up (or close) will have to be handled special. And you have to normalize the left and up vectors.

Edit2: and I left out the range projection along the dir vector and you will need to multiply project by that, too. Scale up the triangle.

upperLeft = dir * range + left * project * range + up * project * range;

If you imagine you are staring down the direction vector then the pyramids far quad will extend left, right, up, down along vectors perpendicular to that direction vector.

A cross product between the âpure upâ vec3(0,1,0) and the direction vector will give you the perpendicular side vector when normalized. If youâve got the order of the cross product right then it will be pointing left.

A cross product between that vector and the direction vector will give you the relative up vector. Note: technically you now have a 3D rotation matrix, by the way.

At any rate, you now have the three axes or rotation for your pyramidâs space.

p = direction * range will give you the center of your blue âteeâ.

From there you want to go out based on your angleâŚ that will be the sine * range since range is essentially the scale of your triangle.

p += left * sine * range will give you the point where the blue line intersects the black between â1â and â2â in your drawing.

p += up * sine * range will give you point â1â

I called âsineâ âprojectâ in my original because you are using it to project down the vectors.

Edit: note that if you made a matrix from left, up, dir then the above is equivalent of a matrix mult with vec3(sin * range, sin * range, range)

Too much workâŚ Why not just precompute the pyramid vertices and then just multiply it by a rotation matrix? This is for the lighting geometry generator right?

Based on the shader you showed me, you just transform a constant uniform vec4 array by the WorldViewProjectionMatrix, so canât you just set the transform of the spot light and get thus get the transformed points for free?

Well, what is the world view projection matrix in this case. You could be doing a lot more work than required if itâs already oriented to the direction vector.

Sorry, donât get it. At most i might be able to skip the World*, since i already am in worldspace. But donât see a way to skip ViewProjection. But then its also late and my head is near to exploding.

If you have time you could also give me a hint on my last bug. (at least the last easily seeable)

While it works for like 70% of the random pointlights. The other 30% would require an inverted value.

What I mean is that if g_WorldViewProjectionMatrix was already oriented to the pyramid then you donât need all of the other stuff. A corner is just g_WorldViewProjectionMatrix * vec3(sin, sin, 1);

Can you explain what the bug is? I wasnât sure what I was looking at in the picture.