Correct vector input to map texture light in Cycles What is the correct vector input for a texture connected to a Cycles lamp so that I can make a projector-like textured light?

I am trying to make an projector-like effect with a textured light in Cycles, currently trying it out with a Spot type of lamp, but I am open to any solution involving other lamp types if they work correctly.

The problem is that whatever vector input I use, the texture is always projected downwards, towards the global $-Z$ axis in scene world space, no matter where I point my spot light. I would like to have the texture always project "forward" towards the the direction the spot light is pointing, in the local $-Z$ axis.



The plan would then be to use this spot at several places in my scene, pointing at different directions, and as it currently stands I would have to have a different node setup for each spot instance, manually compensating for each unique rotation in the scene, which would quickly become unpractical.

I have searched around the internet and I am currently using a solution similar to the one on this BSE question.

Is there any better method, perhaps involving some funky Vector Math, or is this not currently supported?
You can do this without drivers.
You can achieve it using an area light instead of a spot light, then make use of the Geometry node's Normal and Incoming socket and subtract them using a Vector Math node.
It still suffers from tiling/mirroring artifacts at extreme angles like the solutions by @gandalf3, but those can be adjusted with the Vector Mapping node as long as multiple instances of the light are maintain within a certain angle threshold from eachother, and overall it seems like a more maintainable solution in the long term.

Blender 2.79+
As of Blender 2.79 Blender, Cycles can correctly use lamp texture coordinates directly for Spot, Area, and Point lamp types without any further contrivances.

Committed by Lukas Stockner Cycles: Implement texture coordinates for Point, Spot and Area Lamps
Cycles: Implement texture coordinates for Point, Spot and Area Lamps
When using the Normal output of the Texture Coordinate node on Point
and Spot lamps, the coordinates now depend on the rotation of the
lamp. On Area lamps, the Parametric output of the Geometry node now
returns UV coordinates on the area lamp.
Credit for the Area lamp part goes to Stefan Werner (from D1995).

Just use the Normal output on the Texture Coordinates node as vector input for a texture.


If you are using an image based texture you may need to offset the texture coordinates by $0.5$ units on $X$ and $Y$ axis using a Vector Mapping node to center the image on the projection direction.
Smaller sized area lights will produce sharper image projections.