9
$\begingroup$

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.

Normal input in texture

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?

$\endgroup$
  • $\begingroup$ What about having the light still in the scene and rotate everything around with camera? Motion is relative. You can workaround around this like that. The texture coordinates of lights does not follow the light's local transforms..that makes it very hard to do what you want - the solution won't be trivial if there is any at all. $\endgroup$ – Jaroslav Jerryno Novotny Jul 1 '16 at 19:34
  • 2
    $\begingroup$ Also what about the UV project modifier to project a texture with round alpha with emission shader onto some geometry using the UV's $\endgroup$ – Jaroslav Jerryno Novotny Jul 1 '16 at 19:36
  • $\begingroup$ Still light and rotate the scene would be quite cumbersome to manage on a large scene, and would only ever work for one spot per scene unfortunately. The UV project modifier does make the desired effect but as I understand would only work in one object at a time, so it would also be a really cumbersome solution to light up a complex scene with lots of objects/lights. Thanks for the input though $\endgroup$ – Duarte Farrajota Ramos Jul 1 '16 at 23:42
9
$\begingroup$

One way to accomplish this is by using drivers to rotate the coordinates according to the rotation of the lamp.

  1. Add a mapping node between the texture coordinate node and the texture
  2. Add drivers to the rotation values with RMB RMB> Add Drivers
  3. Open the graph editor and switch from F-Curves to Drivers in the header
  4. With the lamp object and mapping node selected, set up each driver by selecting the appropriate driver type and transform type:

    enter image description here

Result:

enter image description here

$\endgroup$
  • $\begingroup$ This seems to be working reasonably well, best solution so far. I had never used drivers in Blender before. Is there a way to specify the driver to take the value automatically from the object its applied to (self?), so that on duplication new spot (spot 2, spot3) objects are automatically driven by their own rotation instead of the original spot's (spot 1) rotation? That would definitely ease the process. $\endgroup$ – Duarte Farrajota Ramos Jul 1 '16 at 23:49
  • 1
    $\begingroup$ @DuarteFarrajotaRamos Unfortunately no.. I sure wish there was such a thing, but some workarounds are possible $\endgroup$ – gandalf3 Jul 2 '16 at 2:32
  • $\begingroup$ Ah I see, one can only dream... Thanks for those links, I'll look into those solutions tomorrow, and also thanks got the answer. $\endgroup$ – Duarte Farrajota Ramos Jul 2 '16 at 3:20
  • $\begingroup$ I may have found a similar solution using area lights instead, in case you are interested. Answer posted bellow $\endgroup$ – Duarte Farrajota Ramos Jul 2 '16 at 18:48
  • $\begingroup$ Someone 'up there' must have heard our prayers. \o/ Unless I misunderstood this commit, from henceforth self reference now seems to be supported in drivers for upcoming Blender builds. $\endgroup$ – Duarte Farrajota Ramos Jul 31 '16 at 4:26
12
$\begingroup$

For the sake of completeness and future reference I found out how to do it without drivers.

You can achieve this 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, and overall it seems like a more maintainable solution in the long term.

Textured area light

Smaller sized area lights will produce sharper image projections.

EDIT: As of Blender 2.79 Blender, Cycles can correctly use lamp texture coordinates directly in Spot, Area, and Point Lamp types without any further contrivances. Just use the Normal output on the Texture Coordinates node as vector input for a texture.

enter image description here enter image description here

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).

$\endgroup$
10
$\begingroup$

As Duarte mentioned, 2.79 fixes light projection so textured lamps can be rotated, but to make a spotlight into a "normal" projector the image needs to be centered and warp adjusted. Added node setup for reference. enter image description here enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.