1
$\begingroup$

I'm trying to replicate an effect/shader I've seen used in Ori and the Will of the Wisps, a videogame. Basically it's a 2D game with real-time lightning. The lightning in 2D is achieved by having various versions of the sprite with light drawn-in manually at various angles and then based on the position of the light source, two or more drawings are blended together to create the final lit sprite. This effect is not normal map based, so just dropping a light in the scene would just give flat lightning to everything. I wanted to replicate the effect in Blender because I think it would be interesting. I was thinking about trying this in both Cycles and Eevee.

From my googling and trying stuff in the shader editor though, I haven't found a way to feed the light position in the shader. I've seen the Light path node, but from my understanding it's just a boolean that says if a ray is of a certain type or not, without info on the location where it's coming from.

Is there any way to achieve this?

$\endgroup$
1
$\begingroup$

If you want the location of the light in World space, you can do it with drivers:

enter image description here

That's the disconnected Combine XYZ node labelled 'Light Location' in the illustration. Pin the material's node editor open for convenience, right-click each of the X, Y and Z fields in the light's Transform > Location panel, select Copy as New Driver, and right-click > Paste Driver in the XYZ fields.

You can also do it without drivers, by adding/subtracting the coordinates of the shading-point in various texture-spaces. However, you probably don't want the light's location in rotated spaces.. the only way I can think of getting round that is to associate an un-rotated target Empty with the objects of interest. I've called them 'Locators'. They have Copy Location constraints on their objects, but don't rotate with them.

enter image description here

Then the Yellow Vector Math node in the illustration gives the Light's location with respect to the cube's location, and the Turquoise one gives the Light's location in World Space.

Drivers are probably the way to go, otherwise it's more fiddly to reproduce the material for different objects.

$\endgroup$
0
$\begingroup$

I'm not 100% sure what you're going for, but you could start by trying something like this. The light position is fed into the shader using the Object Texture Coordinate with the Light selected as the object. The second (object local) Texture Coordinate is not necessary, but I think it looks better when the two vectors are added. This may change depending on what you need it for (try with just the light coordinate on it's own as well). Try moving the light around and see what happens on the plane.

WillOWisp

Also, you may want to run whatever you're using through an emission shader if you're trying to replicate light. I just used the BaseColor input for the example.

$\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.