Shader newbie: how to calculate (signed) angle between object and face

I’ve created a shader that lets me play with “inverting” the normal perspective projections.

It uses the object output of the texture coordinate node with the object set as the empty being used as a “projector.”

It’s working well on the faces closest to the projector empty, but it’s showing up on faces that it shouldn’t - e.g. the top face (shown) and back faces:

I think I can fix this by calculating the angle between the point being coloured and the projector empty, and not using this part of the shader for angles >=180˚.

I’ve tried playing with taking the cross and dot products of the normal and object outputs of the texture coordinate node, but so far it’s not behaved like I expected.

It could be due to the orientation of the empty- it’s arranged so X aligns with world, but Z aligns with world Y (-ve Z towards the object.) I don’t really understand how the empty’s location/rotation/scale is transformed in the shader on the cube. This is the orientation that ended up behaving in a way that made sense- ie projected image not mirrored, moves on the surface in the same direction as the empty is moved, and gets bigger as the empty moves closer to the surface.

Questions are:

  • Can someone explain to me how an objects coordinates are translated for the object output of the texture coordinate node?
  • Why does the projector empty need that particular orientation (-ve Z towards object)?
  • How do you calculate the angle between the current pixel’s normal and the empty?
  • Is there an easier way to enable/disable this shader flow for pixels not reachable from the projector empty?

Here are the perspective adjustment nodes:

Thanks in advance!

I am not sure this answers all of your questions but maybe you want to play around with this setup:

In order to get the empty’s orientation into the shader setup, I used a driver to copy the empty’s rotation and applied it to a (0,0,1) vector. Using the dot product allows to to check which of the cube’s faces are pointed in the empty’s positive z-direction this way.


empty_to_shader.blend (128.3 KB)

2 Likes

Thanks @LordoftheFleas !

That looks extremely promising, and is pretty much what I was trying to do using the texture coordinates. (I suspect it can be done… if you actually understand how what the coordinate spaces of each of those outputs really is. I have no idea, and not the easiest to interpret!)

But how the heck do you copy those geometry values into the shader?! (I’ll be googling “shader driver” tomorrow!)

That will be really, really cool- cause then I could also grab the empties scale and use that drive another parameter.

I think this is going to be good enough!

Hopefully someone can clarify the orientations of texture coordinate node outputs for me :slight_smile:

drivers are easy: just right-click any value and select “copy as new driver” and then right click the value you want to be driven and select “paste driver”

2 Likes

< < Jaw drop > > that is…AWESOME!

Thanks for pointing me in the direction of drivers + a clear description!

1 Like